Changeset a2d4d1c for src/InitTweak/GenInit.cc
- Timestamp:
- Sep 26, 2017, 10:15:38 AM (8 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:
- 19c43b7
- Parents:
- 4dfa562 (diff), a139c11 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r4dfa562 ra2d4d1c 26 26 #include "Common/UniqueName.h" // for UniqueName 27 27 #include "Common/utility.h" // for ValueGuard, maybeClone 28 #include "GenPoly/DeclMutator.h" // for DeclMutator29 28 #include "GenPoly/GenPoly.h" // for getFunctionType, isPolyType 30 29 #include "GenPoly/ScopedSet.h" // for ScopedSet, ScopedSet<>::const_iter... … … 62 61 }; 63 62 64 struct CtorDtor : public WithGuards, public WithShortCircuiting {63 struct CtorDtor : public WithGuards, public WithShortCircuiting, public WithVisitorRef<CtorDtor> { 65 64 /// create constructor and destructor statements for object declarations. 66 65 /// the actual call statements will be added in after the resolver has run … … 75 74 // that need to be constructed or destructed 76 75 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; } 76 void previsit( AggregateDecl * ) { visit_children = false; } 77 void previsit( NamedTypeDecl * ) { visit_children = false; } 78 void previsit( FunctionType * ) { visit_children = false; } 83 79 84 80 void previsit( CompoundStmt * compoundStmt ); … … 96 92 }; 97 93 98 class HoistArrayDimension final : public GenPoly::DeclMutator { 99 public: 100 typedef GenPoly::DeclMutator Parent; 101 94 struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards { 102 95 /// hoist dimension from array types in object declaration so that it uses a single 103 96 /// const variable of type size_t, so that side effecting array dimensions are only … … 105 98 static void hoistArrayDimension( std::list< Declaration * > & translationUnit ); 106 99 107 private: 108 using Parent::mutate; 109 110 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override; 111 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 100 void premutate( ObjectDecl * objectDecl ); 101 DeclarationWithType * postmutate( ObjectDecl * objectDecl ); 102 void premutate( FunctionDecl *functionDecl ); 112 103 // should not traverse into any of these declarations to find objects 113 104 // 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; } 105 void premutate( AggregateDecl * ) { visit_children = false; } 106 void premutate( NamedTypeDecl * ) { visit_children = false; } 107 void premutate( FunctionType * ) { visit_children = false; } 122 108 123 109 void hoist( Type * type ); … … 128 114 129 115 void genInit( std::list< Declaration * > & translationUnit ) { 130 ReturnFixer::makeReturnTemp( translationUnit );116 fixReturnStatements( translationUnit ); 131 117 HoistArrayDimension::hoistArrayDimension( translationUnit ); 132 118 CtorDtor::generateCtorDtor( translationUnit ); 133 119 } 134 120 135 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) {121 void fixReturnStatements( std::list< Declaration * > & translationUnit ) { 136 122 PassVisitor<ReturnFixer> fixer; 137 123 mutateAll( translationUnit, fixer ); … … 143 129 // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address 144 130 // is being returned 145 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! dynamic_cast< ReferenceType * >( returnVals.front()->get_type() ) ) {131 if ( returnStmt->get_expr() && returnVals.size() == 1 && isConstructable( returnVals.front()->get_type() ) ) { 146 132 // explicitly construct the return value using the return expression and the retVal object 147 133 assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() ); … … 158 144 GuardValue( funcName ); 159 145 160 ftype = functionDecl-> get_functionType();161 funcName = functionDecl-> get_name();146 ftype = functionDecl->type; 147 funcName = functionDecl->name; 162 148 } 163 149 … … 165 151 // which would be incorrect if it is a side-effecting computation. 166 152 void HoistArrayDimension::hoistArrayDimension( std::list< Declaration * > & translationUnit ) { 167 HoistArrayDimension hoister; 168 hoister.mutateDeclarationList( translationUnit ); 169 } 170 171 DeclarationWithType * HoistArrayDimension::mutate( ObjectDecl * objectDecl ) { 153 PassVisitor<HoistArrayDimension> hoister; 154 mutateAll( translationUnit, hoister ); 155 } 156 157 void HoistArrayDimension::premutate( ObjectDecl * objectDecl ) { 158 GuardValue( storageClasses ); 172 159 storageClasses = objectDecl->get_storageClasses(); 173 DeclarationWithType * temp = Parent::mutate( objectDecl ); 160 } 161 162 DeclarationWithType * HoistArrayDimension::postmutate( ObjectDecl * objectDecl ) { 174 163 hoist( objectDecl->get_type() ); 175 return temp;164 return objectDecl; 176 165 } 177 166 … … 194 183 195 184 arrayType->set_dimension( new VariableExpr( arrayDimension ) ); 196 addDeclaration( arrayDimension );185 declsToAddBefore.push_back( arrayDimension ); 197 186 198 187 hoist( arrayType->get_base() ); … … 201 190 } 202 191 203 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 204 ValueGuard< bool > oldInFunc( inFunction ); 205 inFunction = true; 206 DeclarationWithType * decl = Parent::mutate( functionDecl ); 207 return decl; 192 void HoistArrayDimension::premutate( FunctionDecl * ) { 193 GuardValue( inFunction ); 208 194 } 209 195 … … 214 200 215 201 bool CtorDtor::isManaged( Type * type ) const { 216 // at least for now,references are never constructed202 // references are never constructed 217 203 if ( dynamic_cast< ReferenceType * >( type ) ) return false; 218 204 // need to clear and reset qualifiers when determining if a type is managed … … 221 207 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( type ) ) { 222 208 // 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 ); }) ) {209 if ( std::any_of( tupleType->types.begin(), tupleType->types.end(), [&](Type * type) { return isManaged( type ); }) ) { 224 210 return true; 225 211 } … … 305 291 306 292 void CtorDtor::previsit( FunctionDecl *functionDecl ) { 293 visit_children = false; // do not try and construct parameters or forall parameters 307 294 GuardValue( inFunction ); 308 295 inFunction = true; … … 318 305 } 319 306 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 307 maybeAccept( functionDecl->get_statements(), *visitor ); 324 308 } 325 309 … … 340 324 } 341 325 342 void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt) {326 void CtorDtor::previsit( CompoundStmt * ) { 343 327 GuardScope( managedTypes ); 344 328 }
Note:
See TracChangeset
for help on using the changeset viewer.