Changeset 20eacb7 for src/InitTweak
- Timestamp:
- Nov 9, 2017, 5:42:35 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 10dc6908
- Parents:
- 96fc67b
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r96fc67b r20eacb7 653 653 } 654 654 655 DeclarationWithType * getDtorFunc( ObjectDecl * objDecl, Statement * dtor, std::list< Statement * > & stmtsToAdd ) { 655 DeclarationWithType * getDtorFunc( ObjectDecl * objDecl, Statement * input, std::list< Statement * > & stmtsToAdd ) { 656 // unwrap implicit statement wrapper 657 assert( dtor ); 658 std::list< Expression * > matches; 659 collectCtorDtorCalls( dtor, matches ); 660 656 661 if ( dynamic_cast< ExprStmt * >( dtor ) ) { 657 if ( DeclarationWithType * func = getFunction( getCtorDtorCall( dtor ) ) ) { 662 // only one destructor call in the expression 663 if ( matches.size() == 1 ) { 664 DeclarationWithType * func = getFunction( matches.front() ); 665 assertf( func, "getFunction failed to find function in %s", toString( matches.front() ).c_str() ); 666 658 667 // cleanup argument must be a function, not an object (including function pointer) 659 668 if ( FunctionDecl * dtorFunc = dynamic_cast< FunctionDecl * > ( func ) ) { … … 677 686 ObjectDecl * thisParam = getParamThis( dtorFunc->type ); 678 687 Expression * replacement = new VariableExpr( thisParam ); 679 if ( ArrayType * at = dynamic_cast< ArrayType * >( replacement->result->stripReferences() ) ) { 688 689 Type * base = replacement->result->stripReferences(); 690 if ( dynamic_cast< ArrayType * >( base ) || dynamic_cast< TupleType * > ( base ) ) { 680 691 // need to cast away reference for array types, since the destructor is generated without the reference type 681 replacement = new CastExpr( replacement, at->clone() );692 replacement = new CastExpr( replacement, base->clone() ); 682 693 } 683 694 VarExprReplacer::replace( dtor, { std::make_pair( objDecl, replacement ) } ); … … 804 815 ImplicitCtorDtorStmt * implicit = strict_dynamic_cast< ImplicitCtorDtorStmt * >( dtor ); 805 816 Statement * dtorStmt = implicit->callStmt; 817 806 818 // don't need to call intrinsic dtor, because it does nothing, but 807 819 // non-intrinsic dtors must be called … … 810 822 DeclarationWithType * dtorFunc = getDtorFunc( objDecl, dtorStmt, stmtsToAddBefore ); 811 823 objDecl->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorFunc ) } ) ); 812 // objDecl->attributes.push_back( new Attribute( "cleanup", { new NameExpr( dtorFunc->name ) } ) );813 824 ctorInit->dtor = nullptr; 814 825 } // if -
src/InitTweak/InitTweak.cc
r96fc67b r20eacb7 343 343 std::list< Expression * > matches; 344 344 collectCtorDtorCalls( stmt, matches ); 345 assert ( matches.size() <= 1);345 assertf( matches.size() <= 1, "%zd constructor/destructors found in %s", matches.size(), toString( stmt ).c_str() ); 346 346 return matches.size() == 1 ? matches.front() : nullptr; 347 347 }
Note: See TracChangeset
for help on using the changeset viewer.