Changeset a28bc02 for src/InitTweak
- Timestamp:
- May 11, 2017, 2:09:51 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 6a4f3d4
- Parents:
- ddbde34
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/InitTweak/FixInit.cc ¶
rddbde34 ra28bc02 361 361 FunctionType * ftype = dynamic_cast< FunctionType * >( GenPoly::getFunctionType( funcDecl->get_type() ) ); 362 362 assert( ftype ); 363 if ( (isConstructor( funcDecl->get_name() ) || funcDecl->get_name() == "?=?") && ftype->get_parameters().size() == 2 ) {363 if ( isConstructor( funcDecl->get_name() ) && ftype->get_parameters().size() == 2 ) { 364 364 Type * t1 = ftype->get_parameters().front()->get_type(); 365 365 Type * t2 = ftype->get_parameters().back()->get_type(); … … 367 367 368 368 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 369 // optimization: don't need to copy construct in order to call a copy constructor or 370 // assignment operator 369 // optimization: don't need to copy construct in order to call a copy constructor 371 370 return appExpr; 372 371 } // if … … 636 635 assert( ! stmtExpr->get_returnDecls().empty() ); 637 636 body->get_kids().push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 638 } 639 stmtExpr->get_returnDecls().clear(); 640 stmtExpr->get_dtors().clear(); 637 stmtExpr->get_returnDecls().clear(); 638 stmtExpr->get_dtors().clear(); 639 } 640 assert( stmtExpr->get_returnDecls().empty() ); 641 assert( stmtExpr->get_dtors().empty() ); 641 642 return stmtExpr; 642 643 } … … 667 668 stmtsToAdd.splice( stmtsToAdd.end(), fixer.stmtsToAdd ); 668 669 unqMap[unqExpr->get_id()] = unqExpr; 670 if ( unqCount[ unqExpr->get_id() ] == 0 ) { // insert destructor after the last use of the unique expression 671 stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] ); 672 } else { // remember dtors for last instance of unique expr 673 dtors[ unqExpr->get_id() ] = fixer.stmtsToAddAfter; 674 } 669 675 if ( UntypedExpr * deref = dynamic_cast< UntypedExpr * >( unqExpr->get_expr() ) ) { 670 676 // unique expression is now a dereference, because the inner expression is an lvalue returning function call. … … 675 681 getCallArg( deref, 0 ) = unqExpr; 676 682 addDeref.insert( unqExpr->get_id() ); 677 if ( unqCount[ unqExpr->get_id() ] == 0 ) { // insert destructor after the last use of the unique expression678 stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] );679 } else { // remember dtors for last instance of unique expr680 dtors[ unqExpr->get_id() ] = fixer.stmtsToAddAfter;681 }682 683 return deref; 683 684 } -
TabularUnified src/InitTweak/GenInit.cc ¶
rddbde34 ra28bc02 142 142 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address 143 143 // is being returned 144 // Note: under the assumption that assignments return *this, checking for ?=? here is an optimization, since it shouldn't be necessary to copy construct `this`. This is a temporary optimization until reference types are added, at which point this should be removed, along with the analogous optimization in copy constructor generation. 145 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_lvalue() ) { 144 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! returnVals.front()->get_type()->get_lvalue() ) { 146 145 // explicitly construct the return value using the return expression and the retVal object 147 146 assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() );
Note: See TracChangeset
for help on using the changeset viewer.