Changes in src/InitTweak/FixGlobalInit.cc [7b3f66b:ec79847]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r7b3f66b rec79847 10 10 // Created On : Mon May 04 15:14:56 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri May 13 11:37:30201612 // Last Modified On : Mon May 09 11:44:29 2016 13 13 // Update Count : 2 14 14 // 15 15 16 16 #include "FixGlobalInit.h" 17 #include " InitTweak.h"17 #include "GenInit.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;131 130 // C allows you to initialize objects with constant expressions 132 131 // xxx - this is an optimization. Need to first resolve constructors before we decide … … 134 133 // if ( isConstExpr( objDecl->get_init() ) ) return; 135 134 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 ) ); 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 ) ); 143 139 144 // copy construct objDecl using temporary145 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 ) );140 // copy construct objDecl using temporary 141 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 ) ); 149 145 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 } 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 ) ); 155 150 } 156 151
Note:
See TracChangeset
for help on using the changeset viewer.