Changeset 1cdfa82 for src/Concurrency
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r2efe4b8 r1cdfa82 54 54 public: 55 55 56 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) :57 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {}56 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) : 57 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {} 58 58 59 59 virtual ~ConcurrentSueKeyword() {} 60 60 61 void postvisit( StructDecl * decl );61 Declaration * postmutate( StructDecl * decl ); 62 62 63 63 void handle( StructDecl * ); … … 67 67 68 68 virtual bool is_target( StructDecl * decl ) = 0; 69 70 Expression * postmutate( KeywordCastExpr * cast ); 69 71 70 72 private: … … 74 76 const std::string context_error; 75 77 bool needs_main; 78 KeywordCastExpr::Target cast_target; 76 79 77 80 StructDecl* type_decl = nullptr; … … 96 99 "get_thread", 97 100 "thread keyword requires threads to be in scope, add #include <thread>", 98 true 101 true, 102 KeywordCastExpr::Thread 99 103 ) 100 104 {} … … 106 110 static void implement( std::list< Declaration * > & translationUnit ) { 107 111 PassVisitor< ThreadKeyword > impl; 108 acceptAll( translationUnit, impl );112 mutateAll( translationUnit, impl ); 109 113 } 110 114 }; … … 127 131 "get_coroutine", 128 132 "coroutine keyword requires coroutines to be in scope, add #include <coroutine>", 129 true 133 true, 134 KeywordCastExpr::Coroutine 130 135 ) 131 136 {} … … 137 142 static void implement( std::list< Declaration * > & translationUnit ) { 138 143 PassVisitor< CoroutineKeyword > impl; 139 acceptAll( translationUnit, impl );144 mutateAll( translationUnit, impl ); 140 145 } 141 146 }; … … 158 163 "get_monitor", 159 164 "monitor keyword requires monitors to be in scope, add #include <monitor>", 160 false 165 false, 166 KeywordCastExpr::Monitor 161 167 ) 162 168 {} … … 168 174 static void implement( std::list< Declaration * > & translationUnit ) { 169 175 PassVisitor< MonitorKeyword > impl; 170 acceptAll( translationUnit, impl );176 mutateAll( translationUnit, impl ); 171 177 } 172 178 }; … … 263 269 } 264 270 265 void ConcurrentSueKeyword::postvisit(StructDecl * decl) {271 Declaration * ConcurrentSueKeyword::postmutate(StructDecl * decl) { 266 272 if( decl->name == type_name && decl->body ) { 267 273 assert( !type_decl ); … … 271 277 handle( decl ); 272 278 } 273 } 279 return decl; 280 } 281 282 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 283 if ( cast_target == cast->target ) { 284 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 285 if( !type_decl ) SemanticError( cast, context_error ); 286 Expression * arg = cast->arg; 287 cast->arg = nullptr; 288 delete cast; 289 return new CastExpr( 290 UntypedExpr::createDeref( 291 new UntypedExpr( new NameExpr( getter_name ), { arg } ) 292 ), 293 new ReferenceType( 294 noQualifiers, 295 new StructInstType( noQualifiers, type_decl ) ) 296 ); 297 } 298 return cast; 299 } 300 274 301 275 302 void ConcurrentSueKeyword::handle( StructDecl * decl ) {
Note: See TracChangeset
for help on using the changeset viewer.