Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rba3706f r5fe35d6  
    4949#include "SynTree/Expression.h"        // for UniqueExpr, VariableExpr, Unty...
    5050#include "SynTree/Initializer.h"       // for ConstructorInit, SingleInit
    51 #include "SynTree/Label.h"             // for Label, operator<
     51#include "SynTree/Label.h"             // for Label, noLabels, operator<
    5252#include "SynTree/Mutator.h"           // for mutateAll, Mutator, maybeMutate
    5353#include "SynTree/Statement.h"         // for ExprStmt, CompoundStmt, Branch...
     
    393393                        if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types
    394394
    395                         // type may involve type variables, so apply type substitution to get temporary variable's actual type,
    396                         // since result type may not be substituted (e.g., if the type does not appear in the parameter list)
     395                        // type may involve type variables, so apply type substitution to get temporary variable's actual type.
    397396                        // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T).
     397                        result = result->clone();
    398398                        env->applyFree( result );
    399399                        ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr );
     
    544544                        // add all temporary declarations and their constructors
    545545                        for ( ObjectDecl * obj : tempDecls ) {
    546                                 stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     546                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    547547                        } // for
    548548                        for ( ObjectDecl * obj : returnDecls ) {
    549                                 stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     549                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    550550                        } // for
    551551
    552552                        // add destructors after current statement
    553553                        for ( Expression * dtor : dtors ) {
    554                                 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
     554                                stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) );
    555555                        } // for
    556556
     
    570570
    571571                        if ( returnDecl ) {
    572                                 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr );
     572                                UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) );
     573                                assign->get_args().push_back( new VariableExpr( returnDecl ) );
     574                                assign->get_args().push_back( callExpr );
     575                                // know the result type of the assignment is the type of the LHS (minus the pointer), so
     576                                // add that onto the assignment expression so that later steps have the necessary information
     577                                assign->set_result( returnDecl->get_type()->clone() );
     578
    573579                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    574580                                // move env from callExpr to retExpr
     
    598604                        if ( ! result->isVoid() ) {
    599605                                for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) {
    600                                         stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     606                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    601607                                } // for
    602608                                // add destructors after current statement
    603609                                for ( Expression * dtor : stmtExpr->get_dtors() ) {
    604                                         stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
     610                                        stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) );
    605611                                } // for
    606612                                // must have a non-empty body, otherwise it wouldn't have a result
    607613                                assert( ! stmts.empty() );
    608614                                assert( ! stmtExpr->get_returnDecls().empty() );
    609                                 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
     615                                stmts.push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
    610616                                stmtExpr->get_returnDecls().clear();
    611617                                stmtExpr->get_dtors().clear();
     
    685691
    686692                                                // generate body of if
    687                                                 CompoundStmt * initStmts = new CompoundStmt();
     693                                                CompoundStmt * initStmts = new CompoundStmt( noLabels );
    688694                                                std::list< Statement * > & body = initStmts->get_kids();
    689695                                                body.push_back( ctor );
    690                                                 body.push_back( new ExprStmt( setTrue ) );
     696                                                body.push_back( new ExprStmt( noLabels, setTrue ) );
    691697
    692698                                                // put it all together
    693                                                 IfStmt * ifStmt = new IfStmt( new VariableExpr( isUninitializedVar ), initStmts, 0 );
    694                                                 stmtsToAddAfter.push_back( new DeclStmt( isUninitializedVar ) );
     699                                                IfStmt * ifStmt = new IfStmt( noLabels, new VariableExpr( isUninitializedVar ), initStmts, 0 );
     700                                                stmtsToAddAfter.push_back( new DeclStmt( noLabels, isUninitializedVar ) );
    695701                                                stmtsToAddAfter.push_back( ifStmt );
    696702
     
    707713
    708714                                                        // void __objName_dtor_atexitN(...) {...}
    709                                                         FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     715                                                        FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    710716                                                        dtorCaller->fixUniqueId();
    711717                                                        dtorCaller->get_statements()->push_back( dtorStmt );
     
    715721                                                        callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) );
    716722
    717                                                         body.push_back( new ExprStmt( callAtexit ) );
     723                                                        body.push_back( new ExprStmt( noLabels, callAtexit ) );
    718724
    719725                                                        // hoist variable and dtor caller decls to list of decls that will be added into global scope
     
    11401146                        assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 );
    11411147
     1148                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
     1149                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );
     1150                        declsToAddBefore.push_back( tmp );
     1151
    11421152                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
    11431153                        ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() );
     
    11451155                        ctorExpr->set_callExpr( nullptr );
    11461156                        ctorExpr->set_env( nullptr );
    1147 
    1148                         // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    1149                         ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );
    1150                         declsToAddBefore.push_back( tmp );
    11511157                        delete ctorExpr;
    11521158
Note: See TracChangeset for help on using the changeset viewer.