Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    ra09e45b r1f370451  
    8181
    8282namespace 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:
    8489                /// Flattens nested struct types
    8590                static void hoistStruct( std::list< Declaration * > &translationUnit );
    8691
    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 );
    93102          private:
     103                HoistStruct();
     104
    94105                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
    95106
    96                 bool inStruct = false;
     107                std::list< Declaration * > declsToAdd, declsToAddAfter;
     108                bool inStruct;
    97109        };
    98110
     
    293305
    294306        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 ) {
    297312        }
    298313
     
    305320                if ( inStruct ) {
    306321                        // Add elements in stack order corresponding to nesting structure.
    307                         declsToAddBefore.push_front( aggregateDecl );
     322                        declsToAdd.push_front( aggregateDecl );
     323                        Visitor::visit( aggregateDecl );
    308324                } else {
    309                         GuardValue( inStruct );
    310325                        inStruct = true;
     326                        Visitor::visit( aggregateDecl );
     327                        inStruct = false;
    311328                } // if
    312329                // 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                         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 ) {
     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 ) {
    335352                handleAggregate( aggregateDecl );
    336353        }
    337354
    338         void HoistStruct::previsit( UnionDecl * aggregateDecl ) {
     355        void HoistStruct::visit( UnionDecl *aggregateDecl ) {
    339356                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 );
    340365        }
    341366
Note: See TracChangeset for help on using the changeset viewer.