Changeset 5b40f30 for src/InitTweak
- Timestamp:
- Mar 15, 2016, 3:16:53 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- dac0aa9
- Parents:
- 972e6f7
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r972e6f7 r5b40f30 48 48 } 49 49 50 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the51 // declaration. This will (seemingly) cause the later phases to do the right thing with the assignment52 50 ObjectDecl *FixInit::mutate( ObjectDecl *objDecl ) { 53 51 if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) { … … 79 77 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ) ) { 80 78 if ( VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ) ) { 79 // check for Intrinsic only - don't want to remove all overridable dtors because autogenerated dtor 80 // will call all member dtors, and some members may have a user defined dtor. 81 81 if ( function->get_var()->get_name() == "^?{}" && function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 82 82 statements.erase(it++); -
src/InitTweak/RemoveInit.cc
r972e6f7 r5b40f30 29 29 namespace { 30 30 const std::list<Label> noLabels; 31 const std::list<Expression *> noDesignators; 31 32 } 32 33 … … 112 113 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address 113 114 // is being returned 114 // xxx - this should construct rather than assign115 115 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 116 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); 116 // ensure return value is not destructed by explicitly creating 117 // an empty SingleInit node wherein maybeConstruct is false 118 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), new ListInit( std::list<Initializer*>(), noDesignators, false ) ); 117 119 stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) ); 118 120 119 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 120 assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 121 assign->get_args().push_back( returnStmt->get_expr() ); 122 stmtsToAdd.push_back(new ExprStmt(noLabels, assign)); 121 // and explicitly create the constructor expression separately 122 UntypedExpr *construct = new UntypedExpr( new NameExpr( "?{}" ) ); 123 construct->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 124 construct->get_args().push_back( returnStmt->get_expr() ); 125 stmtsToAdd.push_back(new ExprStmt(noLabels, construct)); 123 126 124 127 returnStmt->set_expr( new VariableExpr( newObj ) );
Note: See TracChangeset
for help on using the changeset viewer.