Changes in src/InitTweak/FixGlobalInit.cc [ec79847:7b3f66b]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
rec79847 r7b3f66b 10 10 // Created On : Mon May 04 15:14:56 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon May 09 11:44:29201612 // Last Modified On : Fri May 13 11:37:30 2016 13 13 // Update Count : 2 14 14 // 15 15 16 16 #include "FixGlobalInit.h" 17 #include " GenInit.h"17 #include "InitTweak.h" 18 18 #include "SynTree/Declaration.h" 19 19 #include "SynTree/Type.h" … … 125 125 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); 126 126 127 if ( objDecl->get_init() == NULL ) return;127 // if ( objDecl->get_init() == NULL ) return; 128 128 if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects 129 129 if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable 130 if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return; 130 131 // C allows you to initialize objects with constant expressions 131 132 // xxx - this is an optimization. Need to first resolve constructors before we decide … … 133 134 // if ( isConstExpr( objDecl->get_init() ) ) return; 134 135 135 // steal initializer from object and attach it to a new temporary 136 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() ); 137 objDecl->set_init( NULL ); 138 initStatements.push_back( new DeclStmt( noLabels, newObj ) ); 136 if ( ArrayType * at = dynamic_cast< ArrayType * > ( objDecl->get_type() ) ) { 137 // xxx - initialize each element of the array 138 } else { 139 // steal initializer from object and attach it to a new temporary 140 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() ); 141 objDecl->set_init( NULL ); 142 initStatements.push_back( new DeclStmt( noLabels, newObj ) ); 139 143 140 // copy construct objDecl using temporary141 UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) );142 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );143 init->get_args().push_back( new VariableExpr( newObj ) );144 initStatements.push_back( new ExprStmt( noLabels, init ) );144 // copy construct objDecl using temporary 145 UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) ); 146 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 147 init->get_args().push_back( new VariableExpr( newObj ) ); 148 initStatements.push_back( new ExprStmt( noLabels, init ) ); 145 149 146 // add destructor calls to global destroy function 147 UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) ); 148 destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 149 destroyStatements.push_front( new ExprStmt( noLabels, destroy ) ); 150 // add destructor calls to global destroy function 151 UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) ); 152 destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 153 destroyStatements.push_front( new ExprStmt( noLabels, destroy ) ); 154 } 150 155 } 151 156
Note:
See TracChangeset
for help on using the changeset viewer.