Changes in src/InitTweak/FixInit.cc [5fe35d6:ba3706f]
- File:
-
- 1 edited
-
src/InitTweak/FixInit.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r5fe35d6 rba3706f 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, noLabels,operator<51 #include "SynTree/Label.h" // for Label, 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. 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) 396 397 // 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( noLabels,obj ) );546 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 547 547 } // for 548 548 for ( ObjectDecl * obj : returnDecls ) { 549 stmtsToAddBefore.push_back( new DeclStmt( noLabels,obj ) );549 stmtsToAddBefore.push_back( new DeclStmt( 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( noLabels,dtor ) );554 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 555 555 } // for 556 556 … … 570 570 571 571 if ( returnDecl ) { 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 572 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr ); 579 573 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 580 574 // move env from callExpr to retExpr … … 604 598 if ( ! result->isVoid() ) { 605 599 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) { 606 stmtsToAddBefore.push_back( new DeclStmt( noLabels,obj ) );600 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 607 601 } // for 608 602 // add destructors after current statement 609 603 for ( Expression * dtor : stmtExpr->get_dtors() ) { 610 stmtsToAddAfter.push_back( new ExprStmt( noLabels,dtor ) );604 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 611 605 } // for 612 606 // must have a non-empty body, otherwise it wouldn't have a result 613 607 assert( ! stmts.empty() ); 614 608 assert( ! stmtExpr->get_returnDecls().empty() ); 615 stmts.push_back( new ExprStmt( n oLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );609 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 616 610 stmtExpr->get_returnDecls().clear(); 617 611 stmtExpr->get_dtors().clear(); … … 691 685 692 686 // generate body of if 693 CompoundStmt * initStmts = new CompoundStmt( noLabels);687 CompoundStmt * initStmts = new CompoundStmt(); 694 688 std::list< Statement * > & body = initStmts->get_kids(); 695 689 body.push_back( ctor ); 696 body.push_back( new ExprStmt( noLabels,setTrue ) );690 body.push_back( new ExprStmt( setTrue ) ); 697 691 698 692 // put it all together 699 IfStmt * ifStmt = new IfStmt( n oLabels, new VariableExpr( isUninitializedVar ), initStmts, 0 );700 stmtsToAddAfter.push_back( new DeclStmt( noLabels,isUninitializedVar ) );693 IfStmt * ifStmt = new IfStmt( new VariableExpr( isUninitializedVar ), initStmts, 0 ); 694 stmtsToAddAfter.push_back( new DeclStmt( isUninitializedVar ) ); 701 695 stmtsToAddAfter.push_back( ifStmt ); 702 696 … … 713 707 714 708 // void __objName_dtor_atexitN(...) {...} 715 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels) );709 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 716 710 dtorCaller->fixUniqueId(); 717 711 dtorCaller->get_statements()->push_back( dtorStmt ); … … 721 715 callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) ); 722 716 723 body.push_back( new ExprStmt( noLabels,callAtexit ) );717 body.push_back( new ExprStmt( callAtexit ) ); 724 718 725 719 // hoist variable and dtor caller decls to list of decls that will be added into global scope … … 1146 1140 assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 ); 1147 1141 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 1152 1142 // xxx - this can be TupleAssignExpr now. Need to properly handle this case. 1153 1143 ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() ); … … 1155 1145 ctorExpr->set_callExpr( nullptr ); 1156 1146 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 ); 1157 1151 delete ctorExpr; 1158 1152
Note:
See TracChangeset
for help on using the changeset viewer.