Changeset a09e45b


Ignore:
Timestamp:
Dec 1, 2017, 11:25:58 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

Convert HoistStruct? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rad6cd6d ra09e45b  
    8181
    8282namespace 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 {
    8984                /// Flattens nested struct types
    9085                static void hoistStruct( std::list< Declaration * > &translationUnit );
    9186
    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
    10293          private:
    103                 HoistStruct();
    104 
    10594                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
    10695
    107                 std::list< Declaration * > declsToAdd, declsToAddAfter;
    108                 bool inStruct;
     96                bool inStruct = false;
    10997        };
    11098
     
    305293
    306294        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 );
    312297        }
    313298
     
    320305                if ( inStruct ) {
    321306                        // Add elements in stack order corresponding to nesting structure.
    322                         declsToAdd.push_front( aggregateDecl );
    323                         Visitor::visit( aggregateDecl );
     307                        declsToAddBefore.push_front( aggregateDecl );
    324308                } else {
     309                        GuardValue( inStruct );
    325310                        inStruct = true;
    326                         Visitor::visit( aggregateDecl );
    327                         inStruct = false;
    328311                } // if
    329312                // 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 ) {
    352335                handleAggregate( aggregateDecl );
    353336        }
    354337
    355         void HoistStruct::visit( UnionDecl *aggregateDecl ) {
     338        void HoistStruct::previsit( UnionDecl * aggregateDecl ) {
    356339                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 );
    365340        }
    366341
Note: See TracChangeset for help on using the changeset viewer.