Changeset f1e012b for src/InitTweak/RemoveInit.cc
- Timestamp:
- Jan 19, 2016, 1:28:25 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:
- ca1c11f
- Parents:
- 71f4e4f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/RemoveInit.cc
r71f4e4f rf1e012b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:19:35201613 // Update Count : 1 5412 // Last Modified On : Tue Jan 19 11:12:49 2016 13 // Update Count : 165 14 14 // 15 15 … … 59 59 static void generateCtorDtor( std::list< Declaration * > &translationUnit ); 60 60 61 CtorDtor() : inFunction( false ) {} 62 61 63 virtual ObjectDecl * mutate( ObjectDecl * ); 62 64 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); … … 71 73 72 74 protected: 75 bool inFunction; 73 76 74 77 // to be added before block ends - use push_front so order is correct … … 93 96 if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) { 94 97 if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) { 95 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 98 // xxx this can be more complicated - consider ListInit 99 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?{}" ) ); 96 100 assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) ); 97 101 assign->get_args().push_back( single->get_value()->clone() ); … … 107 111 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address 108 112 // is being returned 113 // xxx - this should construct rather than assign 109 114 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 110 115 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); … … 186 191 // hands off if designated or if @= 187 192 if ( tryConstruct( objDecl ) ) { 188 Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) ); 189 Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() ); 190 191 // need to remember init expression, in case no ctors exist 192 // if ctor does exist, want to use ctor expression instead of init 193 // push this decision to the resolver 194 objDecl->set_init( new ConstructorInit( ctor, objDecl->get_init() ) ); 195 destructorStmts.push_front( new ExprStmt( noLabels, dtor ) ); 193 if ( inFunction ) { 194 Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) ); 195 Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() ); 196 197 // need to remember init expression, in case no ctors exist 198 // if ctor does exist, want to use ctor expression instead of init 199 // push this decision to the resolver 200 objDecl->set_init( new ConstructorInit( ctor, objDecl->get_init() ) ); 201 destructorStmts.push_front( new ExprStmt( noLabels, dtor ) ); 202 } else { 203 // xxx - find a way to construct/destruct globals 204 // hack: implicit "static" initialization routine for each struct type? or something similar? 205 // --ties into module system 206 } 196 207 } 197 208 return objDecl; … … 200 211 DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) { 201 212 // parameters should not be constructed and destructed, so don't mutate FunctionType 213 bool oldInFunc = inFunction; 202 214 mutateAll( functionDecl->get_oldDecls(), *this ); 215 inFunction = true; 203 216 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 217 inFunction = oldInFunc; 204 218 return functionDecl; 205 219 }
Note: See TracChangeset
for help on using the changeset viewer.