[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
|
---|
[145f1fc] | 11 | // Last Modified By : Rob Schluntz
|
---|
[70a06f6] | 12 | // Last Modified On : Thu Apr 14 15:52:42 2016
|
---|
[630a82a] | 13 | // Update Count : 5
|
---|
[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 addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
|
---|
| 30 | addVisitStatementList( compoundStmt->get_kids(), visitor );
|
---|
| 31 | }
|
---|
[51b73452] | 32 |
|
---|
[0dd3a2f] | 33 | template< typename Visitor >
|
---|
| 34 | inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
|
---|
| 35 | addVisitStatementList( switchStmt->get_branches(), visitor );
|
---|
| 36 | maybeAccept( switchStmt->get_condition(), visitor );
|
---|
| 37 | }
|
---|
[51b73452] | 38 |
|
---|
[0dd3a2f] | 39 | template< typename Visitor >
|
---|
| 40 | inline void addVisit(ChooseStmt *switchStmt, Visitor &visitor) {
|
---|
| 41 | addVisitStatementList( switchStmt->get_branches(), visitor );
|
---|
| 42 | maybeAccept( switchStmt->get_condition(), visitor );
|
---|
| 43 | }
|
---|
[51b73452] | 44 |
|
---|
[630a82a] | 45 | // template< typename Visitor >
|
---|
| 46 | // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
|
---|
| 47 | // addVisitStatementList( caseStmt->get_statements(), visitor );
|
---|
| 48 | // maybeAccept( caseStmt->get_condition(), visitor );
|
---|
| 49 | // }
|
---|
[620cb95] | 50 |
|
---|
| 51 | template< typename Visitor >
|
---|
| 52 | void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
|
---|
| 53 | std::list< Declaration * >::iterator i = translationUnit.begin();
|
---|
| 54 | while ( i != translationUnit.end() ) {
|
---|
| 55 | (*i)->accept( visitor );
|
---|
| 56 | std::list< Declaration * >::iterator next = i;
|
---|
| 57 | next++;
|
---|
| 58 | if ( ! visitor.get_declsToAdd().empty() ) {
|
---|
| 59 | translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
|
---|
| 60 | } // if
|
---|
| 61 | i = next;
|
---|
| 62 | } // while
|
---|
| 63 | }
|
---|
[70a06f6] | 64 |
|
---|
[51b73452] | 65 | } // namespace SymTab
|
---|
[0dd3a2f] | 66 |
|
---|
| 67 | // Local Variables: //
|
---|
| 68 | // tab-width: 4 //
|
---|
| 69 | // mode: c++ //
|
---|
| 70 | // compile-command: "make install" //
|
---|
| 71 | // End: //
|
---|