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
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Thu Feb 2 16:36:02 2017
|
---|
13 | // Update Count : 14
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include "SynTree/Statement.h"
|
---|
17 |
|
---|
18 | namespace SymTab {
|
---|
19 | void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
|
---|
20 |
|
---|
21 | template< typename Visitor >
|
---|
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( *decl );
|
---|
27 | stmts.insert( stmt, declStmt );
|
---|
28 | }
|
---|
29 | visitor.declsToAddAfter.clear();
|
---|
30 |
|
---|
31 | if ( stmt == stmts.end() ) break;
|
---|
32 |
|
---|
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( *decl );
|
---|
39 | stmts.insert( stmt, declStmt );
|
---|
40 | }
|
---|
41 | visitor.declsToAdd.clear();
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | template< typename Visitor >
|
---|
46 | inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
|
---|
47 | addVisitStatementList( compoundStmt->get_kids(), visitor );
|
---|
48 | }
|
---|
49 |
|
---|
50 | template< typename Visitor >
|
---|
51 | inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
|
---|
52 | addVisitStatementList( switchStmt->get_statements(), visitor );
|
---|
53 | maybeAccept( switchStmt->get_condition(), visitor );
|
---|
54 | }
|
---|
55 |
|
---|
56 | template< typename Visitor >
|
---|
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;
|
---|
63 |
|
---|
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 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | } // namespace SymTab
|
---|
73 |
|
---|
74 | // Local Variables: //
|
---|
75 | // tab-width: 4 //
|
---|
76 | // mode: c++ //
|
---|
77 | // compile-command: "make install" //
|
---|
78 | // End: //
|
---|