Changes in src/InitTweak/FixGlobalInit.cc [f072892:a16764a6]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
rf072892 ra16764a6 37 37 class GlobalFixer : public WithShortCircuiting { 38 38 public: 39 GlobalFixer( bool inLibrary );39 GlobalFixer( const std::string & name, bool inLibrary ); 40 40 41 41 void previsit( ObjectDecl *objDecl ); … … 52 52 }; 53 53 54 void fixGlobalInit( std::list< Declaration * > & translationUnit, bool inLibrary ) {55 PassVisitor<GlobalFixer> visitor( inLibrary );54 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) { 55 PassVisitor<GlobalFixer> visitor( name, inLibrary ); 56 56 acceptAll( translationUnit, visitor ); 57 57 GlobalFixer & fixer = visitor.pass; … … 70 70 } 71 71 72 GlobalFixer::GlobalFixer( bool inLibrary ) : tempNamer( "_global_init" ) { 72 std::string globalFunctionName( const std::string & name ) { 73 // get basename 74 std::string ret = name.substr( 0, name.find( '.' ) ); 75 // replace invalid characters with _ 76 static std::string invalid = "/-"; 77 replace_if( ret.begin(), ret.end(), []( char c ) { return invalid.find(c) != std::string::npos; }, '_' ); 78 return ret; 79 } 80 81 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 82 std::string fixedName = globalFunctionName( name ); 73 83 std::list< Expression * > ctorParameters; 74 84 std::list< Expression * > dtorParameters; … … 80 90 // for library code are run before constructors and destructors for user code, 81 91 // specify a priority when building the library. Priorities 0-100 are reserved by gcc. 82 // Priorities 101-200 are reserved by cfa, so use priority 200 for CFA library globals, 83 // allowing room for overriding with a higher priority. 84 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) ); 85 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) ); 92 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 93 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 86 94 } 87 initFunction = new FunctionDecl( "_ _global_init__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );95 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 88 96 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 89 destroyFunction = new FunctionDecl( "_ _global_destroy__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );97 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 90 98 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 91 99 } … … 102 110 if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) { 103 111 // a decision should have been made by the resolver, so ctor and init are not both non-NULL 104 assert( ! ctorInit-> ctor || ! ctorInit->init);112 assert( ! ctorInit->get_ctor() || ! ctorInit->get_init() ); 105 113 106 Statement * dtor = ctorInit-> dtor;114 Statement * dtor = ctorInit->get_dtor(); 107 115 if ( dtor && ! isIntrinsicSingleArgCallStmt( dtor ) ) { 108 116 // don't need to call intrinsic dtor, because it does nothing, but 109 117 // non-intrinsic dtors must be called 110 118 destroyStatements.push_front( dtor ); 111 ctorInit-> dtor = nullptr;119 ctorInit->set_dtor( NULL ); 112 120 } // if 113 if ( Statement * ctor = ctorInit-> ctor) {121 if ( Statement * ctor = ctorInit->get_ctor() ) { 114 122 initStatements.push_back( ctor ); 115 objDecl-> init = nullptr;116 ctorInit-> ctor = nullptr;117 } else if ( Initializer * init = ctorInit-> init) {118 objDecl-> init = init;119 ctorInit-> init = nullptr;123 objDecl->set_init( NULL ); 124 ctorInit->set_ctor( NULL ); 125 } else if ( Initializer * init = ctorInit->get_init() ) { 126 objDecl->set_init( init ); 127 ctorInit->set_init( NULL ); 120 128 } else { 121 129 // no constructor and no initializer, which is okay 122 objDecl-> init = nullptr;130 objDecl->set_init( NULL ); 123 131 } // if 124 132 delete ctorInit;
Note:
See TracChangeset
for help on using the changeset viewer.