Changeset dbd8652 for src/GenPoly
- Timestamp:
- Feb 29, 2016, 5:42:02 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 9d7b3ea
- Parents:
- 540ddb7d
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/DeclMutator.cc
r540ddb7d rdbd8652 24 24 } 25 25 26 DeclMutator::DeclMutator() : Mutator(), declsToAdd(1) {}26 DeclMutator::DeclMutator() : Mutator(), declsToAdd(1), declsToAddAfter(1) {} 27 27 28 28 DeclMutator::~DeclMutator() {} 29 29 30 30 void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) { 31 for ( std::list< Declaration* >::iterator decl = decls.begin(); decl != decls.end(); ++decl ) { 31 for ( std::list< Declaration* >::iterator decl = decls.begin(); ; ++decl ) { 32 // splice in new declarations after previous decl 33 decls.splice( decl, declsToAddAfter.back() ); 34 35 if ( decl == decls.end() ) break; 36 32 37 // run mutator on declaration 33 38 *decl = maybeMutate( *decl, *this ); … … 39 44 40 45 void DeclMutator::doBeginScope() { 41 // add new decl list for inside of scope46 // add new decl lists for inside of scope 42 47 declsToAdd.resize( declsToAdd.size()+1 ); 48 declsToAddAfter.resize( declsToAddAfter.size()+1 ); 43 49 } 44 50 … … 49 55 newBack->splice( newBack->end(), *back ); 50 56 declsToAdd.pop_back(); 57 58 back = declsToAddAfter.rbegin(); 59 newBack = back + 1; 60 newBack->splice( newBack->end(), *back ); 61 declsToAddAfter.pop_back(); 51 62 } 52 63 … … 61 72 stmt = maybeMutate( stmt, *this ); 62 73 // return if no declarations to add 63 if ( declsToAdd.back().empty() ) return stmt; 74 if ( declsToAdd.back().empty() && declsToAddAfter.back().empty() ) { 75 doEndScope(); 76 return stmt; 77 } 64 78 65 79 // otherwise add declarations to new compound statement … … 71 85 declsToAdd.back().clear(); 72 86 87 // add mutated statement 88 compound->get_kids().push_back( stmt ); 89 90 // add declarations after to new compound statement 91 for ( std::list< Declaration* >::iterator decl = declsToAddAfter.back().begin(); decl != declsToAddAfter.back().end(); ++decl ) { 92 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 93 compound->get_kids().push_back( declStmt ); 94 } 95 declsToAddAfter.back().clear(); 96 73 97 doEndScope(); 74 75 // add mutated statement and return76 compound->get_kids().push_back( stmt );77 98 return compound; 78 99 } … … 80 101 void DeclMutator::mutateStatementList( std::list< Statement* > &stmts ) { 81 102 doBeginScope(); 103 82 104 83 for ( std::list< Statement* >::iterator stmt = stmts.begin(); stmt != stmts.end(); ++stmt ) { 105 for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) { 106 // add any new declarations after the previous statement 107 for ( std::list< Declaration* >::iterator decl = declsToAddAfter.back().begin(); decl != declsToAddAfter.back().end(); ++decl ) { 108 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 109 stmts.insert( stmt, declStmt ); 110 } 111 declsToAddAfter.back().clear(); 112 113 if ( stmt == stmts.end() ) break; 114 84 115 // run mutator on statement 85 116 *stmt = maybeMutate( *stmt, *this ); … … 92 123 declsToAdd.back().clear(); 93 124 } 94 125 95 126 doEndScope(); 96 127 } … … 98 129 void DeclMutator::addDeclaration( Declaration *decl ) { 99 130 declsToAdd.back().push_back( decl ); 131 } 132 133 void DeclMutator::addDeclarationAfter( Declaration *decl ) { 134 declsToAddAfter.back().push_back( decl ); 100 135 } 101 136 -
src/GenPoly/DeclMutator.h
r540ddb7d rdbd8652 55 55 /// Add a declaration to the list to be added before the current position 56 56 void addDeclaration( Declaration* decl ); 57 /// Add a declaration to the list to be added after the current position 58 void addDeclarationAfter( Declaration* decl ); 57 59 private: 58 60 /// A stack of declarations to add before the current declaration or statement 59 61 std::vector< std::list< Declaration* > > declsToAdd; 62 /// A stack of declarations to add after the current declaration or statement 63 std::vector< std::list< Declaration* > > declsToAddAfter; 60 64 }; 61 65 } // namespace
Note: See TracChangeset
for help on using the changeset viewer.