ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        ctor
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        gc_noraii
        jacob/cs343-translation
        jenkins-sandbox
        memory
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        string
        with_gc
      
      
        
          | Last change
 on this file since fe3b61b was             51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago | 
        
          | 
initial commit
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.0 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <list> | 
|---|
| 2 | #include <cassert> | 
|---|
| 3 | #include <iostream> | 
|---|
| 4 | #include <iterator> | 
|---|
| 5 | #include <algorithm> | 
|---|
| 6 |  | 
|---|
| 7 | #include "utility.h" | 
|---|
| 8 |  | 
|---|
| 9 | #include "SynTree/Statement.h" | 
|---|
| 10 | #include "SynTree/Expression.h" | 
|---|
| 11 | #include "SynTree/Declaration.h" | 
|---|
| 12 |  | 
|---|
| 13 | #include "DeclarationHoister.h" | 
|---|
| 14 |  | 
|---|
| 15 |  | 
|---|
| 16 | namespace InitTweak { | 
|---|
| 17 |  | 
|---|
| 18 | CompoundStmt* DeclarationHoister::mutate(CompoundStmt *compoundStmt) { | 
|---|
| 19 | typedef std::list<Statement *>::iterator stmt_it; | 
|---|
| 20 | // 1. collect Declaration Statements  in this scope | 
|---|
| 21 | std::list<Statement *> &kids = compoundStmt->get_kids(); | 
|---|
| 22 | std::list<Statement *>::iterator result = kids.begin(); | 
|---|
| 23 | std::list< stmt_it > decls; | 
|---|
| 24 |  | 
|---|
| 25 | while ( result !=  kids.end() ) { | 
|---|
| 26 | result = std::find_if(result, kids.end(), cast_ptr< Statement, DeclStmt > ); | 
|---|
| 27 |  | 
|---|
| 28 | if ( result != kids.end() ) { | 
|---|
| 29 | decls.push_back( result ); | 
|---|
| 30 | std::advance( result, 1 ); | 
|---|
| 31 | } | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | for( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ){ | 
|---|
| 35 | kids.push_front( **i ); | 
|---|
| 36 | kids.erase( *i ); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | return compoundStmt; | 
|---|
| 40 | } | 
|---|
| 41 | } // namespace InitTweak | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 |  | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.