Changeset e5d9274 for src/InitTweak


Ignore:
Timestamp:
Jun 2, 2022, 3:11:21 PM (3 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
ced5e2a
Parents:
015925a (diff), fc134a48 (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

Location:
src/InitTweak
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInitNew.cpp

    r015925a re5d9274  
    454454
    455455                auto expr = new ast::ImplicitCopyCtorExpr( appExpr->location, mutExpr );
    456                 // Move the type substitution to the new top-level, if it is attached to the appExpr.
    457                 // Ensure it is not deleted with the ImplicitCopyCtorExpr by removing it before deletion.
    458                 // The substitution is needed to obtain the type of temporary variables so that copy constructor
    459                 // calls can be resolved.
     456                // Move the type substitution to the new top-level. The substitution
     457                // is needed to obtain the type of temporary variables so that copy
     458                // constructor calls can be resolved.
    460459                assert( typeSubs );
    461                 // assert (mutExpr->env);
    462460                expr->env = tmp;
    463                 // mutExpr->env = nullptr;
    464                 //std::swap( expr->env, appExpr->env );
    465461                return expr;
    466462        }
    467463
    468464        void ResolveCopyCtors::previsit(const ast::Expr * expr) {
    469                 if (expr->env) {
    470                         GuardValue(env);
    471                         GuardValue(envModified);
    472                         env = expr->env->clone();
    473                         envModified = false;
    474                 }
     465                if ( nullptr == expr->env ) {
     466                        return;
     467                }
     468                GuardValue( env ) = expr->env->clone();
     469                GuardValue( envModified ) = false;
    475470        }
    476471
    477472        const ast::Expr * ResolveCopyCtors::postvisit(const ast::Expr * expr) {
    478                 if (expr->env) {
    479                         if (envModified) {
    480                                 auto mutExpr = mutate(expr);
    481                                 mutExpr->env = env;
    482                                 return mutExpr;
    483                         }
    484                         else {
    485                                 // env was not mutated, skip and delete the shallow copy
    486                                 delete env;
    487                                 return expr;
    488                         }
    489                 }
    490                 else {
     473                // No local environment, skip.
     474                if ( nullptr == expr->env ) {
     475                        return expr;
     476                // Environment was modified, mutate and replace.
     477                } else if ( envModified ) {
     478                        auto mutExpr = mutate(expr);
     479                        mutExpr->env = env;
     480                        return mutExpr;
     481                // Environment was not mutated, delete the shallow copy before guard.
     482                } else {
     483                        delete env;
    491484                        return expr;
    492485                }
     
    497490        const ast::Expr * ResolveCopyCtors::makeCtorDtor( const std::string & fname, const ast::ObjectDecl * var, const ast::Expr * cpArg ) {
    498491                assert( var );
    499                 assert (var->isManaged());
    500                 assert (!cpArg || cpArg->isManaged());
     492                assert( var->isManaged() );
     493                assert( !cpArg || cpArg->isManaged() );
    501494                // arrays are not copy constructed, so this should always be an ExprStmt
    502495                ast::ptr< ast::Stmt > stmt = genCtorDtor(var->location, fname, var, cpArg );
     
    504497                auto exprStmt = stmt.strict_as<ast::ImplicitCtorDtorStmt>()->callStmt.strict_as<ast::ExprStmt>();
    505498                ast::ptr<ast::Expr> untyped = exprStmt->expr; // take ownership of expr
    506                 // exprStmt->expr = nullptr;
    507499
    508500                // resolve copy constructor
     
    516508                        env->add( *resolved->env );
    517509                        envModified = true;
    518                         // delete resolved->env;
    519510                        auto mut = mutate(resolved.get());
    520511                        assertf(mut == resolved.get(), "newly resolved expression must be unique");
    521512                        mut->env = nullptr;
    522513                } // if
    523                 // delete stmt;
    524514                if ( auto assign = resolved.as<ast::TupleAssignExpr>() ) {
    525515                        // fix newly generated StmtExpr
  • src/InitTweak/GenInit.cc

    r015925a re5d9274  
    368368
    369369        struct ReturnFixer_New final :
    370                         public ast::WithStmtsToAdd<>, ast::WithGuards {
     370                        public ast::WithStmtsToAdd<>, ast::WithGuards, ast::WithShortCircuiting {
    371371                void previsit( const ast::FunctionDecl * decl );
    372372                const ast::ReturnStmt * previsit( const ast::ReturnStmt * stmt );
     
    376376
    377377        void ReturnFixer_New::previsit( const ast::FunctionDecl * decl ) {
     378                if (decl->linkage == ast::Linkage::Intrinsic) visit_children = false;
    378379                GuardValue( funcDecl ) = decl;
    379380        }
  • src/InitTweak/module.mk

    r015925a re5d9274  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Rob Schluntz
    13 ## Last Modified On : Fri May 13 11:36:24 2016
    14 ## Update Count     : 3
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:31:00 2022
     14## Update Count     : 4
    1515###############################################################################
    1616
    17 SRC += \
    18         InitTweak/FixGlobalInit.cc \
    19         InitTweak/FixGlobalInit.h \
    20         InitTweak/FixInit.cc \
    21         InitTweak/FixInit.h \
    22         InitTweak/GenInit.cc \
    23         InitTweak/GenInit.h \
    24         InitTweak/InitTweak.cc \
    25         InitTweak/InitTweak.h \
    26         InitTweak/FixInitNew.cpp
    27 
    28 SRCDEMANGLE += \
     17SRC_INITTWEAK = \
    2918        InitTweak/GenInit.cc \
    3019        InitTweak/GenInit.h \
     
    3221        InitTweak/InitTweak.h
    3322
     23SRC += $(SRC_INITTWEAK) \
     24        InitTweak/FixGlobalInit.cc \
     25        InitTweak/FixGlobalInit.h \
     26        InitTweak/FixInit.cc \
     27        InitTweak/FixInit.h \
     28        InitTweak/FixInitNew.cpp
     29
     30SRCDEMANGLE += $(SRC_INITTWEAK)
Note: See TracChangeset for help on using the changeset viewer.