| [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 | // | 
|---|
|  | 7 | // AddVisit.h -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Sun May 17 16:14:32 2015 | 
|---|
| [145f1fc] | 11 | // Last Modified By : Rob Schluntz | 
|---|
|  | 12 | // Last Modified On : Tue Jul 14 12:26:17 2015 | 
|---|
|  | 13 | // Update Count     : 4 | 
|---|
| [0dd3a2f] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
|  | 16 | namespace SymTab { | 
|---|
| [0dd3a2f] | 17 | void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i ); | 
|---|
| [51b73452] | 18 |  | 
|---|
| [0dd3a2f] | 19 | template< typename Visitor > | 
|---|
|  | 20 | inline void addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) { | 
|---|
|  | 21 | for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { | 
|---|
|  | 22 | addDecls( visitor.get_declsToAdd(), statements, i ); | 
|---|
|  | 23 | (*i)->accept( visitor ); | 
|---|
|  | 24 | } // for | 
|---|
|  | 25 | addDecls( visitor.get_declsToAdd(), statements, statements.end() ); | 
|---|
|  | 26 | } | 
|---|
| [51b73452] | 27 |  | 
|---|
| [0dd3a2f] | 28 | template< typename Visitor > | 
|---|
|  | 29 | inline void addVisitStatement( Statement *stmt, Visitor &visitor ) { | 
|---|
|  | 30 | maybeAccept( stmt, visitor ); | 
|---|
| [a32b204] | 31 | ///   if ( ! declsToAdd.empty() ) { | 
|---|
| [51b73452] | 32 | ///     CompoundStmt *compound = new CompoundStmt( noLabels ); | 
|---|
|  | 33 | ///     compound->get_kids().push_back( stmt ); | 
|---|
|  | 34 | ///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() ); | 
|---|
|  | 35 | ///   } | 
|---|
| [0dd3a2f] | 36 | } | 
|---|
| [51b73452] | 37 |  | 
|---|
| [0dd3a2f] | 38 | template< typename Visitor > | 
|---|
|  | 39 | inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) { | 
|---|
|  | 40 | addVisitStatementList( compoundStmt->get_kids(), visitor ); | 
|---|
|  | 41 | } | 
|---|
| [51b73452] | 42 |  | 
|---|
| [0dd3a2f] | 43 | template< typename Visitor > | 
|---|
|  | 44 | inline void addVisit(IfStmt *ifStmt, Visitor &visitor) { | 
|---|
|  | 45 | addVisitStatement( ifStmt->get_thenPart(), visitor ); | 
|---|
|  | 46 | addVisitStatement( ifStmt->get_elsePart(), visitor ); | 
|---|
|  | 47 | maybeAccept( ifStmt->get_condition(), visitor ); | 
|---|
|  | 48 | } | 
|---|
| [51b73452] | 49 |  | 
|---|
| [0dd3a2f] | 50 | template< typename Visitor > | 
|---|
|  | 51 | inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) { | 
|---|
|  | 52 | addVisitStatement( whileStmt->get_body(), visitor ); | 
|---|
|  | 53 | maybeAccept( whileStmt->get_condition(), visitor ); | 
|---|
|  | 54 | } | 
|---|
| [51b73452] | 55 |  | 
|---|
| [0dd3a2f] | 56 | template< typename Visitor > | 
|---|
|  | 57 | inline void addVisit(ForStmt *forStmt, Visitor &visitor) { | 
|---|
|  | 58 | addVisitStatement( forStmt->get_body(), visitor ); | 
|---|
| [145f1fc] | 59 | acceptAll( forStmt->get_initialization(), visitor ); | 
|---|
| [0dd3a2f] | 60 | maybeAccept( forStmt->get_condition(), visitor ); | 
|---|
|  | 61 | maybeAccept( forStmt->get_increment(), visitor ); | 
|---|
|  | 62 | } | 
|---|
| [51b73452] | 63 |  | 
|---|
| [0dd3a2f] | 64 | template< typename Visitor > | 
|---|
|  | 65 | inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) { | 
|---|
|  | 66 | addVisitStatementList( switchStmt->get_branches(), visitor ); | 
|---|
|  | 67 | maybeAccept( switchStmt->get_condition(), visitor ); | 
|---|
|  | 68 | } | 
|---|
| [51b73452] | 69 |  | 
|---|
| [0dd3a2f] | 70 | template< typename Visitor > | 
|---|
|  | 71 | inline void addVisit(ChooseStmt *switchStmt, Visitor &visitor) { | 
|---|
|  | 72 | addVisitStatementList( switchStmt->get_branches(), visitor ); | 
|---|
|  | 73 | maybeAccept( switchStmt->get_condition(), visitor ); | 
|---|
|  | 74 | } | 
|---|
| [51b73452] | 75 |  | 
|---|
| [0dd3a2f] | 76 | template< typename Visitor > | 
|---|
|  | 77 | inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { | 
|---|
|  | 78 | addVisitStatementList( caseStmt->get_statements(), visitor ); | 
|---|
|  | 79 | maybeAccept( caseStmt->get_condition(), visitor ); | 
|---|
|  | 80 | } | 
|---|
| [51b73452] | 81 |  | 
|---|
| [0dd3a2f] | 82 | template< typename Visitor > | 
|---|
|  | 83 | inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) { | 
|---|
|  | 84 | addVisitStatement( cathStmt->get_body(), visitor ); | 
|---|
|  | 85 | maybeAccept( cathStmt->get_decl(), visitor ); | 
|---|
|  | 86 | } | 
|---|
| [51b73452] | 87 | } // namespace SymTab | 
|---|
| [0dd3a2f] | 88 |  | 
|---|
|  | 89 | // Local Variables: // | 
|---|
|  | 90 | // tab-width: 4 // | 
|---|
|  | 91 | // mode: c++ // | 
|---|
|  | 92 | // compile-command: "make install" // | 
|---|
|  | 93 | // End: // | 
|---|