Changes in src/Concurrency/Keywords.cc [97e3296:2065609]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Concurrency/Keywords.cc ¶
r97e3296 r2065609 19 19 #include <string> // for string, operator== 20 20 21 #include "Common/PassVisitor.h" // for PassVisitor 21 22 #include "Common/SemanticError.h" // for SemanticError 22 23 #include "Common/utility.h" // for deleteAll, map_range 23 #include "InitTweak/InitTweak.h" // for isConstructor 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 #include "InitTweak/InitTweak.h" // for getPointerBase 24 26 #include "Parser/LinkageSpec.h" // for Cforall 25 27 #include "SymTab/AddVisit.h" // for acceptAndAdd … … 45 47 46 48 //============================================================================================= 47 // Visitors declaration49 // Pass declarations 48 50 //============================================================================================= 49 51 … … 57 59 // static inline NewField_t * getter_name( MyType * this ) { return &this->newField; } 58 60 // 59 class ConcurrentSueKeyword : public Visitor { 60 protected: 61 template< typename Visitor > 62 friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 61 class ConcurrentSueKeyword : public WithDeclsToAdd { 63 62 public: 64 63 … … 68 67 virtual ~ConcurrentSueKeyword() {} 69 68 70 using Visitor::visit; 71 virtual void visit( StructDecl * decl ) override final; 69 void postvisit( StructDecl * decl ); 72 70 73 71 void handle( StructDecl * ); … … 85 83 bool needs_main; 86 84 87 std::list< Declaration * > declsToAdd, declsToAddAfter;88 85 StructDecl* type_decl = nullptr; 89 86 }; … … 116 113 117 114 static void implement( std::list< Declaration * > & translationUnit ) { 118 ThreadKeywordimpl;119 SymTab::acceptAndAdd( translationUnit, impl );115 PassVisitor< ThreadKeyword > impl; 116 acceptAll( translationUnit, impl ); 120 117 } 121 118 }; … … 147 144 148 145 static void implement( std::list< Declaration * > & translationUnit ) { 149 CoroutineKeywordimpl;150 SymTab::acceptAndAdd( translationUnit, impl );146 PassVisitor< CoroutineKeyword > impl; 147 acceptAll( translationUnit, impl ); 151 148 } 152 149 }; … … 178 175 179 176 static void implement( std::list< Declaration * > & translationUnit ) { 180 MonitorKeywordimpl;181 SymTab::acceptAndAdd( translationUnit, impl );177 PassVisitor< MonitorKeyword > impl; 178 acceptAll( translationUnit, impl ); 182 179 } 183 180 }; … … 191 188 // } } 192 189 // 193 class MutexKeyword final : public Visitor{190 class MutexKeyword final { 194 191 public: 195 192 196 using Visitor::visit; 197 virtual void visit( FunctionDecl * decl ) override final; 198 virtual void visit( StructDecl * decl ) override final; 193 void postvisit( FunctionDecl * decl ); 194 void postvisit( StructDecl * decl ); 199 195 200 196 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* ); … … 203 199 204 200 static void implement( std::list< Declaration * > & translationUnit ) { 205 MutexKeywordimpl;201 PassVisitor< MutexKeyword > impl; 206 202 acceptAll( translationUnit, impl ); 207 203 } … … 229 225 // } } 230 226 // 231 class ThreadStarter final : public Visitor{227 class ThreadStarter final { 232 228 public: 233 229 234 using Visitor::visit; 235 virtual void visit( FunctionDecl * decl ) override final; 230 void postvisit( FunctionDecl * decl ); 236 231 237 232 void addStartStatement( FunctionDecl * decl, DeclarationWithType * param ); 238 233 239 234 static void implement( std::list< Declaration * > & translationUnit ) { 240 ThreadStarterimpl;235 PassVisitor< ThreadStarter > impl; 241 236 acceptAll( translationUnit, impl ); 242 237 } … … 263 258 // Generic keyword implementation 264 259 //============================================================================================= 265 void ConcurrentSueKeyword::visit(StructDecl * decl) { 266 Visitor::visit(decl); 260 void ConcurrentSueKeyword::postvisit(StructDecl * decl) { 267 261 if( decl->get_name() == type_name && decl->has_body() ) { 268 262 assert( !type_decl ); … … 298 292 LinkageSpec::Cforall, 299 293 nullptr, 300 new PointerType(294 new ReferenceType( 301 295 noQualifiers, 302 296 new StructInstType( … … 352 346 } 353 347 354 declsToAdd .push_back( forward );355 if( needs_main ) declsToAdd .push_back( main_decl );356 declsToAdd .push_back( get_decl );348 declsToAddBefore.push_back( forward ); 349 if( needs_main ) declsToAddBefore.push_back( main_decl ); 350 declsToAddBefore.push_back( get_decl ); 357 351 358 352 return get_decl; … … 404 398 //============================================================================================= 405 399 406 void MutexKeyword::visit(FunctionDecl* decl) { 407 Visitor::visit(decl); 400 void MutexKeyword::postvisit(FunctionDecl* decl) { 408 401 409 402 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); … … 423 416 } 424 417 425 void MutexKeyword::visit(StructDecl* decl) { 426 Visitor::visit(decl); 418 void MutexKeyword::postvisit(StructDecl* decl) { 427 419 428 420 if( decl->get_name() == "monitor_desc" ) { … … 455 447 456 448 //Makes sure it's not a copy 457 PointerType* pty = dynamic_cast< PointerType * >( ty );458 if( ! pty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg );449 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty ); 450 if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg ); 459 451 460 452 //Make sure the we are pointing directly to a type 461 Type* base = pty->get_base(); 462 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 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 ); 463 456 464 457 //Make sure that typed isn't mutex … … 530 523 // General entry routine 531 524 //============================================================================================= 532 void ThreadStarter::visit(FunctionDecl * decl) { 533 Visitor::visit(decl); 534 535 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 525 void ThreadStarter::postvisit(FunctionDecl * decl) { 526 if( ! CodeGen::isConstructor(decl->get_name()) ) return; 536 527 537 528 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 538 auto ptr = dynamic_cast< PointerType * >( param->get_type() ); 539 // if( ptr ) std::cerr << "FRED1" << std::endl; 540 auto type = dynamic_cast< StructInstType * >( ptr->get_base() ); 529 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 541 530 // if( type ) std::cerr << "FRED2" << std::endl; 542 531 if( type && type->get_baseStruct()->is_thread() ) {
Note: See TracChangeset
for help on using the changeset viewer.