source: src/SymTab/AddVisit.h @ 7069652

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 7069652 was c0aa336, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

third attempt at gcc attributes

  • Property mode set to 100644
File size: 2.5 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 : Peter A. Buhr
12// Last Modified On : Thu Feb  2 16:36:02 2017
13// Update Count     : 14
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* > &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                }
41        }
42
43        template< typename Visitor >
44        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
45                addVisitStatementList( compoundStmt->get_kids(), visitor );
46        }
47
48        template< typename Visitor >
49        inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
50                addVisitStatementList( switchStmt->get_statements(), visitor );
51                maybeAccept( switchStmt->get_condition(), visitor );
52        }
53
54        template< typename Visitor >
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                }
68        }
69
70} // namespace SymTab
71
72// Local Variables: //
73// tab-width: 4 //
74// mode: c++ //
75// compile-command: "make install" //
76// End: //
Note: See TracBrowser for help on using the repository browser.