Changeset 36d0a80
- Timestamp:
- Oct 30, 2020, 3:49:48 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0e707bd
- Parents:
- f7e4f8e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInitNew.cpp
rf7e4f8e8 r36d0a80 67 67 68 68 struct StmtExprResult { 69 static void link( std::list<ast::ptr<ast::Decl> > & translationUnit );70 71 69 const ast::StmtExpr * previsit( const ast::StmtExpr * stmtExpr ); 72 70 }; 73 71 72 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which 73 /// function calls need their parameters to be copy constructed 74 74 struct InsertImplicitCalls : public ast::WithConstTypeSubstitution, public ast::WithShortCircuiting { 75 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which76 /// function calls need their parameters to be copy constructed77 static void insert( std::list<ast::ptr<ast::Decl> > & translationUnit );78 79 75 const ast::Expr * postvisit( const ast::ApplicationExpr * appExpr ); 80 76 … … 86 82 }; 87 83 84 /// generate temporary ObjectDecls for each argument and return value of each ImplicitCopyCtorExpr, 85 /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both 86 /// arguments and return value temporaries 88 87 struct ResolveCopyCtors final : public ast::WithGuards, public ast::WithStmtsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting, public ast::WithVisitorRef<ResolveCopyCtors> { 89 /// generate temporary ObjectDecls for each argument and return value of each ImplicitCopyCtorExpr,90 /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both91 /// arguments and return value temporaries92 static void resolveImplicitCalls( std::list<ast::ptr<ast::Decl> > & translationUnit );93 94 88 const ast::Expr * postvisit( const ast::ImplicitCopyCtorExpr * impCpCtorExpr ); 95 89 const ast::StmtExpr * previsit( const ast::StmtExpr * stmtExpr ); … … 161 155 }; 162 156 157 /// insert destructor calls at the appropriate places. must happen before CtorInit nodes are removed 158 /// (currently by FixInit) 163 159 struct InsertDtors final : public ObjDeclCollector, public ast::WithStmtsToAdd<> { 164 /// insert destructor calls at the appropriate places. must happen before CtorInit nodes are removed165 /// (currently by FixInit)166 static void insert( std::list< ast::ptr<ast::Decl> > & translationUnit );167 168 160 typedef std::list< ObjectDecl * > OrderedDecls; 169 161 typedef std::list< OrderedDecls > OrderedDeclsStack; … … 185 177 }; 186 178 187 class FixInit : public ast::WithStmtsToAdd<> { 188 public: 189 /// expand each object declaration to use its constructor after it is declared. 179 /// expand each object declaration to use its constructor after it is declared. 180 struct FixInit : public ast::WithStmtsToAdd<> { 190 181 static void fixInitializers( std::list< ast::ptr<ast::Decl> > &translationUnit ); 191 182 … … 195 186 }; 196 187 188 /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors 189 /// for any member that is missing a corresponding ctor/dtor call. 190 /// error if a member is used before constructed 197 191 struct GenStructMemberCalls final : public ast::WithGuards, public ast::WithShortCircuiting, public ast::WithSymbolTable, public ast::WithVisitorRef<GenStructMemberCalls> { 198 /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors199 /// for any member that is missing a corresponding ctor/dtor call.200 /// error if a member is used before constructed201 static void generate( std::list< ast::ptr<ast::Decl> > & translationUnit );202 203 192 void previsit( const ast::FunctionDecl * funcDecl ); 204 193 const ast::DeclWithType * postvisit( const ast::FunctionDecl * funcDecl ); … … 224 213 }; 225 214 215 /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument 226 216 struct FixCtorExprs final : public ast::WithDeclsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting { 227 /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument228 static void fix( std::list< ast::ptr<ast::Decl> > & translationUnit );229 230 217 const ast::Expr * postvisit( const ast::ConstructorExpr * ctorExpr ); 231 218 }; 232 219 220 /// add CompoundStmts around top-level expressions so that temporaries are destroyed in the correct places. 233 221 struct SplitExpressions : public ast::WithShortCircuiting { 234 /// add CompoundStmts around top-level expressions so that temporaries are destroyed in the correct places.235 static void split( std::list<ast::ptr<ast::Decl> > & translationUnit );236 237 222 ast::Stmt * postvisit( const ast::ExprStmt * stmt ); 238 223 void previsit( const ast::TupleAssignExpr * expr ); … … 241 226 242 227 void fix( std::list< ast::ptr<ast::Decl> > & translationUnit, bool inLibrary ) { 243 ast::Pass<SelfAssignChecker> checker; 244 accept_all( translationUnit, checker ); 228 ast::Pass<SelfAssignChecker>::run( translationUnit ); 245 229 246 230 // fixes StmtExpr to properly link to their resulting expression 247 StmtExprResult::link( translationUnit );231 ast::Pass<StmtExprResult>::run( translationUnit ); 248 232 249 233 // fixes ConstructorInit for global variables. should happen before fixInitializers. … … 251 235 252 236 // must happen before ResolveCopyCtors because temporaries have to be inserted into the correct scope 253 SplitExpressions::split( translationUnit );254 255 InsertImplicitCalls::insert( translationUnit );237 ast::Pass<SplitExpressions>::run( translationUnit ); 238 239 ast::Pass<InsertImplicitCalls>::run( translationUnit ); 256 240 257 241 // Needs to happen before ResolveCopyCtors, because argument/return temporaries should not be considered in 258 242 // error checking branch statements 259 InsertDtors::insert( translationUnit ); 260 261 ResolveCopyCtors::resolveImplicitCalls( translationUnit ); 243 { 244 ast::Pass<LabelFinder> finder; 245 ast::Pass<InsertDtors>::run( translationUnit, finder ); 246 } 247 248 ast::Pass<ResolveCopyCtors>::run( translationUnit ); 262 249 FixInit::fixInitializers( translationUnit ); 263 GenStructMemberCalls::generate( translationUnit );250 ast::Pass<GenStructMemberCalls>::run( translationUnit ); 264 251 265 252 // Needs to happen after GenStructMemberCalls, since otherwise member constructors exprs 266 253 // don't have the correct form, and a member can be constructed more than once. 267 FixCtorExprs::fix( translationUnit );254 ast::Pass<FixCtorExprs>::run( translationUnit ); 268 255 } 269 256 … … 319 306 320 307 return dtorFunc; 321 }322 323 void StmtExprResult::link( std::list<ast::ptr<ast::Decl> > & translationUnit ) {324 ast::Pass<StmtExprResult> linker;325 accept_all( translationUnit, linker );326 }327 328 void SplitExpressions::split( std::list<ast::ptr<ast::Decl> > & translationUnit ) {329 ast::Pass<SplitExpressions> splitter;330 accept_all( translationUnit, splitter );331 }332 333 void InsertImplicitCalls::insert( std::list<ast::ptr<ast::Decl> > & translationUnit ) {334 ast::Pass<InsertImplicitCalls> inserter;335 accept_all( translationUnit, inserter );336 }337 338 void ResolveCopyCtors::resolveImplicitCalls( std::list< ast::ptr<ast::Decl> > & translationUnit ) {339 ast::Pass<ResolveCopyCtors> resolver;340 accept_all( translationUnit, resolver );341 308 } 342 309 … … 359 326 throw errors; 360 327 } // if 361 }362 363 void InsertDtors::insert( std::list< ast::ptr<ast::Decl> > & translationUnit ) {364 ast::Pass<LabelFinder> finder;365 ast::Pass<InsertDtors> inserter( finder );366 accept_all( translationUnit, inserter );367 }368 369 void GenStructMemberCalls::generate( std::list< ast::ptr<ast::Decl> > & translationUnit ) {370 ast::Pass<GenStructMemberCalls> warner;371 accept_all( translationUnit, warner );372 }373 374 void FixCtorExprs::fix( std::list< ast::ptr<ast::Decl> > & translationUnit ) {375 ast::Pass<FixCtorExprs> fixer;376 accept_all( translationUnit, fixer );377 328 } 378 329
Note: See TracChangeset
for help on using the changeset viewer.