1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: AddVisit.h,v 1.2 2005/08/29 20:14:17 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | |
---|
9 | namespace SymTab { |
---|
10 | |
---|
11 | void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i ); |
---|
12 | |
---|
13 | template< typename Visitor > |
---|
14 | inline void |
---|
15 | addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) |
---|
16 | { |
---|
17 | for( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { |
---|
18 | addDecls( visitor.get_declsToAdd(), statements, i ); |
---|
19 | (*i)->accept( visitor ); |
---|
20 | } |
---|
21 | addDecls( visitor.get_declsToAdd(), statements, statements.end() ); |
---|
22 | } |
---|
23 | |
---|
24 | template< typename Visitor > |
---|
25 | inline void |
---|
26 | addVisitStatement( Statement *stmt, Visitor &visitor ) |
---|
27 | { |
---|
28 | maybeAccept( stmt, visitor ); |
---|
29 | /// if( !declsToAdd.empty() ) { |
---|
30 | /// CompoundStmt *compound = new CompoundStmt( noLabels ); |
---|
31 | /// compound->get_kids().push_back( stmt ); |
---|
32 | /// addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() ); |
---|
33 | /// } |
---|
34 | } |
---|
35 | |
---|
36 | template< typename Visitor > |
---|
37 | inline void |
---|
38 | addVisit(CompoundStmt *compoundStmt, Visitor &visitor) |
---|
39 | { |
---|
40 | addVisitStatementList( compoundStmt->get_kids(), visitor ); |
---|
41 | } |
---|
42 | |
---|
43 | template< typename Visitor > |
---|
44 | inline void |
---|
45 | addVisit(IfStmt *ifStmt, Visitor &visitor) |
---|
46 | { |
---|
47 | addVisitStatement( ifStmt->get_thenPart(), visitor ); |
---|
48 | addVisitStatement( ifStmt->get_elsePart(), visitor ); |
---|
49 | maybeAccept( ifStmt->get_condition(), visitor ); |
---|
50 | } |
---|
51 | |
---|
52 | template< typename Visitor > |
---|
53 | inline void |
---|
54 | addVisit(WhileStmt *whileStmt, Visitor &visitor) |
---|
55 | { |
---|
56 | addVisitStatement( whileStmt->get_body(), visitor ); |
---|
57 | maybeAccept( whileStmt->get_condition(), visitor ); |
---|
58 | } |
---|
59 | |
---|
60 | template< typename Visitor > |
---|
61 | inline void |
---|
62 | addVisit(ForStmt *forStmt, Visitor &visitor) |
---|
63 | { |
---|
64 | addVisitStatement( forStmt->get_body(), visitor ); |
---|
65 | maybeAccept( forStmt->get_initialization(), visitor ); |
---|
66 | maybeAccept( forStmt->get_condition(), visitor ); |
---|
67 | maybeAccept( forStmt->get_increment(), visitor ); |
---|
68 | } |
---|
69 | |
---|
70 | template< typename Visitor > |
---|
71 | inline void |
---|
72 | addVisit(SwitchStmt *switchStmt, Visitor &visitor) |
---|
73 | { |
---|
74 | addVisitStatementList( switchStmt->get_branches(), visitor ); |
---|
75 | maybeAccept( switchStmt->get_condition(), visitor ); |
---|
76 | } |
---|
77 | |
---|
78 | template< typename Visitor > |
---|
79 | inline void |
---|
80 | addVisit(ChooseStmt *switchStmt, Visitor &visitor) |
---|
81 | { |
---|
82 | addVisitStatementList( switchStmt->get_branches(), visitor ); |
---|
83 | maybeAccept( switchStmt->get_condition(), visitor ); |
---|
84 | } |
---|
85 | |
---|
86 | template< typename Visitor > |
---|
87 | inline void |
---|
88 | addVisit(CaseStmt *caseStmt, Visitor &visitor) |
---|
89 | { |
---|
90 | addVisitStatementList( caseStmt->get_statements(), visitor ); |
---|
91 | maybeAccept( caseStmt->get_condition(), visitor ); |
---|
92 | } |
---|
93 | |
---|
94 | template< typename Visitor > |
---|
95 | inline void |
---|
96 | addVisit(CatchStmt *cathStmt, Visitor &visitor) |
---|
97 | { |
---|
98 | addVisitStatement( cathStmt->get_body(), visitor ); |
---|
99 | maybeAccept( cathStmt->get_decl(), visitor ); |
---|
100 | } |
---|
101 | |
---|
102 | } // namespace SymTab |
---|