Changeset 3d5701e for src/Concurrency/Keywords.cc
- Timestamp:
- Feb 25, 2020, 1:17:33 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7dc2e015
- Parents:
- 9fb8f01 (diff), dd9e1ca (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
-
src/Concurrency/Keywords.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r9fb8f01 r3d5701e 11 11 // Last Modified By : 12 12 // Last Modified On : 13 // Update Count : 513 // Update Count : 10 14 14 // 15 15 … … 24 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 25 #include "InitTweak/InitTweak.h" // for getPointerBase 26 #include " Parser/LinkageSpec.h"// for Cforall26 #include "SynTree/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, KeywordCastExpr::Targetcast_target ) :55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate 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 ); 61 62 62 63 void handle( StructDecl * ); … … 75 76 const std::string context_error; 76 77 bool needs_main; 77 KeywordCastExpr::Target cast_target; 78 79 StructDecl* type_decl = nullptr; 78 AggregateDecl::Aggregate cast_target; 79 80 StructDecl * type_decl = nullptr; 81 FunctionDecl * dtor_decl = nullptr; 80 82 }; 81 83 … … 86 88 // int data; int data; 87 89 // a_struct_t more_data; a_struct_t more_data; 88 // => thread_desc__thrd_d;90 // => $thread __thrd_d; 89 91 // }; }; 90 // static inline thread_desc* get_thread( MyThread * this ) { return &this->__thrd_d; }92 // static inline $thread * get_thread( MyThread * this ) { return &this->__thrd_d; } 91 93 // 92 94 class ThreadKeyword final : public ConcurrentSueKeyword { … … 94 96 95 97 ThreadKeyword() : ConcurrentSueKeyword( 96 " thread_desc",98 "$thread", 97 99 "__thrd", 98 100 "get_thread", 99 "thread keyword requires threads to be in scope, add #include <thread.hfa> ",101 "thread keyword requires threads to be in scope, add #include <thread.hfa>\n", 100 102 true, 101 KeywordCastExpr::Thread103 AggregateDecl::Thread 102 104 ) 103 105 {} … … 118 120 // int data; int data; 119 121 // a_struct_t more_data; a_struct_t more_data; 120 // => coroutine_desc__cor_d;122 // => $coroutine __cor_d; 121 123 // }; }; 122 // static inline coroutine_desc* get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }124 // static inline $coroutine * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; } 123 125 // 124 126 class CoroutineKeyword final : public ConcurrentSueKeyword { … … 126 128 127 129 CoroutineKeyword() : ConcurrentSueKeyword( 128 " coroutine_desc",130 "$coroutine", 129 131 "__cor", 130 132 "get_coroutine", 131 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa> ",133 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n", 132 134 true, 133 KeywordCastExpr::Coroutine135 AggregateDecl::Coroutine 134 136 ) 135 137 {} … … 150 152 // int data; int data; 151 153 // a_struct_t more_data; a_struct_t more_data; 152 // => monitor_desc__mon_d;154 // => $monitor __mon_d; 153 155 // }; }; 154 // static inline monitor_desc* get_coroutine( MyMonitor * this ) { return &this->__cor_d; }156 // static inline $monitor * get_coroutine( MyMonitor * this ) { return &this->__cor_d; } 155 157 // 156 158 class MonitorKeyword final : public ConcurrentSueKeyword { … … 158 160 159 161 MonitorKeyword() : ConcurrentSueKeyword( 160 " monitor_desc",162 "$monitor", 161 163 "__mon", 162 164 "get_monitor", 163 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa> ",165 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n", 164 166 false, 165 KeywordCastExpr::Monitor167 AggregateDecl::Monitor 166 168 ) 167 169 {} … … 180 182 //Handles mutex routines definitions : 181 183 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 182 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };184 // $monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 183 185 // monitor_guard_t __guard = { __monitors, 2 }; 184 186 // /*Some code*/ => /*Some code*/ … … 219 221 //Handles mutex routines definitions : 220 222 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 221 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };223 // $monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 222 224 // monitor_guard_t __guard = { __monitors, 2 }; 223 225 // /*Some code*/ => /*Some code*/ … … 284 286 } 285 287 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 286 306 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 287 307 if ( cast_target == cast->target ) { 288 // convert (thread &)t to ( thread_desc&)*get_thread(t), etc.308 // convert (thread &)t to ($thread &)*get_thread(t), etc. 289 309 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 ); 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; 301 315 } 302 316 return cast; … … 308 322 309 323 if( !type_decl ) SemanticError( decl, context_error ); 324 if( !dtor_decl ) SemanticError( decl, context_error ); 310 325 311 326 FunctionDecl * func = forwardDeclare( decl ); … … 362 377 get_type, 363 378 nullptr, 364 noAttributes,379 { new Attribute("const") }, 365 380 Type::Inline 366 381 ); … … 501 516 void MutexKeyword::postvisit(StructDecl* decl) { 502 517 503 if( decl->name == " monitor_desc" && decl->body ) {518 if( decl->name == "$monitor" && decl->body ) { 504 519 assert( !monitor_decl ); 505 520 monitor_decl = decl; … … 597 612 ); 598 613 599 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };614 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 600 615 body->push_front( new DeclStmt( monitors) ); 601 616 } … … 658 673 ); 659 674 660 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };675 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 661 676 body->push_front( new DeclStmt( monitors) ); 662 677 } … … 666 681 //============================================================================================= 667 682 void ThreadStarter::previsit( StructDecl * decl ) { 668 if( decl->name == " thread_desc" && decl->body ) {683 if( decl->name == "$thread" && decl->body ) { 669 684 assert( !thread_decl ); 670 685 thread_decl = decl; … … 701 716 new UntypedExpr( 702 717 new NameExpr( "__thrd_start" ), 703 { new VariableExpr( param ) }718 { new VariableExpr( param ), new NameExpr("main") } 704 719 ) 705 720 )
Note:
See TracChangeset
for help on using the changeset viewer.