Changes in src/Concurrency/Keywords.cc [2065609:be9288a]
- File:
-
- 1 edited
-
src/Concurrency/Keywords.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r2065609 rbe9288a 19 19 #include <string> // for string, operator== 20 20 21 #include "Common/PassVisitor.h" // for PassVisitor22 21 #include "Common/SemanticError.h" // for SemanticError 23 22 #include "Common/utility.h" // for deleteAll, map_range 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 #include "InitTweak/InitTweak.h" // for getPointerBase 23 #include "InitTweak/InitTweak.h" // for isConstructor 26 24 #include "Parser/LinkageSpec.h" // for Cforall 27 25 #include "SymTab/AddVisit.h" // for acceptAndAdd … … 47 45 48 46 //============================================================================================= 49 // Pass declarations47 // Visitors declaration 50 48 //============================================================================================= 51 49 … … 59 57 // static inline NewField_t * getter_name( MyType * this ) { return &this->newField; } 60 58 // 61 class ConcurrentSueKeyword : public WithDeclsToAdd { 59 class ConcurrentSueKeyword : public Visitor { 60 protected: 61 template< typename Visitor > 62 friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 62 63 public: 63 64 … … 67 68 virtual ~ConcurrentSueKeyword() {} 68 69 69 void postvisit( StructDecl * decl ); 70 using Visitor::visit; 71 virtual void visit( StructDecl * decl ) override final; 70 72 71 73 void handle( StructDecl * ); … … 83 85 bool needs_main; 84 86 87 std::list< Declaration * > declsToAdd, declsToAddAfter; 85 88 StructDecl* type_decl = nullptr; 86 89 }; … … 113 116 114 117 static void implement( std::list< Declaration * > & translationUnit ) { 115 PassVisitor< ThreadKeyword >impl;116 acceptAll( translationUnit, impl );118 ThreadKeyword impl; 119 SymTab::acceptAndAdd( translationUnit, impl ); 117 120 } 118 121 }; … … 144 147 145 148 static void implement( std::list< Declaration * > & translationUnit ) { 146 PassVisitor< CoroutineKeyword >impl;147 acceptAll( translationUnit, impl );149 CoroutineKeyword impl; 150 SymTab::acceptAndAdd( translationUnit, impl ); 148 151 } 149 152 }; … … 175 178 176 179 static void implement( std::list< Declaration * > & translationUnit ) { 177 PassVisitor< MonitorKeyword >impl;178 acceptAll( translationUnit, impl );180 MonitorKeyword impl; 181 SymTab::acceptAndAdd( translationUnit, impl ); 179 182 } 180 183 }; … … 188 191 // } } 189 192 // 190 class MutexKeyword final {193 class MutexKeyword final : public Visitor { 191 194 public: 192 195 193 void postvisit( FunctionDecl * decl ); 194 void postvisit( StructDecl * decl ); 196 using Visitor::visit; 197 virtual void visit( FunctionDecl * decl ) override final; 198 virtual void visit( StructDecl * decl ) override final; 195 199 196 200 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* ); 197 201 void validate( DeclarationWithType * ); 198 void addStatments( FunctionDecl* func,CompoundStmt *, const std::list<DeclarationWithType * > &);202 void addStatments( CompoundStmt *, const std::list<DeclarationWithType * > &); 199 203 200 204 static void implement( std::list< Declaration * > & translationUnit ) { 201 PassVisitor< MutexKeyword >impl;205 MutexKeyword impl; 202 206 acceptAll( translationUnit, impl ); 203 207 } … … 206 210 StructDecl* monitor_decl = nullptr; 207 211 StructDecl* guard_decl = nullptr; 208 209 static std::unique_ptr< Type > generic_func;210 212 }; 211 212 std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >(213 new FunctionType(214 noQualifiers,215 true216 )217 );218 213 219 214 //----------------------------------------------------------------------------- … … 225 220 // } } 226 221 // 227 class ThreadStarter final {222 class ThreadStarter final : public Visitor { 228 223 public: 229 224 230 void postvisit( FunctionDecl * decl ); 225 using Visitor::visit; 226 virtual void visit( FunctionDecl * decl ) override final; 231 227 232 228 void addStartStatement( FunctionDecl * decl, DeclarationWithType * param ); 233 229 234 230 static void implement( std::list< Declaration * > & translationUnit ) { 235 PassVisitor< ThreadStarter >impl;231 ThreadStarter impl; 236 232 acceptAll( translationUnit, impl ); 237 233 } … … 258 254 // Generic keyword implementation 259 255 //============================================================================================= 260 void ConcurrentSueKeyword::postvisit(StructDecl * decl) { 256 void ConcurrentSueKeyword::visit(StructDecl * decl) { 257 Visitor::visit(decl); 261 258 if( decl->get_name() == type_name && decl->has_body() ) { 262 259 assert( !type_decl ); … … 292 289 LinkageSpec::Cforall, 293 290 nullptr, 294 new ReferenceType(291 new PointerType( 295 292 noQualifiers, 296 293 new StructInstType( … … 346 343 } 347 344 348 declsToAdd Before.push_back( forward );349 if( needs_main ) declsToAdd Before.push_back( main_decl );350 declsToAdd Before.push_back( get_decl );345 declsToAdd.push_back( forward ); 346 if( needs_main ) declsToAdd.push_back( main_decl ); 347 declsToAdd.push_back( get_decl ); 351 348 352 349 return get_decl; … … 397 394 // Mutex keyword implementation 398 395 //============================================================================================= 399 400 void MutexKeyword::postvisit(FunctionDecl* decl) {396 void MutexKeyword::visit(FunctionDecl* decl) { 397 Visitor::visit(decl); 401 398 402 399 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); … … 413 410 if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl ); 414 411 415 addStatments( decl, body, mutexArgs ); 416 } 417 418 void MutexKeyword::postvisit(StructDecl* decl) { 412 addStatments( body, mutexArgs ); 413 } 414 415 void MutexKeyword::visit(StructDecl* decl) { 416 Visitor::visit(decl); 419 417 420 418 if( decl->get_name() == "monitor_desc" ) { … … 447 445 448 446 //Makes sure it's not a copy 449 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );450 if( ! rty ) throw SemanticError( "Mutex argument must be ofreference type ", arg );447 PointerType* pty = dynamic_cast< PointerType * >( ty ); 448 if( ! pty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg ); 451 449 452 450 //Make sure the we are pointing directly to a type 453 Type* base = rty->get_base(); 454 if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 455 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 451 Type* base = pty->get_base(); 452 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 456 453 457 454 //Make sure that typed isn't mutex … … 459 456 } 460 457 461 void MutexKeyword::addStatments( FunctionDecl* func,CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {458 void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) { 462 459 ObjectDecl * monitors = new ObjectDecl( 463 460 "__monitors", … … 490 487 ); 491 488 492 assert(generic_func);493 494 489 //in reverse order : 495 // monitor_guard_t __guard = { __monitors, # , func};490 // monitor_guard_t __guard = { __monitors, # }; 496 491 body->push_front( 497 492 new DeclStmt( noLabels, new ObjectDecl( … … 507 502 { 508 503 new SingleInit( new VariableExpr( monitors ) ), 509 new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) ), 510 new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) ) 504 new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) ) 511 505 }, 512 506 noDesignators, … … 523 517 // General entry routine 524 518 //============================================================================================= 525 void ThreadStarter::postvisit(FunctionDecl * decl) { 526 if( ! CodeGen::isConstructor(decl->get_name()) ) return; 519 void ThreadStarter::visit(FunctionDecl * decl) { 520 Visitor::visit(decl); 521 522 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 527 523 528 524 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 529 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 525 auto ptr = dynamic_cast< PointerType * >( param->get_type() ); 526 // if( ptr ) std::cerr << "FRED1" << std::endl; 527 auto type = dynamic_cast< StructInstType * >( ptr->get_base() ); 530 528 // if( type ) std::cerr << "FRED2" << std::endl; 531 529 if( type && type->get_baseStruct()->is_thread() ) {
Note:
See TracChangeset
for help on using the changeset viewer.