Changeset 9a707e4e


Ignore:
Timestamp:
Sep 15, 2017, 5:05:48 PM (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:
eada3cf
Parents:
a4ca48c
Message:

Convert GenStructMemberCalls? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    ra4ca48c r9a707e4e  
    238238                };
    239239
    240                 class GenStructMemberCalls final : public SymTab::Indexer {
    241                   public:
    242                         typedef Indexer Parent;
     240                struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer {
    243241                        /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors
    244242                        /// for any member that is missing a corresponding ctor/dtor call.
     
    246244                        static void generate( std::list< Declaration * > & translationUnit );
    247245
    248                         using Parent::visit;
    249 
    250                         virtual void visit( FunctionDecl * funcDecl ) override;
    251 
    252                         virtual void visit( MemberExpr * memberExpr ) override;
    253                         virtual void visit( ApplicationExpr * appExpr ) override;
     246                        void previsit( FunctionDecl * funcDecl );
     247                        void postvisit( FunctionDecl * funcDecl );
     248
     249                        void previsit( MemberExpr * memberExpr );
     250                        void previsit( ApplicationExpr * appExpr );
    254251
    255252                        SemanticError errors;
     
    360357
    361358                void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) {
    362                         GenStructMemberCalls warner;
     359                        PassVisitor<GenStructMemberCalls> warner;
    363360                        acceptAll( translationUnit, warner );
    364361                }
     
    978975                }
    979976
    980                 void GenStructMemberCalls::visit( FunctionDecl * funcDecl ) {
    981                         ValueGuard< FunctionDecl * > oldFunction( funcDecl );
    982                         ValueGuard< std::set< DeclarationWithType * > > oldUnhandled( unhandled );
    983                         ValueGuard< std::map< DeclarationWithType *, CodeLocation > > oldUsedUninit( usedUninit );
    984                         ValueGuard< ObjectDecl * > oldThisParam( thisParam );
    985                         ValueGuard< bool > oldIsCtor( isCtor );
    986                         ValueGuard< StructDecl * > oldStructDecl( structDecl );
     977                void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
     978                        GuardValue( funcDecl );
     979                        GuardValue( unhandled );
     980                        GuardValue( usedUninit );
     981                        GuardValue( thisParam );
     982                        GuardValue( isCtor );
     983                        GuardValue( structDecl );
    987984                        errors = SemanticError();  // clear previous errors
    988985
     
    10101007                                }
    10111008                        }
    1012                         Parent::visit( function );
    1013 
     1009                }
     1010
     1011                void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) {
     1012                        for ( auto d : decls ) {
     1013                                indexer.addId( d );
     1014                        }
     1015                }
     1016
     1017                void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) {
     1018                        for ( auto td : tds ) {
     1019                                indexer.addType( td );
     1020                                addIds( indexer, td->assertions );
     1021                        }
     1022                }
     1023
     1024                void GenStructMemberCalls::postvisit( FunctionDecl * funcDecl ) {
    10141025                        // remove the unhandled objects from usedUninit, because a call is inserted
    10151026                        // to handle them - only objects that are later constructed are used uninitialized.
     
    10321043                        if ( ! unhandled.empty() ) {
    10331044                                // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors
    1034                                 enterScope();
    1035                                 maybeAccept( function->get_functionType(), *this );
     1045                                auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } );
     1046                                addTypes( indexer, function->type->forall );
     1047                                addIds( indexer, function->type->returnVals );
     1048                                addIds( indexer, function->type->parameters );
    10361049
    10371050                                // need to iterate through members in reverse in order for
     
    10631076                                                Statement * callStmt = stmt.front();
    10641077
    1065                                                 MutatingResolver resolver( *this );
     1078                                                MutatingResolver resolver( indexer );
    10661079                                                try {
    10671080                                                        callStmt->acceptMutator( resolver );
     
    10771090                                        }
    10781091                                }
    1079                                 leaveScope();
    10801092                        }
    10811093                        if (! errors.isEmpty()) {
     
    11071119                }
    11081120
    1109                 void GenStructMemberCalls::visit( ApplicationExpr * appExpr ) {
    1110                         if ( ! checkWarnings( function ) ) return;
     1121                void GenStructMemberCalls::previsit( ApplicationExpr * appExpr ) {
     1122                        if ( ! checkWarnings( function ) ) {
     1123                                visit_children = false;
     1124                                return;
     1125                        }
    11111126
    11121127                        std::string fname = getFunctionName( appExpr );
     
    11271142                                }
    11281143                        }
    1129                         Parent::visit( appExpr );
    1130                 }
    1131 
    1132                 void GenStructMemberCalls::visit( MemberExpr * memberExpr ) {
    1133                         if ( ! checkWarnings( function ) ) return;
    1134                         if ( ! isCtor ) return;
     1144                }
     1145
     1146                void GenStructMemberCalls::previsit( MemberExpr * memberExpr ) {
     1147                        if ( ! checkWarnings( function ) || ! isCtor ) {
     1148                                visit_children = false;
     1149                                return;
     1150                        }
    11351151
    11361152                        if ( isThisExpression( memberExpr->get_aggregate(), thisParam ) ) {
     
    11401156                                }
    11411157                        }
    1142                         Parent::visit( memberExpr );
    11431158                }
    11441159
Note: See TracChangeset for help on using the changeset viewer.