Changeset a08ba92 for translator/InitTweak/DeclarationHoister.cc
- Timestamp:
- May 19, 2015, 4:58:14 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:
- 843054c2
- Parents:
- 01aeade
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/InitTweak/DeclarationHoister.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // DeclarationHoister.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:33:20 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 27 28 #include "DeclarationHoister.h" 28 29 30 namespace InitTweak { 31 CompoundStmt* DeclarationHoister::mutate( CompoundStmt *compoundStmt ) { 32 typedef std::list<Statement *>::iterator stmt_it; 33 // 1. collect Declaration Statements in this scope 34 std::list<Statement *> &kids = compoundStmt->get_kids(); 35 std::list<Statement *>::iterator result = kids.begin(); 36 std::list< stmt_it > decls; 29 37 30 namespace InitTweak { 38 while ( result != kids.end() ) { 39 result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > ); 31 40 32 CompoundStmt* DeclarationHoister::mutate(CompoundStmt *compoundStmt) { 33 typedef std::list<Statement *>::iterator stmt_it; 34 // 1. collect Declaration Statements in this scope 35 std::list<Statement *> &kids = compoundStmt->get_kids(); 36 std::list<Statement *>::iterator result = kids.begin(); 37 std::list< stmt_it > decls; 41 if ( result != kids.end() ) { 42 decls.push_back( result ); 43 std::advance( result, 1 ); 44 } // if 45 } // while 38 46 39 while ( result != kids.end() ) { 40 result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > ); 47 for ( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ) { 48 kids.push_front( **i ); 49 kids.erase( *i ); 50 } // for 41 51 42 if ( result != kids.end() ) { 43 decls.push_back( result ); 44 std::advance( result, 1 ); 45 } 46 } 47 48 for ( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ){ 49 kids.push_front( **i ); 50 kids.erase( *i ); 51 } 52 53 return compoundStmt; 54 } 52 return compoundStmt; 53 } 55 54 } // namespace InitTweak 56 57 58 59 60 61 62 63 55 64 56 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.