Changeset 2bfc6b2 for src/InitTweak/FixInit.cc
- Timestamp:
- Aug 30, 2018, 1:00:41 PM (5 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:
- bcc0946
- Parents:
- a715b5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
ra715b5c r2bfc6b2 56 56 #include "SynTree/DeclReplacer.h" // for DeclReplacer 57 57 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 58 #include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy 58 59 59 60 bool ctordtorp = false; // print all debug … … 204 205 static void generate( std::list< Declaration * > & translationUnit ); 205 206 206 void premutate( StructDecl * structDecl );207 208 207 void premutate( FunctionDecl * funcDecl ); 209 208 DeclarationWithType * postmutate( FunctionDecl * funcDecl ); … … 227 226 bool isCtor = false; // true if current function is a constructor 228 227 StructDecl * structDecl = nullptr; 229 230 // special built-in functions necessary for this to work231 StructDecl * dtorStruct = nullptr;232 FunctionDecl * dtorStructDestroy = nullptr;233 228 }; 234 229 … … 1019 1014 } 1020 1015 1021 void GenStructMemberCalls::premutate( StructDecl * structDecl ) {1022 if ( ! dtorStruct && structDecl->name == "__Destructor" ) {1023 dtorStruct = structDecl;1024 }1025 }1026 1027 1016 void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) { 1028 1017 GuardValue( function ); … … 1037 1026 unhandled.clear(); 1038 1027 usedUninit.clear(); 1039 1040 if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {1041 dtorStructDestroy = funcDecl;1042 return;1043 }1044 1028 1045 1029 function = funcDecl; … … 1053 1037 if ( structType ) { 1054 1038 structDecl = structType->get_baseStruct(); 1055 if ( structDecl == dtorStruct ) return;1056 1039 for ( Declaration * member : structDecl->get_members() ) { 1057 1040 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 1127 1110 // function->get_statements()->push_back( callStmt ); 1128 1111 1112 // Optimization: do not need to call intrinsic destructors on members 1113 if ( isIntrinsicSingleArgCallStmt( callStmt ) ) continue;; 1114 1129 1115 // __Destructor _dtor0 = { (void *)&b.a1, (void (*)(void *)_destroy_A }; 1130 1116 std::list< Statement * > stmtsToAdd; 1131 1117 1132 1118 static UniqueName memberDtorNamer = { "__memberDtor" }; 1133 assertf( dtorStruct, "builtin __Destructor not found." );1134 assertf( dtorStructDestroy, "builtin __destroy_Destructor not found." );1119 assertf( Validate::dtorStruct, "builtin __Destructor not found." ); 1120 assertf( Validate::dtorStructDestroy, "builtin __destroy_Destructor not found." ); 1135 1121 1136 1122 Expression * thisExpr = new CastExpr( new AddressExpr( new VariableExpr( thisParam ) ), new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ) ); … … 1142 1128 Type * dtorType = new PointerType( Type::Qualifiers(), dtorFtype ); 1143 1129 1144 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) );1130 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), Validate::dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) ); 1145 1131 function->statements->push_front( new DeclStmt( destructor ) ); 1146 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorStructDestroy ) } ) );1132 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( Validate::dtorStructDestroy ) } ) ); 1147 1133 1148 1134 function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd );
Note: See TracChangeset
for help on using the changeset viewer.