Changes in src/InitTweak/FixGlobalInit.cc [7baed7d:7b3f66b]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r7baed7d r7b3f66b 22 22 #include "SynTree/Initializer.h" 23 23 #include "SynTree/Visitor.h" 24 #include "SynTree/Attribute.h"25 24 #include <algorithm> 26 25 … … 117 116 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 118 117 std::string fixedName = globalFunctionName( name ); 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 ) ); 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 ) ); 135 121 } 136 122 … … 139 125 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); 140 126 127 // if ( objDecl->get_init() == NULL ) return; 141 128 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 variable 142 130 if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return; 143 131 // C allows you to initialize objects with constant expressions … … 158 146 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 159 147 init->get_args().push_back( new VariableExpr( newObj ) ); 160 initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init )) );148 initStatements.push_back( new ExprStmt( noLabels, init ) ); 161 149 162 150 // add destructor calls to global destroy function 163 151 UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) ); 164 152 destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 165 destroyStatements.push_front( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, destroy )) );153 destroyStatements.push_front( new ExprStmt( noLabels, destroy ) ); 166 154 } 167 155 }
Note:
See TracChangeset
for help on using the changeset viewer.