PandA-2024.02
visitor.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
43 #ifndef VISITOR_HPP
44 #define VISITOR_HPP
45 
46 #include "refcount.hpp"
47 #include <algorithm>
48 #include <boost/preprocessor/facilities/empty.hpp>
49 #include <boost/preprocessor/seq/for_each.hpp>
50 #include <deque>
51 
53 #define GETID(field) field##_ID
54 #define VISIT_SC(mask, superclass, method) \
56  if(((1 << GETID(superclass)) & (mask)) == 0) \
57  this->superclass::method
58 #define VISIT_MEMBER_NAMED(ref_obj_name, mask, ref_obj, method) \
60  if(((1 << GETID(ref_obj_name)) & (mask)) == 0 && (ref_obj)) \
61  (ref_obj)->method
62 #define VISIT_MEMBER(mask, ref_obj, method) VISIT_MEMBER_NAMED(ref_obj, mask, ref_obj, method)
63 #define SEQ_VISIT_MEMBER(mask, seq, seqbasetype, method, visitor_type, visitor_obj) \
65  if(((1 << GETID(seq)) & (mask)) == 0 && !(seq).empty()) \
66  std::for_each((seq).begin(), (seq).end(), \
67  for_each_functor<seqbasetype, visitor_type>(&seqbasetype::method, visitor_obj))
68 #define NO_VISIT ~0U
70 #define ALL_VISIT 0U
72 #define SET_NO_VISIT_INDEX(mask, index) ((mask) |= (1U << GETID(index)))
74 #define SET_VISIT_INDEX(mask, index) ((mask) &= ~(1U << GETID(index)))
76 
77 #ifndef VISITED_OBJ_SEQ1
78 #error "VISITED_OBJ_SEQ1 has to be defined in the following form #define VISITED_OBJ_SEQ1 (w)(x)(y)(z)"
79 #endif
80 #ifndef VISITED_OBJ_SEQ2
81 #error "VISITED_OBJ_SEQ2 has to be defined in the following form #define VISITED_OBJ_SEQ2 (w)(x)(y)(z)"
82 #endif
83 
84 #define OPERATOR_MACRO_HEADER(r, data, elem) virtual void operator()(const elem*, unsigned int&)
85 #define OPERATOR_MACRO_DECL(r, data, elem) OPERATOR_MACRO_HEADER(r, data, elem);
86 #define OPERATOR_MACRO(r, data, elem) \
87  OPERATOR_MACRO_HEADER(r, data, elem) \
88  { \
89  }
90 #define OPERATOR_MACRO_HEADERO(r, data, elem) void operator()(const elem*, unsigned int&) override
91 #define OPERATOR_MACRO_DECLO(r, data, elem) OPERATOR_MACRO_HEADERO(r, data, elem);
92 #define OPERATOR_MACROO(r, data, elem) \
93  OPERATOR_MACRO_HEADERO(r, data, elem) \
94  { \
95  }
96 
98 #define FORWARD_DECLARATION_MACRO(r, data, elem) class elem;
101 #undef FORWARD_DECLARATION_MACRO
102 
107 {
108  public:
110  virtual ~object_visitor()
111  {
112  }
127 #undef VISITED_OBJ_SEQ1
128 #undef VISITED_OBJ_SEQ2
129 };
130 
132 template <class T, class visitor_obj>
133 class for_each_functor : public std::unary_function<const refcount<T>&, void>
134 {
136  using visitor_type = visitor_obj* const;
137  using visitor_function_type = void (T::*const)(visitor_type) const;
138 
139  public:
142  : visitor_function(_visitor_function), vo(_vo)
143  {
144  }
146  void operator()(const refcount<T>& x) const
147  {
148  ((x.get())->*visitor_function)(vo);
149  }
150 
151  private:
156 };
157 #endif
#define VISITED_OBJ_SEQ1
sequence of all objects
Definition: tree_node.hpp:98
void(T::*const)(visitor_type) const visitor_function_type
Definition: visitor.hpp:137
#define FORWARD_DECLARATION_MACRO(r, data, elem)
forward declaration macro
Definition: visitor.hpp:98
#define OPERATOR_MACRO(r, data, elem)
Definition: visitor.hpp:86
virtual ~object_visitor()
destructor
Definition: visitor.hpp:110
object visitor template.
Definition: visitor.hpp:106
for_each_functor(const visitor_function_type _visitor_function, visitor_type _vo)
constructor
Definition: visitor.hpp:141
BOOST_PP_SEQ_FOR_EACH(OPERATOR_MACRO, BOOST_PP_EMPTY, VISITED_OBJ_SEQ1)
virtual template object functor
Template definition of refcount.
visitor_type vo
visitor object
Definition: visitor.hpp:155
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
T * get() const
Definition: refcount.hpp:169
visitor_obj *const visitor_type
visitor type definition
Definition: visitor.hpp:136
functor used to traverse sequences with std::for_each
Definition: visitor.hpp:133
x
Return the smallest n such that 2^n >= _x.
#define VISITED_OBJ_SEQ2
Definition: tree_node.hpp:100
void operator()(const refcount< T > &x) const
functor
Definition: visitor.hpp:146
const visitor_function_type visitor_function
visitor member
Definition: visitor.hpp:153

Generated on Mon Feb 12 2024 13:02:56 for PandA-2024.02 by doxygen 1.8.13