source: translator/SymTab/AddVisit.h @ 17cd4eb

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 17cd4eb was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[51b7345]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
9namespace SymTab {
10
11void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
12
13template< typename Visitor >
14inline void
15addVisitStatementList( 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
24template< typename Visitor >
25inline void
26addVisitStatement( 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
36template< typename Visitor >
37inline void
38addVisit(CompoundStmt *compoundStmt, Visitor &visitor)
39{
40  addVisitStatementList( compoundStmt->get_kids(), visitor );
41}
42
43template< typename Visitor >
44inline void
45addVisit(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
52template< typename Visitor >
53inline void
54addVisit(WhileStmt *whileStmt, Visitor &visitor)
55{
56  addVisitStatement( whileStmt->get_body(), visitor );
57  maybeAccept( whileStmt->get_condition(), visitor );
58}
59
60template< typename Visitor >
61inline void
62addVisit(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
70template< typename Visitor >
71inline void
72addVisit(SwitchStmt *switchStmt, Visitor &visitor)
73{
74  addVisitStatementList( switchStmt->get_branches(), visitor );
75  maybeAccept( switchStmt->get_condition(), visitor );
76}
77
78template< typename Visitor >
79inline void
80addVisit(ChooseStmt *switchStmt, Visitor &visitor)
81{
82  addVisitStatementList( switchStmt->get_branches(), visitor );
83  maybeAccept( switchStmt->get_condition(), visitor );
84}
85
86template< typename Visitor >
87inline void
88addVisit(CaseStmt *caseStmt, Visitor &visitor)
89{
90  addVisitStatementList( caseStmt->get_statements(), visitor );
91  maybeAccept( caseStmt->get_condition(), visitor );
92}
93
94template< typename Visitor >
95inline void
96addVisit(CatchStmt *cathStmt, Visitor &visitor)
97{
98  addVisitStatement( cathStmt->get_body(), visitor );
99  maybeAccept( cathStmt->get_decl(), visitor );
100}
101
102} // namespace SymTab
Note: See TracBrowser for help on using the repository browser.