mCRL2
Loading...
Searching...
No Matches
replace.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_DATA_REPLACE_H
13#define MCRL2_DATA_REPLACE_H
14
17
18namespace mcrl2
19{
20
21namespace data
22{
23
24namespace detail
25{
26
28template <template <class> class Builder, class Substitution>
29struct replace_sort_expressions_builder: public Builder<replace_sort_expressions_builder<Builder, Substitution> >
30{
31 typedef Builder<replace_sort_expressions_builder<Builder, Substitution> > super;
32 using super::enter;
33 using super::leave;
34 using super::apply;
35 using super::update;
36
37 const Substitution& sigma;
38 bool innermost;
39
40 replace_sort_expressions_builder(const Substitution& sigma_, bool innermost_)
41 : sigma(sigma_),
42 innermost(innermost_)
43 {}
44
45 template <class T>
46 void apply(T& result, const sort_expression& x)
47 {
48 if (innermost)
49 {
50 super::apply(result, x);
51 result = sigma(result);
52 return;
53 }
54 result = sigma(x);
55 return;
56 }
57};
58
59template <template <class> class Builder, class Substitution>
60replace_sort_expressions_builder<Builder, Substitution>
61make_replace_sort_expressions_builder(const Substitution& sigma, bool innermost)
62{
63 return replace_sort_expressions_builder<Builder, Substitution>(sigma, innermost);
64}
65
66template <template <class> class Builder, class Substitution>
67struct replace_data_expressions_builder: public Builder<replace_data_expressions_builder<Builder, Substitution> >
68{
69 typedef Builder<replace_data_expressions_builder<Builder, Substitution> > super;
70 using super::enter;
71 using super::leave;
72 using super::apply;
73 using super::update;
74
75 Substitution sigma;
76 bool innermost;
77
78 replace_data_expressions_builder(Substitution sigma_, bool innermost_)
79 : sigma(sigma_),
80 innermost(innermost_)
81 {}
82
83 template <class T>
84 void apply(T& result, const data_expression& x)
85 {
86 if (innermost)
87 {
88 data_expression y;
89 super::apply(y, x);
90 result = sigma(y);
91 return;
92 }
93 result = sigma(x);
94 }
95};
96
97template <template <class> class Builder, class Substitution>
98replace_data_expressions_builder<Builder, Substitution>
99make_replace_data_expressions_builder(const Substitution& sigma, bool innermost)
100{
101 return replace_data_expressions_builder<Builder, Substitution>(sigma, innermost);
102}
103
104template <template <class> class Builder, template <template <class> class, class> class Binder, class Substitution>
105struct replace_free_variables_builder: public Binder<Builder, replace_free_variables_builder<Builder, Binder, Substitution> >
106{
107 typedef Binder<Builder, replace_free_variables_builder<Builder, Binder, Substitution> > super;
108 using super::enter;
109 using super::leave;
110 using super::apply;
111 using super::update;
112 using super::is_bound;
113 using super::bound_variables;
114 using super::increase_bind_count;
115
116 const Substitution& sigma;
117
118 explicit replace_free_variables_builder(const Substitution& sigma_)
119 : sigma(sigma_)
120 {}
121
122 template <typename VariableContainer>
123 replace_free_variables_builder(const Substitution& sigma_, const VariableContainer& bound_variables)
124 : sigma(sigma_)
125 {
126 increase_bind_count(bound_variables);
127 }
128
129 template <class T>
130 void apply(T& result, const variable& v)
131 {
132 if (is_bound(v))
133 {
134 result = v;
135 return;
136 }
137 result = sigma(v);
138 }
139};
140
141template <template <class> class Builder, template <template <class> class, class> class Binder, class Substitution>
142replace_free_variables_builder<Builder, Binder, Substitution>
143make_replace_free_variables_builder(const Substitution& sigma)
144{
145 return replace_free_variables_builder<Builder, Binder, Substitution>(sigma);
146}
147
148template <template <class> class Builder, template <template <class> class, class> class Binder, class Substitution, class VariableContainer>
149replace_free_variables_builder<Builder, Binder, Substitution>
150make_replace_free_variables_builder(const Substitution& sigma, const VariableContainer& bound_variables)
151{
152 return replace_free_variables_builder<Builder, Binder, Substitution>(sigma, bound_variables);
153}
154
156
157} // namespace detail
158
160template <typename Substitution>
161std::set<data::variable> substitution_variables(const Substitution& /* sigma */)
162{
163 throw mcrl2::runtime_error("substitution_variables is undefined!");
164}
165
166//--- start generated data replace code ---//
167template <typename T, typename Substitution>
169 const Substitution& sigma,
170 bool innermost,
171 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
172 )
173{
174 data::detail::make_replace_sort_expressions_builder<data::sort_expression_builder>(sigma, innermost).update(x);
175}
176
177template <typename T, typename Substitution>
179 const Substitution& sigma,
180 bool innermost,
181 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
182 )
183{
184 T result;
185 data::detail::make_replace_sort_expressions_builder<data::sort_expression_builder>(sigma, innermost).apply(result, x);
186 return result;
187}
188
189template <typename T, typename Substitution>
191 const Substitution& sigma,
192 bool innermost,
193 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
194 )
195{
196 data::detail::make_replace_data_expressions_builder<data::data_expression_builder>(sigma, innermost).update(x);
197}
198
199template <typename T, typename Substitution>
201 const Substitution& sigma,
202 bool innermost,
203 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
204 )
205{
206 T result;
207 data::detail::make_replace_data_expressions_builder<data::data_expression_builder>(sigma, innermost).apply(result, x);
208 return result;
209}
210
211
212template <typename T, typename Substitution>
214 const Substitution& sigma,
215 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
216 )
217{
218 core::make_update_apply_builder<data::data_expression_builder>(sigma).update(x);
219}
220
221template <typename T, typename Substitution>
222T replace_variables(const T& x,
223 const Substitution& sigma,
224 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
225 )
226{
227 T result;
228 core::make_update_apply_builder<data::data_expression_builder>(sigma).apply(result, x);
229 return result;
230}
231
232template <typename T, typename Substitution>
234 const Substitution& sigma,
235 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
236 )
237{
238 core::make_update_apply_builder<data::variable_builder>(sigma).update(x);
239}
240
241template <typename T, typename Substitution>
243 const Substitution& sigma,
244 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
245 )
246{
247 T result;
248 core::make_update_apply_builder<data::variable_builder>(sigma).apply(result, x);
249 return result;
250}
251
254template <typename T, typename Substitution>
256 const Substitution& sigma,
257 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
258 )
259{
261 data::detail::make_replace_free_variables_builder<data::data_expression_builder, data::add_data_variable_builder_binding>(sigma).update(x);
262}
263
266template <typename T, typename Substitution>
268 const Substitution& sigma,
269 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
270 )
271{
273 T result;
274 data::detail::make_replace_free_variables_builder<data::data_expression_builder, data::add_data_variable_builder_binding>(sigma).apply(result, x);
275 return result;
276}
277
280template <typename T, typename Substitution, typename VariableContainer>
282 const Substitution& sigma,
283 const VariableContainer& bound_variables,
284 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
285 )
286{
288 data::detail::make_replace_free_variables_builder<data::data_expression_builder, data::add_data_variable_builder_binding>(sigma).update(x, bound_variables);
289}
290
293template <typename T, typename Substitution, typename VariableContainer>
295 const Substitution& sigma,
296 const VariableContainer& bound_variables,
297 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
298 )
299{
301 T result;
302 data::detail::make_replace_free_variables_builder<data::data_expression_builder, data::add_data_variable_builder_binding>(sigma).apply(result, x, bound_variables);
303 return result;
304}
305//--- end generated data replace code ---//
306
307template <typename T, typename Substitution>
309 const Substitution& sigma,
310 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type* = 0
311 )
312{
313 core::make_update_apply_builder<data::sort_expression_builder>(sigma).update(x);
314}
315
316template <typename T, typename Substitution>
317T substitute_sorts(const T& x,
318 const Substitution& sigma,
319 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type* = 0
320 )
321{
322 T result;
323 core::make_update_apply_builder<data::sort_expression_builder>(sigma).apply(result, x);
324 return result;
325}
326
327} // namespace data
328
329} // namespace mcrl2
330
331#endif // MCRL2_DATA_REPLACE_H
Standard exception class for reporting runtime errors.
Definition exception.h:27
add your file description here.
add your file description here.
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
void substitute_sorts(T &x, const Substitution &sigma, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
Definition replace.h:308
void replace_all_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:233
std::set< data::variable > substitution_variables(const Substitution &)
Returns the variables appearing in the right hand sides of the substitution.
Definition replace.h:161
void replace_sort_expressions(T &x, const Substitution &sigma, bool innermost, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:168
void replace_data_expressions(T &x, const Substitution &sigma, bool innermost, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:190
void replace_free_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:255
bool is_simple_substitution(const Substitution &)
Returns true if the substitution sigma satisfies the property that FV(sigma(x)) is included in {x} fo...
void replace_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition replace.h:213
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72