Changeset 40e636a for src/InitTweak
- Timestamp:
- Jul 21, 2016, 11:19:24 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, 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:
- b81adcc4
- Parents:
- 5f98ce5
- Location:
- src/InitTweak
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r5f98ce5 r40e636a 46 46 FunctionDecl * destroyFunction; 47 47 }; 48 49 class ConstExprChecker : public Visitor {50 public:51 ConstExprChecker() : isConstExpr( true ) {}52 53 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }54 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; }55 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; }56 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }57 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }58 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }59 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }60 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }61 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }62 // these might be okay?63 // virtual void visit( SizeofExpr *sizeofExpr );64 // virtual void visit( AlignofExpr *alignofExpr );65 // virtual void visit( UntypedOffsetofExpr *offsetofExpr );66 // virtual void visit( OffsetofExpr *offsetofExpr );67 // virtual void visit( OffsetPackExpr *offsetPackExpr );68 // virtual void visit( AttrExpr *attrExpr );69 // virtual void visit( CommaExpr *commaExpr );70 // virtual void visit( LogicalExpr *logicalExpr );71 // virtual void visit( ConditionalExpr *conditionalExpr );72 virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }73 virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; }74 virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; }75 virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; }76 virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; }77 virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; }78 79 bool isConstExpr;80 };81 82 bool isConstExpr( Expression * expr ) {83 if ( expr ) {84 ConstExprChecker checker;85 expr->accept( checker );86 return checker.isConstExpr;87 }88 return true;89 }90 91 bool isConstExpr( Initializer * init ) {92 if ( init ) {93 ConstExprChecker checker;94 init->accept( checker );95 return checker.isConstExpr;96 } // if97 // for all intents and purposes, no initializer means const expr98 return true;99 }100 48 101 49 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) { … … 159 107 // xxx - initialize each element of the array 160 108 } else { 161 // steal initializer from object and attach it to a new temporary 162 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() ); 163 objDecl->set_init( NULL ); 164 initStatements.push_back( new DeclStmt( noLabels, newObj ) ); 165 166 // copy construct objDecl using temporary 109 // insert constructor for objDecl into global init function 167 110 UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) ); 168 111 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 169 init->get_args().push_back( new VariableExpr( newObj ) ); 112 init->get_args().splice( init->get_args().end(), makeInitList( objDecl->get_init() ) ); 113 objDecl->set_init( NULL ); 170 114 initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init ) ) ); 171 115 -
src/InitTweak/GenInit.cc
r5f98ce5 r40e636a 90 90 91 91 private: 92 DeclarationWithType * mutate( ObjectDecl * objectDecl ); 92 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ); 93 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 93 94 // should not traverse into any of these declarations to find objects 94 95 // that need to be constructed or destructed … … 105 106 106 107 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass; 108 bool inFunction = false; 107 109 }; 108 110 … … 157 159 void HoistArrayDimension::hoistArrayDimension( std::list< Declaration * > & translationUnit ) { 158 160 HoistArrayDimension hoister; 159 mutateAll( translationUnit, hoister);161 hoister.mutateDeclarationList( translationUnit ); 160 162 } 161 163 … … 169 171 170 172 void HoistArrayDimension::hoist( Type * type ) { 173 // if in function, generate const size_t var 171 174 static UniqueName dimensionName( "_array_dim" ); 172 175 if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) { 176 if ( ! inFunction ) return; 177 173 178 if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist? 174 179 … … 186 191 return; 187 192 } 193 } 194 195 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 196 bool oldInFunc = inFunction; 197 inFunction = true; 198 DeclarationWithType * decl = Parent::mutate( functionDecl ); 199 inFunction = oldInFunc; 200 return decl; 188 201 } 189 202 -
src/InitTweak/InitTweak.cc
r5f98ce5 r40e636a 160 160 else return NULL; 161 161 } 162 163 class ConstExprChecker : public Visitor { 164 public: 165 ConstExprChecker() : isConstExpr( true ) {} 166 167 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 168 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; } 169 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 170 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 171 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 172 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 173 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 174 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 175 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ } 176 // these might be okay? 177 // virtual void visit( SizeofExpr *sizeofExpr ); 178 // virtual void visit( AlignofExpr *alignofExpr ); 179 // virtual void visit( UntypedOffsetofExpr *offsetofExpr ); 180 // virtual void visit( OffsetofExpr *offsetofExpr ); 181 // virtual void visit( OffsetPackExpr *offsetPackExpr ); 182 // virtual void visit( AttrExpr *attrExpr ); 183 // virtual void visit( CommaExpr *commaExpr ); 184 // virtual void visit( LogicalExpr *logicalExpr ); 185 // virtual void visit( ConditionalExpr *conditionalExpr ); 186 virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; } 187 virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; } 188 virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; } 189 virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; } 190 virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; } 191 virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; } 192 193 bool isConstExpr; 194 }; 195 196 bool isConstExpr( Expression * expr ) { 197 if ( expr ) { 198 ConstExprChecker checker; 199 expr->accept( checker ); 200 return checker.isConstExpr; 201 } 202 return true; 203 } 204 205 bool isConstExpr( Initializer * init ) { 206 if ( init ) { 207 ConstExprChecker checker; 208 init->accept( checker ); 209 return checker.isConstExpr; 210 } // if 211 // for all intents and purposes, no initializer means const expr 212 return true; 213 } 214 162 215 }
Note: See TracChangeset
for help on using the changeset viewer.