Changeset 878b1385 for src/ControlStruct/HoistControlDecls.cpp
- Timestamp:
- Jul 24, 2024, 6:59:16 PM (5 months ago)
- Branches:
- master
- Children:
- 151c8db, 5aeb1a9, d02d223
- Parents:
- 1ad112a5 (diff), b6923b17 (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/ControlStruct/HoistControlDecls.cpp
r1ad112a5 r878b1385 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 ) {
Note: See TracChangeset
for help on using the changeset viewer.