Changes in src/Concurrency/Keywords.cc [ceedde6:42107b4]
- File:
-
- 1 edited
-
src/Concurrency/Keywords.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
rceedde6 r42107b4 19 19 #include <string> // for string, operator== 20 20 21 #include "Common/GC.h" // for new_static_root 21 22 #include "Common/PassVisitor.h" // for PassVisitor 22 23 #include "Common/SemanticError.h" // for SemanticError … … 191 192 void postvisit( StructDecl * decl ); 192 193 193 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* , bool & first);194 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* ); 194 195 void validate( DeclarationWithType * ); 195 196 void addDtorStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); … … 206 207 StructDecl* dtor_guard_decl = nullptr; 207 208 208 static std::unique_ptr< Type >generic_func;209 static Type* generic_func; 209 210 }; 210 211 211 std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >( 212 new FunctionType( 213 noQualifiers, 214 true 215 ) 216 ); 212 Type* MutexKeyword::generic_func = new_static_root<FunctionType>( noQualifiers, true ); 217 213 218 214 //----------------------------------------------------------------------------- … … 288 284 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 289 285 if( !type_decl ) SemanticError( cast, context_error ); 290 Expression * arg = cast->arg;291 cast->arg = nullptr;292 delete cast;293 286 return new CastExpr( 294 287 UntypedExpr::createDeref( 295 new UntypedExpr( new NameExpr( getter_name ), { arg } )288 new UntypedExpr( new NameExpr( getter_name ), { cast->arg } ) 296 289 ), 297 290 new ReferenceType( … … 318 311 StructDecl * forward = decl->clone(); 319 312 forward->set_body( false ); 320 deleteAll( forward->get_members() );321 313 forward->get_members().clear(); 322 314 … … 383 375 } 384 376 385 delete this_decl;386 387 377 declsToAddBefore.push_back( forward ); 388 378 if( needs_main ) declsToAddBefore.push_back( main_decl ); … … 441 431 void MutexKeyword::postvisit(FunctionDecl* decl) { 442 432 443 bool first = false; 444 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl, first ); 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 445 438 bool isDtor = CodeGen::isDestructor( decl->name ); 446 439 447 // Is this function relevant to monitors448 if( mutexArgs.empty() ) {449 // If this is the destructor for a monitor it must be mutex450 if(isDtor) {451 Type* ty = decl->get_functionType()->get_parameters().front()->get_type();452 453 // If it's a copy, it's not a mutex454 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 mutex458 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 struct463 StructInstType * baseStruct = dynamic_cast< StructInstType * >( base );464 if( !baseStruct ) return;465 466 // Check if its a monitor467 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 exclusion474 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 destructor477 440 if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" ); 478 441 479 // Make sure all the mutex arguments are monitors480 442 for(auto arg : mutexArgs) { 481 443 validate( arg ); 482 444 } 483 445 484 // Check if we need to instrument the body485 446 CompoundStmt* body = decl->get_statements(); 486 447 if( ! body ) return; 487 448 488 // Do we have the required headers489 449 if( !monitor_decl || !guard_decl || !dtor_guard_decl ) 490 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>\n" ); 491 492 // Instrument the body 450 SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" ); 451 493 452 if( isDtor ) { 494 453 addDtorStatments( decl, body, mutexArgs ); … … 515 474 } 516 475 517 std::list<DeclarationWithType*> MutexKeyword::findMutexArgs( FunctionDecl* decl , bool & first) {476 std::list<DeclarationWithType*> MutexKeyword::findMutexArgs( FunctionDecl* decl ) { 518 477 std::list<DeclarationWithType*> mutexArgs; 519 478 520 bool once = true;521 479 for( auto arg : decl->get_functionType()->get_parameters()) { 522 480 //Find mutex arguments 523 481 Type* ty = arg->get_type(); 524 482 if( ! ty->get_mutex() ) continue; 525 526 if(once) {first = true;}527 once = false;528 483 529 484 //Append it to the list
Note:
See TracChangeset
for help on using the changeset viewer.