Changeset b3fc977
- Timestamp:
- Jan 8, 2018, 3:24:24 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:
- f240484
- Parents:
- 94e025a2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r94e025a2 rb3fc977 197 197 }; 198 198 199 struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer {199 struct GenStructMemberCalls final : public WithGuards, public WithShortCircuiting, public WithIndexer, public WithVisitorRef<GenStructMemberCalls> { 200 200 /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors 201 201 /// for any member that is missing a corresponding ctor/dtor call. … … 203 203 static void generate( std::list< Declaration * > & translationUnit ); 204 204 205 void previsit( FunctionDecl * funcDecl ); 206 void postvisit( FunctionDecl * funcDecl ); 207 208 void previsit( MemberExpr * memberExpr ); 209 void previsit( ApplicationExpr * appExpr ); 205 void premutate( FunctionDecl * funcDecl ); 206 DeclarationWithType * postmutate( FunctionDecl * funcDecl ); 207 208 void premutate( MemberExpr * memberExpr ); 209 void premutate( ApplicationExpr * appExpr ); 210 211 /// Note: this post mutate used to be in a separate visitor. If this pass breaks, one place to examine is whether it is 212 /// okay for this part of the recursion to occur alongside the rest. 213 Expression * postmutate( UntypedExpr * expr ); 210 214 211 215 SemanticError errors; … … 220 224 bool isCtor = false; // true if current function is a constructor 221 225 StructDecl * structDecl = nullptr; 222 };223 224 // very simple resolver-like mutator class - used to225 // resolve UntypedExprs that are found within newly226 // generated constructor/destructor calls227 class MutatingResolver final : public Mutator {228 public:229 MutatingResolver( SymTab::Indexer & indexer ) : indexer( indexer ) {}230 231 using Mutator::mutate;232 virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ) override;233 virtual Expression* mutate( UntypedExpr *untypedExpr ) override;234 235 private:236 SymTab::Indexer & indexer;237 226 }; 238 227 … … 315 304 void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) { 316 305 PassVisitor<GenStructMemberCalls> warner; 317 acceptAll( translationUnit, warner );306 mutateAll( translationUnit, warner ); 318 307 } 319 308 … … 950 939 } 951 940 952 void GenStructMemberCalls::pre visit( FunctionDecl * funcDecl ) {941 void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) { 953 942 GuardValue( function ); 954 943 GuardValue( unhandled ); … … 984 973 } 985 974 986 void GenStructMemberCalls::postvisit( FunctionDecl * funcDecl ) {975 DeclarationWithType * GenStructMemberCalls::postmutate( FunctionDecl * funcDecl ) { 987 976 // remove the unhandled objects from usedUninit, because a call is inserted 988 977 // to handle them - only objects that are later constructed are used uninitialized. … … 1038 1027 Statement * callStmt = stmt.front(); 1039 1028 1040 MutatingResolver resolver( indexer );1041 1029 try { 1042 callStmt->acceptMutator( resolver );1030 callStmt->acceptMutator( *visitor ); 1043 1031 if ( isCtor ) { 1044 1032 function->get_statements()->push_front( callStmt ); … … 1056 1044 throw errors; 1057 1045 } 1046 return funcDecl; 1058 1047 } 1059 1048 … … 1081 1070 } 1082 1071 1083 void GenStructMemberCalls::pre visit( ApplicationExpr * appExpr ) {1072 void GenStructMemberCalls::premutate( ApplicationExpr * appExpr ) { 1084 1073 if ( ! checkWarnings( function ) ) { 1085 1074 visit_children = false; … … 1106 1095 } 1107 1096 1108 void GenStructMemberCalls::pre visit( MemberExpr * memberExpr ) {1097 void GenStructMemberCalls::premutate( MemberExpr * memberExpr ) { 1109 1098 if ( ! checkWarnings( function ) || ! isCtor ) { 1110 1099 visit_children = false; … … 1134 1123 } 1135 1124 1136 DeclarationWithType * MutatingResolver::mutate( ObjectDecl * objectDecl ) { 1137 // add object to the indexer assumes that there will be no name collisions 1138 // in generated code. If this changes, add mutate methods for entities with 1139 // scope and call {enter,leave}Scope explicitly. 1140 indexer.addId( objectDecl ); 1141 return objectDecl; 1142 } 1143 1144 Expression * MutatingResolver::mutate( UntypedExpr * untypedExpr ) { 1125 Expression * GenStructMemberCalls::postmutate( UntypedExpr * untypedExpr ) { 1145 1126 Expression * newExpr = untypedExpr; 1146 1127 ResolvExpr::findVoidExpression( newExpr, indexer );
Note: See TracChangeset
for help on using the changeset viewer.