| [0dd3a2f] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
 | 
|---|
 | 3 | //
 | 
|---|
 | 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
 | 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
 | 6 | //
 | 
|---|
| [620cb95] | 7 | // AddVisit.h --
 | 
|---|
| [0dd3a2f] | 8 | //
 | 
|---|
 | 9 | // Author           : Richard C. Bilson
 | 
|---|
 | 10 | // Created On       : Sun May 17 16:14:32 2015
 | 
|---|
| [4e06c1e] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [c0aa336] | 12 | // Last Modified On : Thu Feb  2 16:36:02 2017
 | 
|---|
 | 13 | // Update Count     : 14
 | 
|---|
| [0dd3a2f] | 14 | //
 | 
|---|
| [51b73452] | 15 | 
 | 
|---|
| [30f9072] | 16 | #include "SynTree/Statement.h"
 | 
|---|
 | 17 | 
 | 
|---|
| [51b73452] | 18 | namespace SymTab {
 | 
|---|
| [0dd3a2f] | 19 |         void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
 | 
|---|
| [51b73452] | 20 | 
 | 
|---|
| [0dd3a2f] | 21 |         template< typename Visitor >
 | 
|---|
| [c0aa336] | 22 |         inline void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ) {
 | 
|---|
 | 23 |                 for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) {
 | 
|---|
 | 24 |                         // add any new declarations after the previous statement
 | 
|---|
 | 25 |                         for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) {
 | 
|---|
 | 26 |                                 DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
 | 
|---|
 | 27 |                                 stmts.insert( stmt, declStmt );
 | 
|---|
 | 28 |                         }
 | 
|---|
 | 29 |                         visitor.declsToAddAfter.clear();
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 |                         if ( stmt == stmts.end() ) break;
 | 
|---|
| [30f9072] | 32 | 
 | 
|---|
| [c0aa336] | 33 |                         // run mutator on statement
 | 
|---|
 | 34 |                         maybeAccept( *stmt, visitor );
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |                         // add any new declarations before the statement
 | 
|---|
 | 37 |                         for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) {
 | 
|---|
 | 38 |                                 DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
 | 
|---|
 | 39 |                                 stmts.insert( stmt, declStmt );
 | 
|---|
 | 40 |                         }
 | 
|---|
 | 41 |                         visitor.declsToAdd.clear();
 | 
|---|
 | 42 |                 }
 | 
|---|
| [0dd3a2f] | 43 |         }
 | 
|---|
| [51b73452] | 44 | 
 | 
|---|
| [0dd3a2f] | 45 |         template< typename Visitor >
 | 
|---|
 | 46 |         inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
 | 
|---|
 | 47 |                 addVisitStatementList( compoundStmt->get_kids(), visitor );
 | 
|---|
 | 48 |         }
 | 
|---|
| [51b73452] | 49 | 
 | 
|---|
| [0dd3a2f] | 50 |         template< typename Visitor >
 | 
|---|
 | 51 |         inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
 | 
|---|
| [8688ce1] | 52 |                 addVisitStatementList( switchStmt->get_statements(), visitor );
 | 
|---|
| [0dd3a2f] | 53 |                 maybeAccept( switchStmt->get_condition(), visitor );
 | 
|---|
 | 54 |         }
 | 
|---|
| [51b73452] | 55 | 
 | 
|---|
| [620cb95] | 56 |         template< typename Visitor >
 | 
|---|
| [c0aa336] | 57 |         void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ) {
 | 
|---|
 | 58 |                 for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); ; ++decl ) {
 | 
|---|
 | 59 |                         // splice in new declarations after previous decl
 | 
|---|
 | 60 |                         translationUnit.splice( decl, visitor.declsToAddAfter );
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 |                         if ( decl == translationUnit.end() ) break;
 | 
|---|
| [30f9072] | 63 | 
 | 
|---|
| [c0aa336] | 64 |                         // run mutator on declaration
 | 
|---|
 | 65 |                         maybeAccept( *decl, visitor );
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 |                         // splice in new declarations before current decl
 | 
|---|
 | 68 |                         translationUnit.splice( decl, visitor.declsToAdd );
 | 
|---|
 | 69 |                 }
 | 
|---|
| [620cb95] | 70 |         }
 | 
|---|
| [70a06f6] | 71 | 
 | 
|---|
| [51b73452] | 72 | } // namespace SymTab
 | 
|---|
| [0dd3a2f] | 73 | 
 | 
|---|
 | 74 | // Local Variables: //
 | 
|---|
 | 75 | // tab-width: 4 //
 | 
|---|
 | 76 | // mode: c++ //
 | 
|---|
 | 77 | // compile-command: "make install" //
 | 
|---|
 | 78 | // End: //
 | 
|---|