Changeset 28f3a19 for src/Concurrency
- Timestamp:
- Jun 27, 2018, 3:28:41 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- b21c77a
- Parents:
- 0182bfa (diff), 63238a4 (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
r0182bfa r28f3a19 192 192 void postvisit( StructDecl * decl ); 193 193 194 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );194 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl*, bool & first ); 195 195 void validate( DeclarationWithType * ); 196 196 void addDtorStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); … … 431 431 void MutexKeyword::postvisit(FunctionDecl* decl) { 432 432 433 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); 434 if( mutexArgs.empty() ) return; 435 436 if( CodeGen::isConstructor(decl->name) ) SemanticError( decl, "constructors cannot have mutex parameters" ); 437 433 bool first = false; 434 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl, first ); 438 435 bool isDtor = CodeGen::isDestructor( decl->name ); 439 436 437 // Is this function relevant to monitors 438 if( mutexArgs.empty() ) { 439 // If this is the destructor for a monitor it must be mutex 440 if(isDtor) { 441 Type* ty = decl->get_functionType()->get_parameters().front()->get_type(); 442 443 // If it's a copy, it's not a mutex 444 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty ); 445 if( ! rty ) return; 446 447 // If we are not pointing directly to a type, it's not a mutex 448 Type* base = rty->get_base(); 449 if( dynamic_cast< ReferenceType * >( base ) ) return; 450 if( dynamic_cast< PointerType * >( base ) ) return; 451 452 // Check if its a struct 453 StructInstType * baseStruct = dynamic_cast< StructInstType * >( base ); 454 if( !baseStruct ) return; 455 456 // Check if its a monitor 457 if(baseStruct->baseStruct->is_monitor() || baseStruct->baseStruct->is_thread()) 458 SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters\n" ); 459 } 460 return; 461 } 462 463 // Monitors can't be constructed with mutual exclusion 464 if( CodeGen::isConstructor(decl->name) && !first ) SemanticError( decl, "constructors cannot have mutex parameters" ); 465 466 // It makes no sense to have multiple mutex parameters for the destructor 440 467 if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" ); 441 468 469 // Make sure all the mutex arguments are monitors 442 470 for(auto arg : mutexArgs) { 443 471 validate( arg ); 444 472 } 445 473 474 // Check if we need to instrument the body 446 475 CompoundStmt* body = decl->get_statements(); 447 476 if( ! body ) return; 448 477 478 // Do we have the required headers 449 479 if( !monitor_decl || !guard_decl || !dtor_guard_decl ) 450 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" ); 451 480 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>\n" ); 481 482 // Instrument the body 452 483 if( isDtor ) { 453 484 addDtorStatments( decl, body, mutexArgs ); … … 474 505 } 475 506 476 std::list<DeclarationWithType*> MutexKeyword::findMutexArgs( FunctionDecl* decl ) {507 std::list<DeclarationWithType*> MutexKeyword::findMutexArgs( FunctionDecl* decl, bool & first ) { 477 508 std::list<DeclarationWithType*> mutexArgs; 478 509 510 bool once = true; 479 511 for( auto arg : decl->get_functionType()->get_parameters()) { 480 512 //Find mutex arguments 481 513 Type* ty = arg->get_type(); 482 514 if( ! ty->get_mutex() ) continue; 515 516 if(once) {first = true;} 517 once = false; 483 518 484 519 //Append it to the list
Note: See TracChangeset
for help on using the changeset viewer.