source: src/SymTab/AddVisit.h @ 620cb95

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 620cb95 was 620cb95, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

separate Autogen from Validate, call default ctor/dtors on array elements

  • Property mode set to 100644
File size: 3.6 KB
Line 
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 : Rob Schluntz
12// Last Modified On : Tue Jul 14 12:26:17 2015
13// Update Count     : 4
14//
15
16namespace SymTab {
17        void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
18
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        }
27
28        template< typename Visitor >
29        inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {
30                maybeAccept( stmt, visitor );
31///   if ( ! declsToAdd.empty() ) {
32///     CompoundStmt *compound = new CompoundStmt( noLabels );
33///     compound->get_kids().push_back( stmt );
34///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );
35///   }
36        }
37
38        template< typename Visitor >
39        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
40                addVisitStatementList( compoundStmt->get_kids(), visitor );
41        }
42
43        template< typename Visitor >
44        inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {
45                addVisitStatement( ifStmt->get_thenPart(), visitor );
46                addVisitStatement( ifStmt->get_elsePart(), visitor );
47                maybeAccept( ifStmt->get_condition(), visitor );
48        }
49
50        template< typename Visitor >
51        inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {
52                addVisitStatement( whileStmt->get_body(), visitor );
53                maybeAccept( whileStmt->get_condition(), visitor );
54        }
55
56        template< typename Visitor >
57        inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
58                addVisitStatement( forStmt->get_body(), visitor );
59                acceptAll( forStmt->get_initialization(), visitor );
60                maybeAccept( forStmt->get_condition(), visitor );
61                maybeAccept( forStmt->get_increment(), visitor );
62        }
63
64        template< typename Visitor >
65        inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
66                addVisitStatementList( switchStmt->get_branches(), visitor );
67                maybeAccept( switchStmt->get_condition(), visitor );
68        }
69
70        template< typename Visitor >
71        inline void addVisit(ChooseStmt *switchStmt, Visitor &visitor) {
72                addVisitStatementList( switchStmt->get_branches(), visitor );
73                maybeAccept( switchStmt->get_condition(), visitor );
74        }
75
76        template< typename Visitor >
77        inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
78                addVisitStatementList( caseStmt->get_statements(), visitor );
79                maybeAccept( caseStmt->get_condition(), visitor );
80        }
81
82        template< typename Visitor >
83        inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) {
84                addVisitStatement( cathStmt->get_body(), visitor );
85                maybeAccept( cathStmt->get_decl(), visitor );
86        }
87
88        template< typename Visitor >
89        void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
90                std::list< Declaration * >::iterator i = translationUnit.begin();
91                while ( i != translationUnit.end() ) {
92                        (*i)->accept( visitor );
93                        std::list< Declaration * >::iterator next = i;
94                        next++;
95                        if ( ! visitor.get_declsToAdd().empty() ) {
96                                translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
97                        } // if
98                        i = next;
99                } // while
100        }
101} // namespace SymTab
102
103// Local Variables: //
104// tab-width: 4 //
105// mode: c++ //
106// compile-command: "make install" //
107// End: //
Note: See TracBrowser for help on using the repository browser.