Changeset a09e45b
- Timestamp:
- Dec 1, 2017, 11:25:58 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d16d159
- Parents:
- ad6cd6d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rad6cd6d ra09e45b 81 81 82 82 namespace SymTab { 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: 83 struct HoistStruct final : public WithDeclsToAdd, public WithGuards { 89 84 /// Flattens nested struct types 90 85 static void hoistStruct( std::list< Declaration * > &translationUnit ); 91 86 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 ); 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 102 93 private: 103 HoistStruct();104 105 94 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 106 95 107 std::list< Declaration * > declsToAdd, declsToAddAfter; 108 bool inStruct; 96 bool inStruct = false; 109 97 }; 110 98 … … 305 293 306 294 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 307 HoistStruct hoister; 308 acceptAndAdd( translationUnit, hoister ); 309 } 310 311 HoistStruct::HoistStruct() : inStruct( false ) { 295 PassVisitor<HoistStruct> hoister; 296 acceptAll( translationUnit, hoister ); 312 297 } 313 298 … … 320 305 if ( inStruct ) { 321 306 // Add elements in stack order corresponding to nesting structure. 322 declsToAdd.push_front( aggregateDecl ); 323 Visitor::visit( aggregateDecl ); 307 declsToAddBefore.push_front( aggregateDecl ); 324 308 } else { 309 GuardValue( inStruct ); 325 310 inStruct = true; 326 Visitor::visit( aggregateDecl );327 inStruct = false;328 311 } // if 329 312 // Always remove the hoisted aggregate from the inner structure. 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 ) {313 GuardAction( [this, aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); } ); 314 } 315 316 void HoistStruct::previsit( EnumInstType * inst ) { 317 if ( inst->baseEnum ) { 318 declsToAddBefore.push_front( inst->baseEnum ); 319 } 320 } 321 322 void HoistStruct::previsit( StructInstType * inst ) { 323 if ( inst->baseStruct ) { 324 declsToAddBefore.push_front( inst->baseStruct ); 325 } 326 } 327 328 void HoistStruct::previsit( UnionInstType * inst ) { 329 if ( inst->baseUnion ) { 330 declsToAddBefore.push_front( inst->baseUnion ); 331 } 332 } 333 334 void HoistStruct::previsit( StructDecl * aggregateDecl ) { 352 335 handleAggregate( aggregateDecl ); 353 336 } 354 337 355 void HoistStruct:: visit( UnionDecl *aggregateDecl ) {338 void HoistStruct::previsit( UnionDecl * aggregateDecl ) { 356 339 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 );365 340 } 366 341
Note: See TracChangeset
for help on using the changeset viewer.