Changeset 9a705dc8 for src/Concurrency/Keywords.cc
- Timestamp:
- Apr 19, 2018, 5:18:46 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- da9d79b
- Parents:
- 60ba456
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r60ba456 r9a705dc8 53 53 public: 54 54 55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) :56 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {}55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) : 56 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {} 57 57 58 58 virtual ~ConcurrentSueKeyword() {} 59 59 60 void postvisit( StructDecl * decl );60 Declaration * postmutate( StructDecl * decl ); 61 61 62 62 void handle( StructDecl * ); … … 66 66 67 67 virtual bool is_target( StructDecl * decl ) = 0; 68 69 Expression * postmutate( KeywordCastExpr * cast ); 68 70 69 71 private: … … 73 75 const std::string context_error; 74 76 bool needs_main; 77 KeywordCastExpr::Target cast_target; 75 78 76 79 StructDecl* type_decl = nullptr; … … 95 98 "get_thread", 96 99 "thread keyword requires threads to be in scope, add #include <thread>", 97 true 100 true, 101 KeywordCastExpr::Thread 98 102 ) 99 103 {} … … 105 109 static void implement( std::list< Declaration * > & translationUnit ) { 106 110 PassVisitor< ThreadKeyword > impl; 107 acceptAll( translationUnit, impl );111 mutateAll( translationUnit, impl ); 108 112 } 109 113 }; … … 126 130 "get_coroutine", 127 131 "coroutine keyword requires coroutines to be in scope, add #include <coroutine>", 128 true 132 true, 133 KeywordCastExpr::Coroutine 129 134 ) 130 135 {} … … 136 141 static void implement( std::list< Declaration * > & translationUnit ) { 137 142 PassVisitor< CoroutineKeyword > impl; 138 acceptAll( translationUnit, impl );143 mutateAll( translationUnit, impl ); 139 144 } 140 145 }; … … 157 162 "get_monitor", 158 163 "monitor keyword requires monitors to be in scope, add #include <monitor>", 159 false 164 false, 165 KeywordCastExpr::Monitor 160 166 ) 161 167 {} … … 167 173 static void implement( std::list< Declaration * > & translationUnit ) { 168 174 PassVisitor< MonitorKeyword > impl; 169 acceptAll( translationUnit, impl );175 mutateAll( translationUnit, impl ); 170 176 } 171 177 }; … … 267 273 } 268 274 269 void ConcurrentSueKeyword::postvisit(StructDecl * decl) {275 Declaration * ConcurrentSueKeyword::postmutate(StructDecl * decl) { 270 276 if( decl->name == type_name && decl->body ) { 271 277 assert( !type_decl ); … … 275 281 handle( decl ); 276 282 } 277 } 283 return decl; 284 } 285 286 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 287 if ( cast_target == cast->target ) { 288 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 289 if( !type_decl ) SemanticError( cast, context_error ); 290 Expression * arg = cast->arg; 291 cast->arg = nullptr; 292 delete cast; 293 return new CastExpr( 294 UntypedExpr::createDeref( 295 new UntypedExpr( new NameExpr( getter_name ), { arg } ) 296 ), 297 new ReferenceType( 298 noQualifiers, 299 new StructInstType( noQualifiers, type_decl ) ) 300 ); 301 } 302 return cast; 303 } 304 278 305 279 306 void ConcurrentSueKeyword::handle( StructDecl * decl ) {
Note: See TracChangeset
for help on using the changeset viewer.