Changes in src/InitTweak/FixInit.cc [ba3706f:5fe35d6]
- File:
-
- 1 edited
-
src/InitTweak/FixInit.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
rba3706f r5fe35d6 49 49 #include "SynTree/Expression.h" // for UniqueExpr, VariableExpr, Unty... 50 50 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit 51 #include "SynTree/Label.h" // for Label, operator<51 #include "SynTree/Label.h" // for Label, noLabels, operator< 52 52 #include "SynTree/Mutator.h" // for mutateAll, Mutator, maybeMutate 53 53 #include "SynTree/Statement.h" // for ExprStmt, CompoundStmt, Branch... … … 393 393 if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types 394 394 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. 397 396 // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T). 397 result = result->clone(); 398 398 env->applyFree( result ); 399 399 ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr ); … … 544 544 // add all temporary declarations and their constructors 545 545 for ( ObjectDecl * obj : tempDecls ) { 546 stmtsToAddBefore.push_back( new DeclStmt( obj ) );546 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 547 547 } // for 548 548 for ( ObjectDecl * obj : returnDecls ) { 549 stmtsToAddBefore.push_back( new DeclStmt( obj ) );549 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 550 550 } // for 551 551 552 552 // add destructors after current statement 553 553 for ( Expression * dtor : dtors ) { 554 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );554 stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) ); 555 555 } // for 556 556 … … 570 570 571 571 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 573 579 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 574 580 // move env from callExpr to retExpr … … 598 604 if ( ! result->isVoid() ) { 599 605 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) { 600 stmtsToAddBefore.push_back( new DeclStmt( obj ) );606 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 601 607 } // for 602 608 // add destructors after current statement 603 609 for ( Expression * dtor : stmtExpr->get_dtors() ) { 604 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );610 stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) ); 605 611 } // for 606 612 // must have a non-empty body, otherwise it wouldn't have a result 607 613 assert( ! stmts.empty() ); 608 614 assert( ! stmtExpr->get_returnDecls().empty() ); 609 stmts.push_back( new ExprStmt( n ew VariableExpr( stmtExpr->get_returnDecls().front() ) ) );615 stmts.push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 610 616 stmtExpr->get_returnDecls().clear(); 611 617 stmtExpr->get_dtors().clear(); … … 685 691 686 692 // generate body of if 687 CompoundStmt * initStmts = new CompoundStmt( );693 CompoundStmt * initStmts = new CompoundStmt( noLabels ); 688 694 std::list< Statement * > & body = initStmts->get_kids(); 689 695 body.push_back( ctor ); 690 body.push_back( new ExprStmt( setTrue ) );696 body.push_back( new ExprStmt( noLabels, setTrue ) ); 691 697 692 698 // put it all together 693 IfStmt * ifStmt = new IfStmt( n ew 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 ) ); 695 701 stmtsToAddAfter.push_back( ifStmt ); 696 702 … … 707 713 708 714 // 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 ) ); 710 716 dtorCaller->fixUniqueId(); 711 717 dtorCaller->get_statements()->push_back( dtorStmt ); … … 715 721 callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) ); 716 722 717 body.push_back( new ExprStmt( callAtexit ) );723 body.push_back( new ExprStmt( noLabels, callAtexit ) ); 718 724 719 725 // hoist variable and dtor caller decls to list of decls that will be added into global scope … … 1140 1146 assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 ); 1141 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(), ctorExpr->get_result()->clone(), nullptr ); 1150 declsToAddBefore.push_back( tmp ); 1151 1142 1152 // xxx - this can be TupleAssignExpr now. Need to properly handle this case. 1143 1153 ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() ); … … 1145 1155 ctorExpr->set_callExpr( nullptr ); 1146 1156 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 );1151 1157 delete ctorExpr; 1152 1158
Note:
See TracChangeset
for help on using the changeset viewer.