Changeset 4e24610 for src/InitTweak
- Timestamp:
- May 6, 2016, 1:56:08 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d029162e
- Parents:
- 711eee5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r711eee5 r4e24610 10 10 // Created On : Mon May 04 15:14:56 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 04 16:53:12201612 // Last Modified On : Fri May 06 13:51:00 2016 13 13 // Update Count : 2 14 14 // … … 30 30 class GlobalFixer : public Visitor { 31 31 public: 32 GlobalFixer( const std::string & fileName);32 GlobalFixer(); 33 33 34 34 virtual void visit( ObjectDecl *objDecl ); 35 35 virtual void visit( FunctionDecl *functionDecl ); 36 virtual void visit( StructDecl *aggregateDecl ); 37 virtual void visit( UnionDecl *aggregateDecl ); 38 virtual void visit( EnumDecl *aggregateDecl ); 39 virtual void visit( TraitDecl *aggregateDecl ); 40 virtual void visit( TypeDecl *typeDecl ); 36 41 37 42 UniqueName tempNamer; 38 FunctionDecl * initFunction;43 CompoundStmt * block; 39 44 }; 40 45 … … 83 88 84 89 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name ) { 85 GlobalFixer fixer ( name );90 GlobalFixer fixer; 86 91 acceptAll( translationUnit, fixer ); 87 translationUnit.push_back( fixer.initFunction ); 92 // attribute only appears on the forward declaration, so need to make two function decls: 93 // one with the body, one with the attribute. 94 FunctionDecl * initFunction = new FunctionDecl( initName( name ), DeclarationNode::NoStorageClass, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), 0, false, false ); 95 FunctionDecl * forward = initFunction->clone(); 96 forward->set_attribute( FunctionDecl::Constructor ); 97 initFunction->set_statements( fixer.block ); 98 translationUnit.push_back( forward ); 99 translationUnit.push_back( initFunction ); 88 100 } 89 101 … … 97 109 } 98 110 99 GlobalFixer::GlobalFixer( const std::string & fileName ) : tempNamer( "_global_init" ) { 100 initFunction = new FunctionDecl( initName( fileName ), DeclarationNode::NoStorageClass, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 111 GlobalFixer::GlobalFixer() : tempNamer( "_global_init" ), block( new CompoundStmt( noLabels ) ) { 101 112 } 102 113 103 114 void GlobalFixer::visit( ObjectDecl *objDecl ) { 104 std::list< Statement * > & statements = initFunction->get_statements()->get_kids();115 std::list< Statement * > & statements = block->get_kids(); 105 116 117 if ( objDecl->get_init() == NULL ) return; 118 if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable 106 119 // C allows you to initialize objects with constant expressions 107 if ( isConstExpr( objDecl->get_init() ) ) return; 120 // xxx - this is an optimization. Need to first resolve constructors before we decide 121 // to keep C-style initializer. 122 // if ( isConstExpr( objDecl->get_init() ) ) return; 108 123 109 124 // steal initializer from object and attach it to a new temporary … … 121 136 } 122 137 123 void GlobalFixer::visit( FunctionDecl *functionDecl ) { 124 // only modify global variables 125 } 138 // only modify global variables 139 void GlobalFixer::visit( FunctionDecl *functionDecl ) {} 140 void GlobalFixer::visit( StructDecl *aggregateDecl ) {} 141 void GlobalFixer::visit( UnionDecl *aggregateDecl ) {} 142 void GlobalFixer::visit( EnumDecl *aggregateDecl ) {} 143 void GlobalFixer::visit( TraitDecl *aggregateDecl ) {} 144 void GlobalFixer::visit( TypeDecl *typeDecl ) {} 145 126 146 } // namespace InitTweak 127 147
Note: See TracChangeset
for help on using the changeset viewer.