Changes in src/Concurrency/Keywords.cc [2065609:97e3296]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Concurrency/Keywords.cc ¶
r2065609 r97e3296 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* ); … … 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 } … … 225 229 // } } 226 230 // 227 class ThreadStarter final {231 class ThreadStarter final : public Visitor { 228 232 public: 229 233 230 void postvisit( FunctionDecl * decl ); 234 using Visitor::visit; 235 virtual void visit( FunctionDecl * decl ) override final; 231 236 232 237 void addStartStatement( FunctionDecl * decl, DeclarationWithType * param ); 233 238 234 239 static void implement( std::list< Declaration * > & translationUnit ) { 235 PassVisitor< ThreadStarter >impl;240 ThreadStarter impl; 236 241 acceptAll( translationUnit, impl ); 237 242 } … … 258 263 // Generic keyword implementation 259 264 //============================================================================================= 260 void ConcurrentSueKeyword::postvisit(StructDecl * decl) { 265 void ConcurrentSueKeyword::visit(StructDecl * decl) { 266 Visitor::visit(decl); 261 267 if( decl->get_name() == type_name && decl->has_body() ) { 262 268 assert( !type_decl ); … … 292 298 LinkageSpec::Cforall, 293 299 nullptr, 294 new ReferenceType(300 new PointerType( 295 301 noQualifiers, 296 302 new StructInstType( … … 346 352 } 347 353 348 declsToAdd Before.push_back( forward );349 if( needs_main ) declsToAdd Before.push_back( main_decl );350 declsToAdd Before.push_back( get_decl );354 declsToAdd.push_back( forward ); 355 if( needs_main ) declsToAdd.push_back( main_decl ); 356 declsToAdd.push_back( get_decl ); 351 357 352 358 return get_decl; … … 398 404 //============================================================================================= 399 405 400 void MutexKeyword::postvisit(FunctionDecl* decl) { 406 void MutexKeyword::visit(FunctionDecl* decl) { 407 Visitor::visit(decl); 401 408 402 409 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); … … 416 423 } 417 424 418 void MutexKeyword::postvisit(StructDecl* decl) { 425 void MutexKeyword::visit(StructDecl* decl) { 426 Visitor::visit(decl); 419 427 420 428 if( decl->get_name() == "monitor_desc" ) { … … 447 455 448 456 //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 );457 PointerType* pty = dynamic_cast< PointerType * >( ty ); 458 if( ! pty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg ); 451 459 452 460 //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 ); 461 Type* base = pty->get_base(); 462 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 456 463 457 464 //Make sure that typed isn't mutex … … 523 530 // General entry routine 524 531 //============================================================================================= 525 void ThreadStarter::postvisit(FunctionDecl * decl) { 526 if( ! CodeGen::isConstructor(decl->get_name()) ) return; 532 void ThreadStarter::visit(FunctionDecl * decl) { 533 Visitor::visit(decl); 534 535 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 527 536 528 537 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 529 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 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() ); 530 541 // if( type ) std::cerr << "FRED2" << std::endl; 531 542 if( type && type->get_baseStruct()->is_thread() ) {
Note: See TracChangeset
for help on using the changeset viewer.