Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rb3fc977 r6dfa2e1  
    197197                };
    198198
    199                 struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer, public WithVisitorRef<GenStructMemberCalls> {
     199                struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer {
    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 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 );
     205                        void previsit( FunctionDecl * funcDecl );
     206                        void postvisit( FunctionDecl * funcDecl );
     207
     208                        void previsit( MemberExpr * memberExpr );
     209                        void previsit( ApplicationExpr * appExpr );
    214210
    215211                        SemanticError errors;
     
    224220                        bool isCtor = false; // true if current function is a constructor
    225221                        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;
    226237                };
    227238
     
    304315                void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) {
    305316                        PassVisitor<GenStructMemberCalls> warner;
    306                         mutateAll( translationUnit, warner );
     317                        acceptAll( translationUnit, warner );
    307318                }
    308319
     
    939950                }
    940951
    941                 void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) {
     952                void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
    942953                        GuardValue( function );
    943954                        GuardValue( unhandled );
     
    973984                }
    974985
    975                 DeclarationWithType * GenStructMemberCalls::postmutate( FunctionDecl * funcDecl ) {
     986                void GenStructMemberCalls::postvisit( FunctionDecl * funcDecl ) {
    976987                        // remove the unhandled objects from usedUninit, because a call is inserted
    977988                        // to handle them - only objects that are later constructed are used uninitialized.
     
    10271038                                                Statement * callStmt = stmt.front();
    10281039
     1040                                                MutatingResolver resolver( indexer );
    10291041                                                try {
    1030                                                         callStmt->acceptMutator( *visitor );
     1042                                                        callStmt->acceptMutator( resolver );
    10311043                                                        if ( isCtor ) {
    10321044                                                                function->get_statements()->push_front( callStmt );
     
    10441056                                throw errors;
    10451057                        }
    1046                         return funcDecl;
    10471058                }
    10481059
     
    10701081                }
    10711082
    1072                 void GenStructMemberCalls::premutate( ApplicationExpr * appExpr ) {
     1083                void GenStructMemberCalls::previsit( ApplicationExpr * appExpr ) {
    10731084                        if ( ! checkWarnings( function ) ) {
    10741085                                visit_children = false;
     
    10951106                }
    10961107
    1097                 void GenStructMemberCalls::premutate( MemberExpr * memberExpr ) {
     1108                void GenStructMemberCalls::previsit( MemberExpr * memberExpr ) {
    10981109                        if ( ! checkWarnings( function ) || ! isCtor ) {
    10991110                                visit_children = false;
     
    11231134                }
    11241135
    1125                 Expression * GenStructMemberCalls::postmutate( UntypedExpr * untypedExpr ) {
     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 ) {
    11261145                        Expression * newExpr = untypedExpr;
    11271146                        ResolvExpr::findVoidExpression( newExpr, indexer );
Note: See TracChangeset for help on using the changeset viewer.