[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 | // |
---|
[51b7345] | 15 | |
---|
| 16 | namespace SymTab { |
---|
[0dd3a2f] | 17 | void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i ); |
---|
[51b7345] | 18 | |
---|
[0dd3a2f] | 19 | template< typename Visitor > |
---|
[c0aa336] | 20 | inline void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ) { |
---|
| 21 | for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) { |
---|
| 22 | // add any new declarations after the previous statement |
---|
| 23 | for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) { |
---|
| 24 | DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); |
---|
| 25 | stmts.insert( stmt, declStmt ); |
---|
| 26 | } |
---|
| 27 | visitor.declsToAddAfter.clear(); |
---|
| 28 | |
---|
| 29 | if ( stmt == stmts.end() ) break; |
---|
| 30 | |
---|
| 31 | // run mutator on statement |
---|
| 32 | maybeAccept( *stmt, visitor ); |
---|
| 33 | |
---|
| 34 | // add any new declarations before the statement |
---|
| 35 | for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) { |
---|
| 36 | DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); |
---|
| 37 | stmts.insert( stmt, declStmt ); |
---|
| 38 | } |
---|
| 39 | visitor.declsToAdd.clear(); |
---|
| 40 | } |
---|
[0dd3a2f] | 41 | } |
---|
[51b7345] | 42 | |
---|
[0dd3a2f] | 43 | template< typename Visitor > |
---|
| 44 | inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) { |
---|
| 45 | addVisitStatementList( compoundStmt->get_kids(), visitor ); |
---|
| 46 | } |
---|
[51b7345] | 47 | |
---|
[0dd3a2f] | 48 | template< typename Visitor > |
---|
| 49 | inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) { |
---|
[8688ce1] | 50 | addVisitStatementList( switchStmt->get_statements(), visitor ); |
---|
[0dd3a2f] | 51 | maybeAccept( switchStmt->get_condition(), visitor ); |
---|
| 52 | } |
---|
[51b7345] | 53 | |
---|
[620cb95] | 54 | template< typename Visitor > |
---|
[c0aa336] | 55 | void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ) { |
---|
| 56 | for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); ; ++decl ) { |
---|
| 57 | // splice in new declarations after previous decl |
---|
| 58 | translationUnit.splice( decl, visitor.declsToAddAfter ); |
---|
| 59 | |
---|
| 60 | if ( decl == translationUnit.end() ) break; |
---|
| 61 | |
---|
| 62 | // run mutator on declaration |
---|
| 63 | maybeAccept( *decl, visitor ); |
---|
| 64 | |
---|
| 65 | // splice in new declarations before current decl |
---|
| 66 | translationUnit.splice( decl, visitor.declsToAdd ); |
---|
| 67 | } |
---|
[620cb95] | 68 | } |
---|
[70a06f6] | 69 | |
---|
[51b7345] | 70 | } // namespace SymTab |
---|
[0dd3a2f] | 71 | |
---|
| 72 | // Local Variables: // |
---|
| 73 | // tab-width: 4 // |
---|
| 74 | // mode: c++ // |
---|
| 75 | // compile-command: "make install" // |
---|
| 76 | // End: // |
---|