Changes in src/Concurrency/Keywords.cc [549c006:a843067]
- File:
-
- 1 edited
-
src/Concurrency/Keywords.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r549c006 ra843067 196 196 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* ); 197 197 void validate( DeclarationWithType * ); 198 void addDtorStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &);199 198 void addStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); 200 199 … … 207 206 StructDecl* monitor_decl = nullptr; 208 207 StructDecl* guard_decl = nullptr; 209 StructDecl* dtor_guard_decl = nullptr;210 208 211 209 static std::unique_ptr< Type > generic_func; … … 231 229 232 230 void postvisit( FunctionDecl * decl ); 233 void previsit ( StructDecl * decl );234 231 235 232 void addStartStatement( FunctionDecl * decl, DeclarationWithType * param ); … … 239 236 acceptAll( translationUnit, impl ); 240 237 } 241 242 private :243 bool thread_ctor_seen = false;244 StructDecl * thread_decl = nullptr;245 238 }; 246 239 … … 410 403 if( mutexArgs.empty() ) return; 411 404 412 if( CodeGen::isConstructor(decl->name) ) throw SemanticError( "constructors cannot have mutex parameters", decl );413 414 bool isDtor = CodeGen::isDestructor( decl->name );415 416 if( isDtor && mutexArgs.size() != 1 ) throw SemanticError( "destructors can only have 1 mutex argument", decl );417 418 405 for(auto arg : mutexArgs) { 419 406 validate( arg ); … … 425 412 if( !monitor_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl ); 426 413 if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl ); 427 if( !dtor_guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl ); 428 429 if( isDtor ) { 430 addDtorStatments( decl, body, mutexArgs ); 431 } 432 else { 433 addStatments( decl, body, mutexArgs ); 434 } 414 415 addStatments( decl, body, mutexArgs ); 435 416 } 436 417 … … 444 425 assert( !guard_decl ); 445 426 guard_decl = decl; 446 }447 else if( decl->name == "monitor_dtor_guard_t" ) {448 assert( !dtor_guard_decl );449 dtor_guard_decl = decl;450 427 } 451 428 } … … 480 457 //Make sure that typed isn't mutex 481 458 if( base->get_mutex() ) throw SemanticError( "mutex keyword may only appear once per argument ", arg ); 482 }483 484 void MutexKeyword::addDtorStatments( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {485 Type * arg_type = args.front()->get_type()->clone();486 arg_type->set_mutex( false );487 488 ObjectDecl * monitors = new ObjectDecl(489 "__monitor",490 noStorage,491 LinkageSpec::Cforall,492 nullptr,493 new PointerType(494 noQualifiers,495 new StructInstType(496 noQualifiers,497 monitor_decl498 )499 ),500 new SingleInit( new UntypedExpr(501 new NameExpr( "get_monitor" ),502 { new CastExpr( new VariableExpr( args.front() ), arg_type ) }503 ))504 );505 506 assert(generic_func);507 508 //in reverse order :509 // monitor_guard_t __guard = { __monitors, #, func };510 body->push_front(511 new DeclStmt( noLabels, new ObjectDecl(512 "__guard",513 noStorage,514 LinkageSpec::Cforall,515 nullptr,516 new StructInstType(517 noQualifiers,518 dtor_guard_decl519 ),520 new ListInit(521 {522 new SingleInit( new AddressExpr( new VariableExpr( monitors ) ) ),523 new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) )524 },525 noDesignators,526 true527 )528 ))529 );530 531 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };532 body->push_front( new DeclStmt( noLabels, monitors) );533 459 } 534 460 … … 597 523 // General entry routine 598 524 //============================================================================================= 599 void ThreadStarter::previsit( StructDecl * decl ) {600 if( decl->name == "thread_desc" && decl->body ) {601 assert( !thread_decl );602 thread_decl = decl;603 }604 }605 606 525 void ThreadStarter::postvisit(FunctionDecl * decl) { 607 526 if( ! CodeGen::isConstructor(decl->name) ) return; 608 609 Type * typeof_this = InitTweak::getTypeofThis(decl->type);610 StructInstType * ctored_type = dynamic_cast< StructInstType * >( typeof_this );611 if( ctored_type && ctored_type->baseStruct == thread_decl ) {612 thread_ctor_seen = true;613 }614 527 615 528 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 616 529 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 617 530 if( type && type->get_baseStruct()->is_thread() ) { 618 if( !thread_decl || !thread_ctor_seen ) {619 throw SemanticError("thread keyword requires threads to be in scope, add #include <thread>");620 }621 622 531 addStartStatement( decl, param ); 623 532 }
Note:
See TracChangeset
for help on using the changeset viewer.