Changes in src/SymTab/Validate.cc [a09e45b:1f370451]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
ra09e45b r1f370451 81 81 82 82 namespace SymTab { 83 struct HoistStruct final : public WithDeclsToAdd, public WithGuards { 83 class HoistStruct final : public Visitor { 84 template< typename Visitor > 85 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 86 template< typename Visitor > 87 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 88 public: 84 89 /// Flattens nested struct types 85 90 static void hoistStruct( std::list< Declaration * > &translationUnit ); 86 91 87 void previsit( EnumInstType * enumInstType ); 88 void previsit( StructInstType * structInstType ); 89 void previsit( UnionInstType * unionInstType ); 90 void previsit( StructDecl * aggregateDecl ); 91 void previsit( UnionDecl * aggregateDecl ); 92 92 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 93 94 virtual void visit( EnumInstType *enumInstType ); 95 virtual void visit( StructInstType *structInstType ); 96 virtual void visit( UnionInstType *unionInstType ); 97 virtual void visit( StructDecl *aggregateDecl ); 98 virtual void visit( UnionDecl *aggregateDecl ); 99 100 virtual void visit( CompoundStmt *compoundStmt ); 101 virtual void visit( SwitchStmt *switchStmt ); 93 102 private: 103 HoistStruct(); 104 94 105 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 95 106 96 bool inStruct = false; 107 std::list< Declaration * > declsToAdd, declsToAddAfter; 108 bool inStruct; 97 109 }; 98 110 … … 293 305 294 306 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 295 PassVisitor<HoistStruct> hoister; 296 acceptAll( translationUnit, hoister ); 307 HoistStruct hoister; 308 acceptAndAdd( translationUnit, hoister ); 309 } 310 311 HoistStruct::HoistStruct() : inStruct( false ) { 297 312 } 298 313 … … 305 320 if ( inStruct ) { 306 321 // Add elements in stack order corresponding to nesting structure. 307 declsToAddBefore.push_front( aggregateDecl ); 322 declsToAdd.push_front( aggregateDecl ); 323 Visitor::visit( aggregateDecl ); 308 324 } else { 309 GuardValue( inStruct );310 325 inStruct = true; 326 Visitor::visit( aggregateDecl ); 327 inStruct = false; 311 328 } // if 312 329 // Always remove the hoisted aggregate from the inner structure. 313 GuardAction( [this, aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); });314 } 315 316 void HoistStruct:: previsit( EnumInstType * inst) {317 if ( inst->baseEnum) {318 declsToAdd Before.push_front( inst->baseEnum);319 } 320 } 321 322 void HoistStruct:: previsit( StructInstType * inst) {323 if ( inst->baseStruct) {324 declsToAdd Before.push_front( inst->baseStruct);325 } 326 } 327 328 void HoistStruct:: previsit( UnionInstType * inst) {329 if ( inst->baseUnion) {330 declsToAdd Before.push_front( inst->baseUnion);331 } 332 } 333 334 void HoistStruct:: previsit( StructDecl *aggregateDecl ) {330 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 331 } 332 333 void HoistStruct::visit( EnumInstType *structInstType ) { 334 if ( structInstType->get_baseEnum() ) { 335 declsToAdd.push_front( structInstType->get_baseEnum() ); 336 } 337 } 338 339 void HoistStruct::visit( StructInstType *structInstType ) { 340 if ( structInstType->get_baseStruct() ) { 341 declsToAdd.push_front( structInstType->get_baseStruct() ); 342 } 343 } 344 345 void HoistStruct::visit( UnionInstType *structInstType ) { 346 if ( structInstType->get_baseUnion() ) { 347 declsToAdd.push_front( structInstType->get_baseUnion() ); 348 } 349 } 350 351 void HoistStruct::visit( StructDecl *aggregateDecl ) { 335 352 handleAggregate( aggregateDecl ); 336 353 } 337 354 338 void HoistStruct:: previsit( UnionDecl *aggregateDecl ) {355 void HoistStruct::visit( UnionDecl *aggregateDecl ) { 339 356 handleAggregate( aggregateDecl ); 357 } 358 359 void HoistStruct::visit( CompoundStmt *compoundStmt ) { 360 addVisit( compoundStmt, *this ); 361 } 362 363 void HoistStruct::visit( SwitchStmt *switchStmt ) { 364 addVisit( switchStmt, *this ); 340 365 } 341 366
Note:
See TracChangeset
for help on using the changeset viewer.