Changeset b3fc977


Ignore:
Timestamp:
Jan 8, 2018, 3:24:24 PM (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:
f240484
Parents:
94e025a2
Message:

Merge MutatingResolver? pass into GenStructMemberCalls?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r94e025a2 rb3fc977  
    197197                };
    198198
    199                 struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer {
     199                struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer, public WithVisitorRef<GenStructMemberCalls> {
    200200                        /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors
    201201                        /// for any member that is missing a corresponding ctor/dtor call.
     
    203203                        static void generate( std::list< Declaration * > & translationUnit );
    204204
    205                         void previsit( FunctionDecl * funcDecl );
    206                         void postvisit( FunctionDecl * funcDecl );
    207 
    208                         void previsit( MemberExpr * memberExpr );
    209                         void previsit( ApplicationExpr * appExpr );
     205                        void premutate( FunctionDecl * funcDecl );
     206                        DeclarationWithType * postmutate( FunctionDecl * funcDecl );
     207
     208                        void premutate( MemberExpr * memberExpr );
     209                        void premutate( ApplicationExpr * appExpr );
     210
     211                        /// Note: this post mutate used to be in a separate visitor. If this pass breaks, one place to examine is whether it is
     212                        /// okay for this part of the recursion to occur alongside the rest.
     213                        Expression * postmutate( UntypedExpr * expr );
    210214
    211215                        SemanticError errors;
     
    220224                        bool isCtor = false; // true if current function is a constructor
    221225                        StructDecl * structDecl = nullptr;
    222                 };
    223 
    224                 // very simple resolver-like mutator class - used to
    225                 // resolve UntypedExprs that are found within newly
    226                 // generated constructor/destructor calls
    227                 class MutatingResolver final : public Mutator {
    228                   public:
    229                         MutatingResolver( SymTab::Indexer & indexer ) : indexer( indexer ) {}
    230 
    231                         using Mutator::mutate;
    232                         virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ) override;
    233                         virtual Expression* mutate( UntypedExpr *untypedExpr ) override;
    234 
    235                   private:
    236                         SymTab::Indexer & indexer;
    237226                };
    238227
     
    315304                void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) {
    316305                        PassVisitor<GenStructMemberCalls> warner;
    317                         acceptAll( translationUnit, warner );
     306                        mutateAll( translationUnit, warner );
    318307                }
    319308
     
    950939                }
    951940
    952                 void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
     941                void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) {
    953942                        GuardValue( function );
    954943                        GuardValue( unhandled );
     
    984973                }
    985974
    986                 void GenStructMemberCalls::postvisit( FunctionDecl * funcDecl ) {
     975                DeclarationWithType * GenStructMemberCalls::postmutate( FunctionDecl * funcDecl ) {
    987976                        // remove the unhandled objects from usedUninit, because a call is inserted
    988977                        // to handle them - only objects that are later constructed are used uninitialized.
     
    10381027                                                Statement * callStmt = stmt.front();
    10391028
    1040                                                 MutatingResolver resolver( indexer );
    10411029                                                try {
    1042                                                         callStmt->acceptMutator( resolver );
     1030                                                        callStmt->acceptMutator( *visitor );
    10431031                                                        if ( isCtor ) {
    10441032                                                                function->get_statements()->push_front( callStmt );
     
    10561044                                throw errors;
    10571045                        }
     1046                        return funcDecl;
    10581047                }
    10591048
     
    10811070                }
    10821071
    1083                 void GenStructMemberCalls::previsit( ApplicationExpr * appExpr ) {
     1072                void GenStructMemberCalls::premutate( ApplicationExpr * appExpr ) {
    10841073                        if ( ! checkWarnings( function ) ) {
    10851074                                visit_children = false;
     
    11061095                }
    11071096
    1108                 void GenStructMemberCalls::previsit( MemberExpr * memberExpr ) {
     1097                void GenStructMemberCalls::premutate( MemberExpr * memberExpr ) {
    11091098                        if ( ! checkWarnings( function ) || ! isCtor ) {
    11101099                                visit_children = false;
     
    11341123                }
    11351124
    1136                 DeclarationWithType * MutatingResolver::mutate( ObjectDecl * objectDecl ) {
    1137                         // add object to the indexer assumes that there will be no name collisions
    1138                         // in generated code. If this changes, add mutate methods for entities with
    1139                         // scope and call {enter,leave}Scope explicitly.
    1140                         indexer.addId( objectDecl );
    1141                         return objectDecl;
    1142                 }
    1143 
    1144                 Expression * MutatingResolver::mutate( UntypedExpr * untypedExpr ) {
     1125                Expression * GenStructMemberCalls::postmutate( UntypedExpr * untypedExpr ) {
    11451126                        Expression * newExpr = untypedExpr;
    11461127                        ResolvExpr::findVoidExpression( newExpr, indexer );
Note: See TracChangeset for help on using the changeset viewer.