Ignore:
Timestamp:
Jul 19, 2017, 11:49:33 AM (8 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:
9cc0472
Parents:
fea3faa (diff), a57cb58 (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/GenInit.cc

    rfea3faa rb826e6b  
    4444        }
    4545
    46         class ReturnFixer : public WithStmtsToAdd, public WithScopes {
    47           public:
     46        struct ReturnFixer : public WithStmtsToAdd, public WithGuards {
    4847                /// consistently allocates a temporary variable for the return value
    4948                /// of a function so that anything which the resolver decides can be constructed
     
    5958        };
    6059
    61         class CtorDtor final : public GenPoly::PolyMutator {
    62           public:
    63                 typedef GenPoly::PolyMutator Parent;
    64                 using Parent::mutate;
     60        struct CtorDtor : public WithGuards, public WithShortCircuiting  {
    6561                /// create constructor and destructor statements for object declarations.
    6662                /// the actual call statements will be added in after the resolver has run
     
    6965                static void generateCtorDtor( std::list< Declaration * > &translationUnit );
    7066
    71                 virtual DeclarationWithType * mutate( ObjectDecl * ) override;
    72                 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override;
     67                void previsit( ObjectDecl * );
     68                void previsit( FunctionDecl *functionDecl );
     69
    7370                // should not traverse into any of these declarations to find objects
    7471                // that need to be constructed or destructed
    75                 virtual Declaration* mutate( StructDecl *aggregateDecl ) override;
    76                 virtual Declaration* mutate( UnionDecl *aggregateDecl ) override { return aggregateDecl; }
    77                 virtual Declaration* mutate( EnumDecl *aggregateDecl ) override { return aggregateDecl; }
    78                 virtual Declaration* mutate( TraitDecl *aggregateDecl ) override { return aggregateDecl; }
    79                 virtual TypeDecl* mutate( TypeDecl *typeDecl ) override { return typeDecl; }
    80                 virtual Declaration* mutate( TypedefDecl *typeDecl ) override { return typeDecl; }
    81 
    82                 virtual Type * mutate( FunctionType *funcType ) override { return funcType; }
    83 
    84                 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override;
     72                void previsit( StructDecl *aggregateDecl );
     73                void previsit( __attribute__((unused)) UnionDecl    * aggregateDecl ) { visit_children = false; }
     74                void previsit( __attribute__((unused)) EnumDecl     * aggregateDecl ) { visit_children = false; }
     75                void previsit( __attribute__((unused)) TraitDecl    * aggregateDecl ) { visit_children = false; }
     76                void previsit( __attribute__((unused)) TypeDecl     * typeDecl )      { visit_children = false; }
     77                void previsit( __attribute__((unused)) TypedefDecl  * typeDecl )      { visit_children = false; }
     78                void previsit( __attribute__((unused)) FunctionType * funcType )      { visit_children = false; }
     79
     80                void previsit( CompoundStmt * compoundStmt );
    8581
    8682          private:
     
    211207
    212208        void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) {
    213                 CtorDtor ctordtor;
    214                 mutateAll( translationUnit, ctordtor );
     209                PassVisitor<CtorDtor> ctordtor;
     210                acceptAll( translationUnit, ctordtor );
    215211        }
    216212
     
    289285        }
    290286
    291         DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) {
     287        void CtorDtor::previsit( ObjectDecl * objDecl ) {
    292288                handleDWT( objDecl );
    293289                // hands off if @=, extern, builtin, etc.
     
    301297                        objDecl->set_init( genCtorInit( objDecl ) );
    302298                }
    303                 return Parent::mutate( objDecl );
    304         }
    305 
    306         DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {
    307                 ValueGuard< bool > oldInFunc = inFunction;
     299        }
     300
     301        void CtorDtor::previsit( FunctionDecl *functionDecl ) {
     302                GuardValue( inFunction );
    308303                inFunction = true;
    309304
    310305                handleDWT( functionDecl );
    311306
    312                 managedTypes.beginScope();
     307                GuardScope( managedTypes );
    313308                // go through assertions and recursively add seen ctor/dtors
    314309                for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) {
     
    317312                        }
    318313                }
    319                 // parameters should not be constructed and destructed, so don't mutate FunctionType
    320                 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
    321 
    322                 managedTypes.endScope();
    323                 return functionDecl;
    324         }
    325 
    326         Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) {
     314
     315                PassVisitor<CtorDtor> newCtorDtor;
     316                newCtorDtor.pass = *this;
     317                maybeAccept( functionDecl->get_statements(), newCtorDtor );
     318                visit_children = false;  // do not try and construct parameters or forall parameters - must happen after maybeAccept
     319        }
     320
     321        void CtorDtor::previsit( StructDecl *aggregateDecl ) {
     322                visit_children = false; // do not try to construct and destruct aggregate members
     323
    327324                // don't construct members, but need to take note if there is a managed member,
    328325                // because that means that this type is also managed
     
    336333                        }
    337334                }
    338                 return aggregateDecl;
    339         }
    340 
    341         CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) {
    342                 managedTypes.beginScope();
    343                 CompoundStmt * stmt = Parent::mutate( compoundStmt );
    344                 managedTypes.endScope();
    345                 return stmt;
    346         }
    347 
     335        }
     336
     337        void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt ) {
     338                GuardScope( managedTypes );
     339        }
    348340} // namespace InitTweak
    349341
Note: See TracChangeset for help on using the changeset viewer.