Changeset 36d0a80


Ignore:
Timestamp:
Oct 30, 2020, 3:49:48 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0e707bd
Parents:
f7e4f8e8
Message:

Switch to using ast::Pass::run in FixInitNew?.cpp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInitNew.cpp

    rf7e4f8e8 r36d0a80  
    6767
    6868                struct StmtExprResult {
    69                         static void link( std::list<ast::ptr<ast::Decl> > & translationUnit );
    70 
    7169                        const ast::StmtExpr * previsit( const ast::StmtExpr * stmtExpr );
    7270                };
    7371
     72                /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     73                /// function calls need their parameters to be copy constructed
    7474                struct InsertImplicitCalls : public ast::WithConstTypeSubstitution, public ast::WithShortCircuiting {
    75                         /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
    76                         /// function calls need their parameters to be copy constructed
    77                         static void insert( std::list<ast::ptr<ast::Decl> > & translationUnit );
    78 
    7975                        const ast::Expr * postvisit( const ast::ApplicationExpr * appExpr );
    8076
     
    8682                };
    8783
     84                /// generate temporary ObjectDecls for each argument and return value of each ImplicitCopyCtorExpr,
     85                /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both
     86                /// arguments and return value temporaries
    8887                struct ResolveCopyCtors final : public ast::WithGuards, public ast::WithStmtsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting, public ast::WithVisitorRef<ResolveCopyCtors> {
    89                         /// generate temporary ObjectDecls for each argument and return value of each ImplicitCopyCtorExpr,
    90                         /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both
    91                         /// arguments and return value temporaries
    92                         static void resolveImplicitCalls( std::list<ast::ptr<ast::Decl> > & translationUnit );
    93 
    9488                        const ast::Expr * postvisit( const ast::ImplicitCopyCtorExpr * impCpCtorExpr );
    9589                        const ast::StmtExpr * previsit( const ast::StmtExpr * stmtExpr );
     
    161155                };
    162156
     157                /// insert destructor calls at the appropriate places.  must happen before CtorInit nodes are removed
     158                /// (currently by FixInit)
    163159                struct InsertDtors final : public ObjDeclCollector, public ast::WithStmtsToAdd<> {
    164                         /// insert destructor calls at the appropriate places.  must happen before CtorInit nodes are removed
    165                         /// (currently by FixInit)
    166                         static void insert( std::list< ast::ptr<ast::Decl> > & translationUnit );
    167 
    168160                        typedef std::list< ObjectDecl * > OrderedDecls;
    169161                        typedef std::list< OrderedDecls > OrderedDeclsStack;
     
    185177                };
    186178
    187                 class FixInit : public ast::WithStmtsToAdd<> {
    188                   public:
    189                         /// expand each object declaration to use its constructor after it is declared.
     179                /// expand each object declaration to use its constructor after it is declared.
     180                struct FixInit : public ast::WithStmtsToAdd<> {
    190181                        static void fixInitializers( std::list< ast::ptr<ast::Decl> > &translationUnit );
    191182
     
    195186                };
    196187
     188                /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors
     189                /// for any member that is missing a corresponding ctor/dtor call.
     190                /// error if a member is used before constructed
    197191                struct GenStructMemberCalls final : public ast::WithGuards, public ast::WithShortCircuiting, public ast::WithSymbolTable, public ast::WithVisitorRef<GenStructMemberCalls> {
    198                         /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors
    199                         /// for any member that is missing a corresponding ctor/dtor call.
    200                         /// error if a member is used before constructed
    201                         static void generate( std::list< ast::ptr<ast::Decl> > & translationUnit );
    202 
    203192                        void previsit( const ast::FunctionDecl * funcDecl );
    204193                        const ast::DeclWithType * postvisit( const ast::FunctionDecl * funcDecl );
     
    224213                };
    225214
     215                /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument
    226216                struct FixCtorExprs final : public ast::WithDeclsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting {
    227                         /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument
    228                         static void fix( std::list< ast::ptr<ast::Decl> > & translationUnit );
    229 
    230217                        const ast::Expr * postvisit( const ast::ConstructorExpr * ctorExpr );
    231218                };
    232219
     220                /// add CompoundStmts around top-level expressions so that temporaries are destroyed in the correct places.
    233221                struct SplitExpressions : public ast::WithShortCircuiting {
    234                         /// add CompoundStmts around top-level expressions so that temporaries are destroyed in the correct places.
    235                         static void split( std::list<ast::ptr<ast::Decl> > & translationUnit );
    236 
    237222                        ast::Stmt * postvisit( const ast::ExprStmt * stmt );
    238223                        void previsit( const ast::TupleAssignExpr * expr );
     
    241226
    242227        void fix( std::list< ast::ptr<ast::Decl> > & translationUnit, bool inLibrary ) {
    243                 ast::Pass<SelfAssignChecker> checker;
    244                 accept_all( translationUnit, checker );
     228                ast::Pass<SelfAssignChecker>::run( translationUnit );
    245229
    246230                // fixes StmtExpr to properly link to their resulting expression
    247                 StmtExprResult::link( translationUnit );
     231                ast::Pass<StmtExprResult>::run( translationUnit );
    248232
    249233                // fixes ConstructorInit for global variables. should happen before fixInitializers.
     
    251235
    252236                // must happen before ResolveCopyCtors because temporaries have to be inserted into the correct scope
    253                 SplitExpressions::split( translationUnit );
    254 
    255                 InsertImplicitCalls::insert( translationUnit );
     237                ast::Pass<SplitExpressions>::run( translationUnit );
     238
     239                ast::Pass<InsertImplicitCalls>::run( translationUnit );
    256240
    257241                // Needs to happen before ResolveCopyCtors, because argument/return temporaries should not be considered in
    258242                // error checking branch statements
    259                 InsertDtors::insert( translationUnit );
    260 
    261                 ResolveCopyCtors::resolveImplicitCalls( translationUnit );
     243                {
     244                        ast::Pass<LabelFinder> finder;
     245                        ast::Pass<InsertDtors>::run( translationUnit, finder );
     246                }
     247
     248                ast::Pass<ResolveCopyCtors>::run( translationUnit );
    262249                FixInit::fixInitializers( translationUnit );
    263                 GenStructMemberCalls::generate( translationUnit );
     250                ast::Pass<GenStructMemberCalls>::run( translationUnit );
    264251
    265252                // Needs to happen after GenStructMemberCalls, since otherwise member constructors exprs
    266253                // don't have the correct form, and a member can be constructed more than once.
    267                 FixCtorExprs::fix( translationUnit );
     254                ast::Pass<FixCtorExprs>::run( translationUnit );
    268255        }
    269256
     
    319306
    320307                        return dtorFunc;
    321                 }
    322 
    323                 void StmtExprResult::link( std::list<ast::ptr<ast::Decl> > & translationUnit ) {
    324                         ast::Pass<StmtExprResult> linker;
    325                         accept_all( translationUnit, linker );
    326                 }
    327 
    328                 void SplitExpressions::split( std::list<ast::ptr<ast::Decl> > & translationUnit ) {
    329                         ast::Pass<SplitExpressions> splitter;
    330                         accept_all( translationUnit, splitter );
    331                 }
    332 
    333                 void InsertImplicitCalls::insert( std::list<ast::ptr<ast::Decl> > & translationUnit ) {
    334                         ast::Pass<InsertImplicitCalls> inserter;
    335                         accept_all( translationUnit, inserter );
    336                 }
    337 
    338                 void ResolveCopyCtors::resolveImplicitCalls( std::list< ast::ptr<ast::Decl> > & translationUnit ) {
    339                         ast::Pass<ResolveCopyCtors> resolver;
    340                         accept_all( translationUnit, resolver );
    341308                }
    342309
     
    359326                                throw errors;
    360327                        } // if
    361                 }
    362 
    363                 void InsertDtors::insert( std::list< ast::ptr<ast::Decl> > & translationUnit ) {
    364                         ast::Pass<LabelFinder> finder;
    365                         ast::Pass<InsertDtors> inserter( finder );
    366                         accept_all( translationUnit, inserter );
    367                 }
    368 
    369                 void GenStructMemberCalls::generate( std::list< ast::ptr<ast::Decl> > & translationUnit ) {
    370                         ast::Pass<GenStructMemberCalls> warner;
    371                         accept_all( translationUnit, warner );
    372                 }
    373 
    374                 void FixCtorExprs::fix( std::list< ast::ptr<ast::Decl> > & translationUnit ) {
    375                         ast::Pass<FixCtorExprs> fixer;
    376                         accept_all( translationUnit, fixer );
    377328                }
    378329
Note: See TracChangeset for help on using the changeset viewer.