Changeset ceedde6 for src/Concurrency/Keywords.cc
- Timestamp:
- May 29, 2018, 4:15:33 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 1134b80
- Parents:
- 8638cef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r8638cef rceedde6 443 443 bool first = false; 444 444 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl, first ); 445 if( mutexArgs.empty() ) return;446 447 if( CodeGen::isConstructor(decl->name) && first ) SemanticError( decl, "constructors cannot have mutex parameters" );448 449 445 bool isDtor = CodeGen::isDestructor( decl->name ); 450 446 447 // Is this function relevant to monitors 448 if( mutexArgs.empty() ) { 449 // If this is the destructor for a monitor it must be mutex 450 if(isDtor) { 451 Type* ty = decl->get_functionType()->get_parameters().front()->get_type(); 452 453 // If it's a copy, it's not a mutex 454 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty ); 455 if( ! rty ) return; 456 457 // If we are not pointing directly to a type, it's not a mutex 458 Type* base = rty->get_base(); 459 if( dynamic_cast< ReferenceType * >( base ) ) return; 460 if( dynamic_cast< PointerType * >( base ) ) return; 461 462 // Check if its a struct 463 StructInstType * baseStruct = dynamic_cast< StructInstType * >( base ); 464 if( !baseStruct ) return; 465 466 // Check if its a monitor 467 if(baseStruct->baseStruct->is_monitor() || baseStruct->baseStruct->is_thread()) 468 SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters\n" ); 469 } 470 return; 471 } 472 473 // Monitors can't be constructed with mutual exclusion 474 if( CodeGen::isConstructor(decl->name) && !first ) SemanticError( decl, "constructors cannot have mutex parameters" ); 475 476 // It makes no sense to have multiple mutex parameters for the destructor 451 477 if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" ); 452 478 479 // Make sure all the mutex arguments are monitors 453 480 for(auto arg : mutexArgs) { 454 481 validate( arg ); 455 482 } 456 483 484 // Check if we need to instrument the body 457 485 CompoundStmt* body = decl->get_statements(); 458 486 if( ! body ) return; 459 487 488 // Do we have the required headers 460 489 if( !monitor_decl || !guard_decl || !dtor_guard_decl ) 461 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" ); 462 490 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>\n" ); 491 492 // Instrument the body 463 493 if( isDtor ) { 464 494 addDtorStatments( decl, body, mutexArgs );
Note: See TracChangeset
for help on using the changeset viewer.