- Timestamp:
- Jul 24, 2024, 12:22:52 PM (5 months ago)
- Branches:
- master
- Children:
- 878b1385, a03ed29
- Parents:
- 35c792f
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/HoistControlDecls.cpp
r35c792f rb6923b17 9 9 // Author : Andrew Beach 10 10 // Created On : Fri Dec 3 15:34:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Feb 1 18:59:47 202213 // Update Count : 2511 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 24 12:00:00 2024 13 // Update Count : 3 14 14 // 15 15 … … 23 23 namespace ControlStruct { 24 24 25 namespace { 26 25 27 template<typename StmtT> 26 28 const Stmt * hoist( const StmtT * stmt ) { 27 // If no hoisting is needed, then make no changes. 28 29 if ( stmt->inits.size() == 0 ) { // no declarations ? 29 // If no hoisting is needed (no declaration), then make no changes. 30 if ( stmt->inits.size() == 0 ) { 30 31 // if ( /* no conditional declarations */ ... ) ... 31 32 return stmt; 32 } // if33 } 33 34 34 // Put hoist declarations and modified statement in a compound statement. 35 36 CompoundStmt * block = new CompoundStmt( stmt->location ); // create empty compound statement 35 StmtT * mutStmt = mutate( stmt ); 36 CompoundStmt * block = new CompoundStmt( stmt->location ); 37 37 // {} 38 38 39 for ( const Stmt * next : stmt->inits ) { // link conditional declarations into compound 39 // Label: if ( int x = f(), y = g(); ... ) ... 40 // link declarations into compound statement 41 for ( const Stmt * next : mutStmt->inits ) { 40 42 block->kids.push_back( next ); 41 43 } 42 // if ( int x = f(), y = g(); ... ) ...43 // link declarations into compound statement44 44 // { 45 45 // int x = f(); 46 46 // int y = g(); 47 47 // } 48 mutStmt->inits.clear(); 49 // Label: if ( ... ) ... 48 50 49 StmtT * mutStmt = mutate( stmt ); // create mutate handle to change statement 50 mutStmt->inits.clear(); // remove declarations 51 block->labels.swap( mutStmt->labels ); 52 // Label: { 53 // int x = f(); 54 // int y = g(); 55 // } 51 56 // if ( ... ) ... 52 57 53 block->kids.push_back( mutStmt ); // link modified statement into compound54 // {58 block->kids.push_back( mutStmt ); 59 // Label: { 55 60 // int x = f(); 56 61 // int y = g(); … … 73 78 }; 74 79 80 } // namespace 81 75 82 // Hoist initialization out of for statements. 76 83 void hoistControlDecls( TranslationUnit & translationUnit ) { -
src/ControlStruct/HoistControlDecls.hpp
r35c792f rb6923b17 9 9 // Author : Andrew Beach 10 10 // Created On : Fri Dec 3 15:31:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jan 31 22:25:07 202211 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 24 12:04:00 2024 13 13 // Update Count : 3 14 14 // … … 21 21 22 22 namespace ControlStruct { 23 23 24 /// Hoist declarations out of control flow statements into compound statement. 24 /// Must happen before auto-gen routines are added. 25 /// Must happen before auto-gen routines are added and after loop control 26 /// flow is resolved. 25 27 void hoistControlDecls( ast::TranslationUnit & translationUnit ); 28 26 29 } // namespace ControlStruct 27 30 -
src/main.cpp
r35c792f rb6923b17 331 331 PASS( "Fix Unique Ids", Validate::fixUniqueIds, transUnit ); 332 332 PASS( "Implement Corun", Concurrency::implementCorun, transUnit ); 333 PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit ); 334 PASS( "Fix Labels", ControlStruct::fixLabels, transUnit ); 333 335 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit ); 334 336 … … 342 344 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit ); 343 345 PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit ); 344 PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );345 346 346 347 if ( symtabp ) { … … 356 357 357 358 PASS( "Translate Throws", ControlStruct::translateThrows, transUnit ); 358 PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );359 359 PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit ); 360 360 PASS( "Fix Names", CodeGen::fixNames, transUnit );
Note: See TracChangeset
for help on using the changeset viewer.