Changeset 88e79ad for src/InitTweak/FixInit.cc
- Timestamp:
- Oct 20, 2017, 2:00:55 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:
- 0b9be4d
- Parents:
- 72f85de
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r72f85de r88e79ad 177 177 DeclarationWithType * postmutate( ObjectDecl *objDecl ); 178 178 179 DeclarationWithType * getDtorFunc( ObjectDecl * objDecl, Statement * dtor );180 181 179 std::list< Declaration * > staticDtorDecls; 182 180 }; … … 202 200 static void generate( std::list< Declaration * > & translationUnit ); 203 201 202 void previsit( StructDecl * structDecl ); 203 204 204 void previsit( FunctionDecl * funcDecl ); 205 205 void postvisit( FunctionDecl * funcDecl ); … … 219 219 bool isCtor = false; // true if current function is a constructor 220 220 StructDecl * structDecl = nullptr; 221 222 // special built-in functions necessary for this to work 223 StructDecl * dtorStruct = nullptr; 224 FunctionDecl * dtorStructDestroy = nullptr; 221 225 }; 222 226 … … 635 639 } 636 640 637 DeclarationWithType * FixInit::getDtorFunc( ObjectDecl * objDecl, Statement * dtor) {641 DeclarationWithType * getDtorFunc( ObjectDecl * objDecl, Statement * dtor, std::list< Statement * > & stmtsToAdd ) { 638 642 if ( dynamic_cast< ExprStmt * >( dtor ) ) { 639 643 if ( DeclarationWithType * func = getFunction( getCtorDtorCall( dtor ) ) ) { … … 653 657 // wraps the more complicated code. 654 658 static UniqueName dtorNamer( "__cleanup_dtor" ); 655 FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type , false ), new CompoundStmt( noLabels ) );656 stmtsToAdd Before.push_back( new DeclStmt( noLabels, dtorFunc ) );659 FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type->stripReferences(), false ), new CompoundStmt( noLabels ) ); 660 stmtsToAdd.push_back( new DeclStmt( noLabels, dtorFunc ) ); 657 661 658 662 // the original code contains uses of objDecl - replace them with the newly generated 'this' parameter. … … 785 789 if ( ! isIntrinsicSingleArgCallStmt( dtorStmt ) ) { 786 790 // set dtor location to the object's location for error messages 787 DeclarationWithType * dtorFunc = getDtorFunc( objDecl, dtorStmt );791 DeclarationWithType * dtorFunc = getDtorFunc( objDecl, dtorStmt, stmtsToAddBefore ); 788 792 objDecl->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorFunc ) } ) ); 789 793 // objDecl->attributes.push_back( new Attribute( "cleanup", { new NameExpr( dtorFunc->name ) } ) ); … … 910 914 } 911 915 916 void GenStructMemberCalls::previsit( StructDecl * structDecl ) { 917 if ( ! dtorStruct && structDecl->name == "__Destructor" ) { 918 dtorStruct = structDecl; 919 } 920 } 921 912 922 void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) { 913 923 GuardValue( function ); … … 922 932 unhandled.clear(); 923 933 usedUninit.clear(); 934 935 if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) { 936 dtorStructDestroy = funcDecl; 937 return; 938 } 924 939 925 940 function = funcDecl; … … 933 948 if ( structType ) { 934 949 structDecl = structType->get_baseStruct(); 950 if ( structDecl == dtorStruct ) return; 935 951 for ( Declaration * member : structDecl->get_members() ) { 936 952 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 1004 1020 callStmt->acceptMutator( resolver ); 1005 1021 if ( isCtor ) { 1006 function-> get_statements()->push_front( callStmt );1022 function->statements->push_front( callStmt ); 1007 1023 } else { 1008 1024 // destructor statements should be added at the end 1009 function->get_statements()->push_back( callStmt ); 1025 // function->get_statements()->push_back( callStmt ); 1026 1027 // Destructor _dtor0 = { &b.a1, _destroy_A }; 1028 std::list< Statement * > stmtsToAdd; 1029 1030 static UniqueName memberDtorNamer = { "__memberDtor" }; 1031 assertf( dtorStruct, "builtin __Destructor not found." ); 1032 assertf( dtorStructDestroy, "builtin __destroy_Destructor not found." ); 1033 1034 Expression * thisExpr = new AddressExpr( new VariableExpr( thisParam ) ); 1035 Expression * dtorExpr = new VariableExpr( getDtorFunc( thisParam, callStmt, stmtsToAdd ) ); 1036 1037 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( dtorExpr ) } ) ); 1038 function->statements->push_front( new DeclStmt( noLabels, destructor ) ); 1039 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorStructDestroy ) } ) ); 1040 1041 function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd ); 1010 1042 } 1011 1043 } catch ( SemanticError & error ) {
Note: See TracChangeset
for help on using the changeset viewer.