Changeset 52c14b3


Ignore:
Timestamp:
Feb 8, 2017, 9:51:14 AM (7 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:
4fbdd1e3, 84e2523, b7b8674
Parents:
35b1bf4
Message:

fix scoping issues for labels when inserting destructors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r35b1bf4 r52c14b3  
    104104                        virtual void visit( CompoundStmt *compoundStmt ) override;
    105105                        virtual void visit( DeclStmt *stmt ) override;
     106
     107                        // don't go into other functions
     108                        virtual void visit( FunctionDecl *decl ) override {}
     109
    106110                  protected:
    107111                        ObjectSet curVars;
     
    166170                        typedef std::list< OrderedDecls > OrderedDeclsStack;
    167171
    168                         InsertDtors( LabelFinder & finder ) : labelVars( finder.vars ) {}
     172                        InsertDtors( LabelFinder & finder ) : finder( finder ), labelVars( finder.vars ) {}
    169173
    170174                        using Parent::visit;
    171175
    172176                        virtual void visit( ObjectDecl * objDecl ) override;
     177                        virtual void visit( FunctionDecl * funcDecl ) override;
    173178
    174179                        virtual void visit( CompoundStmt * compoundStmt ) override;
     
    178183                        void handleGoto( BranchStmt * stmt );
    179184
     185                        LabelFinder & finder;
    180186                        LabelFinder::LabelMap & labelVars;
    181187                        OrderedDeclsStack reverseDeclOrder;
     
    318324                        LabelFinder finder;
    319325                        InsertDtors inserter( finder );
    320                         acceptAll( translationUnit, finder );
    321326                        acceptAll( translationUnit, inserter );
    322327                }
     
    778783                }
    779784
    780                 void ObjDeclCollector::visit( CompoundStmt *compoundStmt ) {
     785                void ObjDeclCollector::visit( CompoundStmt * compoundStmt ) {
    781786                        std::set< ObjectDecl * > prevVars = curVars;
    782787                        Parent::visit( compoundStmt );
     
    784789                }
    785790
    786                 void ObjDeclCollector::visit( DeclStmt *stmt ) {
     791                void ObjDeclCollector::visit( DeclStmt * stmt ) {
    787792                        // keep track of all variables currently in scope
    788793                        if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) {
     
    828833                        } // if
    829834                        Parent::visit( objDecl );
     835                }
     836
     837                template< typename Visitor >
     838                void handleFuncDecl( FunctionDecl * funcDecl, Visitor & visitor ) {
     839                        maybeAccept( funcDecl->get_functionType(), visitor );
     840                        acceptAll( funcDecl->get_oldDecls(), visitor );
     841                        maybeAccept( funcDecl->get_statements(), visitor );
     842                }
     843
     844                void InsertDtors::visit( FunctionDecl * funcDecl ) {
     845                        // each function needs to have its own set of labels
     846                        ValueGuard< LabelFinder::LabelMap > oldLabels( labelVars );
     847                        labelVars.clear();
     848                        handleFuncDecl( funcDecl, finder );
     849
     850                        // all labels for this function have been collected, insert destructors as appropriate.
     851                        // can't be Parent::mutate, because ObjDeclCollector bottoms out on FunctionDecl
     852                        handleFuncDecl( funcDecl, *this );
    830853                }
    831854
Note: See TracChangeset for help on using the changeset viewer.