Changeset 9a707e4e for src/InitTweak
- Timestamp:
- Sep 15, 2017, 5:05:48 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:
- eada3cf
- Parents:
- a4ca48c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
ra4ca48c r9a707e4e 238 238 }; 239 239 240 class GenStructMemberCalls final : public SymTab::Indexer { 241 public: 242 typedef Indexer Parent; 240 struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer { 243 241 /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors 244 242 /// for any member that is missing a corresponding ctor/dtor call. … … 246 244 static void generate( std::list< Declaration * > & translationUnit ); 247 245 248 using Parent::visit; 249 250 virtual void visit( FunctionDecl * funcDecl ) override; 251 252 virtual void visit( MemberExpr * memberExpr ) override; 253 virtual void visit( ApplicationExpr * appExpr ) override; 246 void previsit( FunctionDecl * funcDecl ); 247 void postvisit( FunctionDecl * funcDecl ); 248 249 void previsit( MemberExpr * memberExpr ); 250 void previsit( ApplicationExpr * appExpr ); 254 251 255 252 SemanticError errors; … … 360 357 361 358 void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) { 362 GenStructMemberCallswarner;359 PassVisitor<GenStructMemberCalls> warner; 363 360 acceptAll( translationUnit, warner ); 364 361 } … … 978 975 } 979 976 980 void GenStructMemberCalls:: visit( FunctionDecl * funcDecl ) {981 ValueGuard< FunctionDecl * > oldFunction( funcDecl );982 ValueGuard< std::set< DeclarationWithType * > > oldUnhandled( unhandled );983 ValueGuard< std::map< DeclarationWithType *, CodeLocation > > oldUsedUninit( usedUninit );984 ValueGuard< ObjectDecl * > oldThisParam( thisParam );985 ValueGuard< bool > oldIsCtor( isCtor );986 ValueGuard< StructDecl * > oldStructDecl( structDecl );977 void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) { 978 GuardValue( funcDecl ); 979 GuardValue( unhandled ); 980 GuardValue( usedUninit ); 981 GuardValue( thisParam ); 982 GuardValue( isCtor ); 983 GuardValue( structDecl ); 987 984 errors = SemanticError(); // clear previous errors 988 985 … … 1010 1007 } 1011 1008 } 1012 Parent::visit( function ); 1013 1009 } 1010 1011 void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) { 1012 for ( auto d : decls ) { 1013 indexer.addId( d ); 1014 } 1015 } 1016 1017 void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) { 1018 for ( auto td : tds ) { 1019 indexer.addType( td ); 1020 addIds( indexer, td->assertions ); 1021 } 1022 } 1023 1024 void GenStructMemberCalls::postvisit( FunctionDecl * funcDecl ) { 1014 1025 // remove the unhandled objects from usedUninit, because a call is inserted 1015 1026 // to handle them - only objects that are later constructed are used uninitialized. … … 1032 1043 if ( ! unhandled.empty() ) { 1033 1044 // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors 1034 enterScope(); 1035 maybeAccept( function->get_functionType(), *this ); 1045 auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } ); 1046 addTypes( indexer, function->type->forall ); 1047 addIds( indexer, function->type->returnVals ); 1048 addIds( indexer, function->type->parameters ); 1036 1049 1037 1050 // need to iterate through members in reverse in order for … … 1063 1076 Statement * callStmt = stmt.front(); 1064 1077 1065 MutatingResolver resolver( *this);1078 MutatingResolver resolver( indexer ); 1066 1079 try { 1067 1080 callStmt->acceptMutator( resolver ); … … 1077 1090 } 1078 1091 } 1079 leaveScope();1080 1092 } 1081 1093 if (! errors.isEmpty()) { … … 1107 1119 } 1108 1120 1109 void GenStructMemberCalls::visit( ApplicationExpr * appExpr ) { 1110 if ( ! checkWarnings( function ) ) return; 1121 void GenStructMemberCalls::previsit( ApplicationExpr * appExpr ) { 1122 if ( ! checkWarnings( function ) ) { 1123 visit_children = false; 1124 return; 1125 } 1111 1126 1112 1127 std::string fname = getFunctionName( appExpr ); … … 1127 1142 } 1128 1143 } 1129 Parent::visit( appExpr ); 1130 } 1131 1132 void GenStructMemberCalls::visit( MemberExpr * memberExpr ) { 1133 if ( ! checkWarnings( function ) ) return; 1134 if ( ! isCtor ) return; 1144 } 1145 1146 void GenStructMemberCalls::previsit( MemberExpr * memberExpr ) { 1147 if ( ! checkWarnings( function ) || ! isCtor ) { 1148 visit_children = false; 1149 return; 1150 } 1135 1151 1136 1152 if ( isThisExpression( memberExpr->get_aggregate(), thisParam ) ) { … … 1140 1156 } 1141 1157 } 1142 Parent::visit( memberExpr );1143 1158 } 1144 1159
Note: See TracChangeset
for help on using the changeset viewer.