Changeset ea23d10 for src/InitTweak


Ignore:
Timestamp:
Feb 8, 2017, 2:35:08 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
e994912, f923b5f
Parents:
424931d (diff), 4fbdd1e3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r424931d rea23d10  
    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
     
    952975                        std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) );
    953976                        for ( DeclarationWithType * member : diff ) {
    954                                 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", member->get_name(), " used before being constructed" );
     977                                emit( "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", member->get_name(), " used before being constructed" );
    955978                        }
    956979
     
    9971020                                                        }
    9981021                                                } catch ( SemanticError & error ) {
    999                                                         emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
     1022                                                        emit( "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
    10001023                                                }
    10011024                                        }
Note: See TracChangeset for help on using the changeset viewer.