Changes in src/Concurrency/Keywords.cc [ac2b598:2bf7ef6]
- File:
-
- 1 edited
-
src/Concurrency/Keywords.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
rac2b598 r2bf7ef6 11 11 // Last Modified By : 12 12 // Last Modified On : 13 // Update Count : 1013 // Update Count : 5 14 14 // 15 15 … … 24 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 25 #include "InitTweak/InitTweak.h" // for getPointerBase 26 #include " SynTree/LinkageSpec.h"// for Cforall26 #include "Parser/LinkageSpec.h" // for Cforall 27 27 #include "SynTree/Constant.h" // for Constant 28 28 #include "SynTree/Declaration.h" // for StructDecl, FunctionDecl, ObjectDecl … … 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, AggregateDecl::Aggregatecast_target ) :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 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 … … 59 59 60 60 Declaration * postmutate( StructDecl * decl ); 61 DeclarationWithType * postmutate( FunctionDecl * decl );62 61 63 62 void handle( StructDecl * ); … … 76 75 const std::string context_error; 77 76 bool needs_main; 78 AggregateDecl::Aggregate cast_target; 79 80 StructDecl * type_decl = nullptr; 81 FunctionDecl * dtor_decl = nullptr; 77 KeywordCastExpr::Target cast_target; 78 79 StructDecl* type_decl = nullptr; 82 80 }; 83 81 … … 88 86 // int data; int data; 89 87 // a_struct_t more_data; a_struct_t more_data; 90 // => $thread__thrd_d;88 // => thread_desc __thrd_d; 91 89 // }; }; 92 // static inline $thread* get_thread( MyThread * this ) { return &this->__thrd_d; }90 // static inline thread_desc * get_thread( MyThread * this ) { return &this->__thrd_d; } 93 91 // 94 92 class ThreadKeyword final : public ConcurrentSueKeyword { … … 96 94 97 95 ThreadKeyword() : ConcurrentSueKeyword( 98 " $thread",96 "thread_desc", 99 97 "__thrd", 100 98 "get_thread", 101 "thread keyword requires threads to be in scope, add #include <thread.hfa> \n",99 "thread keyword requires threads to be in scope, add #include <thread.hfa>", 102 100 true, 103 AggregateDecl::Thread101 KeywordCastExpr::Thread 104 102 ) 105 103 {} … … 120 118 // int data; int data; 121 119 // a_struct_t more_data; a_struct_t more_data; 122 // => $coroutine__cor_d;120 // => coroutine_desc __cor_d; 123 121 // }; }; 124 // static inline $coroutine* get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }122 // static inline coroutine_desc * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; } 125 123 // 126 124 class CoroutineKeyword final : public ConcurrentSueKeyword { … … 128 126 129 127 CoroutineKeyword() : ConcurrentSueKeyword( 130 " $coroutine",128 "coroutine_desc", 131 129 "__cor", 132 130 "get_coroutine", 133 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa> \n",131 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>", 134 132 true, 135 AggregateDecl::Coroutine133 KeywordCastExpr::Coroutine 136 134 ) 137 135 {} … … 152 150 // int data; int data; 153 151 // a_struct_t more_data; a_struct_t more_data; 154 // => $monitor__mon_d;152 // => monitor_desc __mon_d; 155 153 // }; }; 156 // static inline $monitor* get_coroutine( MyMonitor * this ) { return &this->__cor_d; }154 // static inline monitor_desc * get_coroutine( MyMonitor * this ) { return &this->__cor_d; } 157 155 // 158 156 class MonitorKeyword final : public ConcurrentSueKeyword { … … 160 158 161 159 MonitorKeyword() : ConcurrentSueKeyword( 162 " $monitor",160 "monitor_desc", 163 161 "__mon", 164 162 "get_monitor", 165 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa> \n",163 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>", 166 164 false, 167 AggregateDecl::Monitor165 KeywordCastExpr::Monitor 168 166 ) 169 167 {} … … 182 180 //Handles mutex routines definitions : 183 181 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 184 // $monitor* __monitors[] = { get_monitor(a), get_monitor(b) };182 // monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 185 183 // monitor_guard_t __guard = { __monitors, 2 }; 186 184 // /*Some code*/ => /*Some code*/ … … 221 219 //Handles mutex routines definitions : 222 220 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 223 // $monitor* __monitors[] = { get_monitor(a), get_monitor(b) };221 // monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 224 222 // monitor_guard_t __guard = { __monitors, 2 }; 225 223 // /*Some code*/ => /*Some code*/ … … 286 284 } 287 285 288 DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) {289 if( !type_decl ) return decl;290 if( !CodeGen::isDestructor( decl->name ) ) return decl;291 292 auto params = decl->type->parameters;293 if( params.size() != 1 ) return decl;294 295 auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() );296 if( !type ) return decl;297 298 auto stype = dynamic_cast<StructInstType*>( type->base );299 if( !stype ) return decl;300 if( stype->baseStruct != type_decl ) return decl;301 302 if( !dtor_decl ) dtor_decl = decl;303 return decl;304 }305 306 286 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 307 287 if ( cast_target == cast->target ) { 308 // convert (thread &)t to ( $thread&)*get_thread(t), etc.288 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 309 289 if( !type_decl ) SemanticError( cast, context_error ); 310 if( !dtor_decl ) SemanticError( cast, context_error ); 311 assert( cast->result == nullptr ); 312 cast->set_result( new ReferenceType( noQualifiers, new StructInstType( noQualifiers, type_decl ) ) ); 313 cast->concrete_target.field = field_name; 314 cast->concrete_target.getter = getter_name; 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 ); 315 301 } 316 302 return cast; … … 322 308 323 309 if( !type_decl ) SemanticError( decl, context_error ); 324 if( !dtor_decl ) SemanticError( decl, context_error );325 310 326 311 FunctionDecl * func = forwardDeclare( decl ); … … 377 362 get_type, 378 363 nullptr, 379 { new Attribute("const") },364 noAttributes, 380 365 Type::Inline 381 366 ); … … 516 501 void MutexKeyword::postvisit(StructDecl* decl) { 517 502 518 if( decl->name == " $monitor" && decl->body ) {503 if( decl->name == "monitor_desc" && decl->body ) { 519 504 assert( !monitor_decl ); 520 505 monitor_decl = decl; … … 612 597 ); 613 598 614 // $monitor* __monitors[] = { get_monitor(a), get_monitor(b) };599 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 615 600 body->push_front( new DeclStmt( monitors) ); 616 601 } … … 673 658 ); 674 659 675 // $monitor* __monitors[] = { get_monitor(a), get_monitor(b) };660 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 676 661 body->push_front( new DeclStmt( monitors) ); 677 662 } … … 681 666 //============================================================================================= 682 667 void ThreadStarter::previsit( StructDecl * decl ) { 683 if( decl->name == " $thread" && decl->body ) {668 if( decl->name == "thread_desc" && decl->body ) { 684 669 assert( !thread_decl ); 685 670 thread_decl = decl; … … 716 701 new UntypedExpr( 717 702 new NameExpr( "__thrd_start" ), 718 { new VariableExpr( param ) , new NameExpr("main")}703 { new VariableExpr( param ) } 719 704 ) 720 705 )
Note:
See TracChangeset
for help on using the changeset viewer.