Changeset 22bc276 for src/InitTweak/GenInit.cc
- Timestamp:
- Sep 21, 2017, 3:23:33 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 05807e9, 29bc63e
- Parents:
- e4d6335
- git-author:
- Rob Schluntz <rschlunt@…> (09/21/17 15:19:47)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/21/17 15:23:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
re4d6335 r22bc276 62 62 }; 63 63 64 struct CtorDtor : public WithGuards, public WithShortCircuiting {64 struct CtorDtor : public WithGuards, public WithShortCircuiting, public WithVisitorRef<CtorDtor> { 65 65 /// create constructor and destructor statements for object declarations. 66 66 /// the actual call statements will be added in after the resolver has run … … 75 75 // that need to be constructed or destructed 76 76 void previsit( StructDecl *aggregateDecl ); 77 void previsit( __attribute__((unused)) UnionDecl * aggregateDecl ) { visit_children = false; } 78 void previsit( __attribute__((unused)) EnumDecl * aggregateDecl ) { visit_children = false; } 79 void previsit( __attribute__((unused)) TraitDecl * aggregateDecl ) { visit_children = false; } 80 void previsit( __attribute__((unused)) TypeDecl * typeDecl ) { visit_children = false; } 81 void previsit( __attribute__((unused)) TypedefDecl * typeDecl ) { visit_children = false; } 82 void previsit( __attribute__((unused)) FunctionType * funcType ) { visit_children = false; } 77 void premutate( AggregateDecl * ) { visit_children = false; } 78 void premutate( NamedTypeDecl * ) { visit_children = false; } 79 void previsit( FunctionType * ) { visit_children = false; } 83 80 84 81 void previsit( CompoundStmt * compoundStmt ); … … 96 93 }; 97 94 98 class HoistArrayDimension final : public GenPoly::DeclMutator { 99 public: 100 typedef GenPoly::DeclMutator Parent; 101 95 struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards { 102 96 /// hoist dimension from array types in object declaration so that it uses a single 103 97 /// const variable of type size_t, so that side effecting array dimensions are only … … 105 99 static void hoistArrayDimension( std::list< Declaration * > & translationUnit ); 106 100 107 private: 108 using Parent::mutate; 109 110 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override; 111 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 101 void premutate( ObjectDecl * objectDecl ); 102 DeclarationWithType * postmutate( ObjectDecl * objectDecl ); 103 void premutate( FunctionDecl *functionDecl ); 112 104 // should not traverse into any of these declarations to find objects 113 105 // that need to be constructed or destructed 114 virtual Declaration* mutate( StructDecl *aggregateDecl ) override { return aggregateDecl; } 115 virtual Declaration* mutate( UnionDecl *aggregateDecl ) override { return aggregateDecl; } 116 virtual Declaration* mutate( EnumDecl *aggregateDecl ) override { return aggregateDecl; } 117 virtual Declaration* mutate( TraitDecl *aggregateDecl ) override { return aggregateDecl; } 118 virtual TypeDecl* mutate( TypeDecl *typeDecl ) override { return typeDecl; } 119 virtual Declaration* mutate( TypedefDecl *typeDecl ) override { return typeDecl; } 120 121 virtual Type* mutate( FunctionType *funcType ) override { return funcType; } 106 void premutate( AggregateDecl * ) { visit_children = false; } 107 void premutate( NamedTypeDecl * ) { visit_children = false; } 108 void premutate( FunctionType * ) { visit_children = false; } 122 109 123 110 void hoist( Type * type ); … … 143 130 // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address 144 131 // is being returned 145 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! dynamic_cast< ReferenceType * >( returnVals.front()->get_type() ) ) {132 if ( returnStmt->get_expr() && returnVals.size() == 1 && tryConstruct( returnVals.front() ) ) { 146 133 // explicitly construct the return value using the return expression and the retVal object 147 134 assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() ); … … 158 145 GuardValue( funcName ); 159 146 160 ftype = functionDecl-> get_functionType();161 funcName = functionDecl-> get_name();147 ftype = functionDecl->type; 148 funcName = functionDecl->name; 162 149 } 163 150 … … 165 152 // which would be incorrect if it is a side-effecting computation. 166 153 void HoistArrayDimension::hoistArrayDimension( std::list< Declaration * > & translationUnit ) { 167 HoistArrayDimension hoister; 168 hoister.mutateDeclarationList( translationUnit ); 169 } 170 171 DeclarationWithType * HoistArrayDimension::mutate( ObjectDecl * objectDecl ) { 154 PassVisitor<HoistArrayDimension> hoister; 155 mutateAll( translationUnit, hoister ); 156 } 157 158 void HoistArrayDimension::premutate( ObjectDecl * objectDecl ) { 159 GuardValue( storageClasses ); 172 160 storageClasses = objectDecl->get_storageClasses(); 173 DeclarationWithType * temp = Parent::mutate( objectDecl ); 161 } 162 163 DeclarationWithType * HoistArrayDimension::postmutate( ObjectDecl * objectDecl ) { 174 164 hoist( objectDecl->get_type() ); 175 return temp;165 return objectDecl; 176 166 } 177 167 … … 194 184 195 185 arrayType->set_dimension( new VariableExpr( arrayDimension ) ); 196 addDeclaration( arrayDimension );186 declsToAddBefore.push_back( arrayDimension ); 197 187 198 188 hoist( arrayType->get_base() ); … … 201 191 } 202 192 203 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 204 ValueGuard< bool > oldInFunc( inFunction ); 205 inFunction = true; 206 DeclarationWithType * decl = Parent::mutate( functionDecl ); 207 return decl; 193 void HoistArrayDimension::premutate( FunctionDecl * ) { 194 GuardValue( inFunction ); 208 195 } 209 196 … … 214 201 215 202 bool CtorDtor::isManaged( Type * type ) const { 216 // at least for now,references are never constructed203 // references are never constructed 217 204 if ( dynamic_cast< ReferenceType * >( type ) ) return false; 218 205 // need to clear and reset qualifiers when determining if a type is managed … … 221 208 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( type ) ) { 222 209 // tuple is also managed if any of its components are managed 223 if ( std::any_of( tupleType-> get_types().begin(), tupleType->get_types().end(), [&](Type * type) { return isManaged( type ); }) ) {210 if ( std::any_of( tupleType->types.begin(), tupleType->types.end(), [&](Type * type) { return isManaged( type ); }) ) { 224 211 return true; 225 212 } … … 305 292 306 293 void CtorDtor::previsit( FunctionDecl *functionDecl ) { 294 visit_children = false; // do not try and construct parameters or forall parameters 307 295 GuardValue( inFunction ); 308 296 inFunction = true; … … 318 306 } 319 307 320 PassVisitor<CtorDtor> newCtorDtor; 321 newCtorDtor.pass = *this; 322 maybeAccept( functionDecl->get_statements(), newCtorDtor ); 323 visit_children = false; // do not try and construct parameters or forall parameters - must happen after maybeAccept 308 maybeAccept( functionDecl->get_statements(), *visitor ); 324 309 } 325 310 … … 340 325 } 341 326 342 void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt) {327 void CtorDtor::previsit( CompoundStmt * ) { 343 328 GuardScope( managedTypes ); 344 329 }
Note: See TracChangeset
for help on using the changeset viewer.