Changes in src/InitTweak/FixGlobalInit.cc [7b3f66b:7baed7d]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r7b3f66b r7baed7d 22 22 #include "SynTree/Initializer.h" 23 23 #include "SynTree/Visitor.h" 24 #include "SynTree/Attribute.h" 24 25 #include <algorithm> 25 26 … … 116 117 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 117 118 std::string fixedName = globalFunctionName( name ); 118 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Constructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 119 120 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Destructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 119 std::list< Expression * > ctorParameters; 120 std::list< Expression * > dtorParameters; 121 if ( inLibrary ) { 122 // Constructor/destructor attributes take a single parameter which 123 // is the priority, with lower numbers meaning higher priority. 124 // Functions specified with priority are guaranteed to run before 125 // functions without a priority. To ensure that constructors and destructors 126 // for library code are run before constructors and destructors for user code, 127 // specify a priority when building the library. Priorities 0-100 are reserved by gcc. 128 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 129 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 130 } 131 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 132 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 133 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 134 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 121 135 } 122 136 … … 125 139 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); 126 140 127 // if ( objDecl->get_init() == NULL ) return;128 141 if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects 129 if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable130 142 if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return; 131 143 // C allows you to initialize objects with constant expressions … … 146 158 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 147 159 init->get_args().push_back( new VariableExpr( newObj ) ); 148 initStatements.push_back( new ExprStmt( noLabels, init) );160 initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init ) ) ); 149 161 150 162 // add destructor calls to global destroy function 151 163 UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) ); 152 164 destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 153 destroyStatements.push_front( new ExprStmt( noLabels, destroy) );165 destroyStatements.push_front( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, destroy ) ) ); 154 166 } 155 167 }
Note:
See TracChangeset
for help on using the changeset viewer.