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_LPS_REPLACE_H
13#define MCRL2_LPS_REPLACE_H
14
18
19namespace mcrl2
20{
21
22namespace lps
23{
24
25namespace detail {
26
28} // namespace detail
29
30//--- start generated lps replace code ---//
31template <typename T, typename Substitution>
33 const Substitution& sigma,
34 bool innermost,
35 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
36 )
37{
38 data::detail::make_replace_sort_expressions_builder<lps::sort_expression_builder>(sigma, innermost).update(x);
39}
40
41template <typename T, typename Substitution>
42T replace_sort_expressions(const T& x,
43 const Substitution& sigma,
44 bool innermost,
45 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
46 )
47{
48 T result;
49 data::detail::make_replace_sort_expressions_builder<lps::sort_expression_builder>(sigma, innermost).apply(result, x);
50 return result;
51}
52
53template <typename T, typename Substitution>
55 const Substitution& sigma,
56 bool innermost,
57 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
58 )
59{
60 data::detail::make_replace_data_expressions_builder<lps::data_expression_builder>(sigma, innermost).update(x);
61}
62
63template <typename T, typename Substitution>
64T replace_data_expressions(const T& x,
65 const Substitution& sigma,
66 bool innermost,
67 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
68 )
69{
70 T result;
71 data::detail::make_replace_data_expressions_builder<lps::data_expression_builder>(sigma, innermost).apply(result, x);
72 return result;
73}
74
75
76template <typename T, typename Substitution>
77void replace_variables(T& x,
78 const Substitution& sigma,
79 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
80 )
81{
82 core::make_update_apply_builder<lps::data_expression_builder>(sigma).update(x);
83}
84
85template <typename T, typename Substitution>
86T replace_variables(const T& x,
87 const Substitution& sigma,
88 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
89 )
90{
91 T result;
92 core::make_update_apply_builder<lps::data_expression_builder>(sigma).apply(result, x);
93 return result;
94}
95
96template <typename T, typename Substitution>
97void replace_all_variables(T& x,
98 const Substitution& sigma,
99 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
100 )
101{
102 core::make_update_apply_builder<lps::variable_builder>(sigma).update(x);
103}
104
105template <typename T, typename Substitution>
106T replace_all_variables(const T& x,
107 const Substitution& sigma,
108 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
109 )
110{
111 T result;
112 core::make_update_apply_builder<lps::variable_builder>(sigma).apply(result, x);
113 return result;
114}
115
118template <typename T, typename Substitution>
119void replace_free_variables(T& x,
120 const Substitution& sigma,
121 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
122 )
123{
125 data::detail::make_replace_free_variables_builder<lps::data_expression_builder, lps::add_data_variable_builder_binding>(sigma).update(x);
126}
127
130template <typename T, typename Substitution>
131T replace_free_variables(const T& x,
132 const Substitution& sigma,
133 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
134 )
135{
137 T result;
138 data::detail::make_replace_free_variables_builder<lps::data_expression_builder, lps::add_data_variable_builder_binding>(sigma).apply(result, x);
139 return result;
140}
141
144template <typename T, typename Substitution, typename VariableContainer>
145void replace_free_variables(T& x,
146 const Substitution& sigma,
147 const VariableContainer& bound_variables,
148 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
149 )
150{
152 data::detail::make_replace_free_variables_builder<lps::data_expression_builder, lps::add_data_variable_builder_binding>(sigma).update(x, bound_variables);
153}
154
157template <typename T, typename Substitution, typename VariableContainer>
158T replace_free_variables(const T& x,
159 const Substitution& sigma,
160 const VariableContainer& bound_variables,
161 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
162 )
163{
165 T result;
166 data::detail::make_replace_free_variables_builder<lps::data_expression_builder, lps::add_data_variable_builder_binding>(sigma).apply(result, x, bound_variables);
167 return result;
168}
169//--- end generated lps replace code ---//
170
171namespace detail {
172
174template <template <class> class Builder, template <template <class> class, class> class Binder, class Substitution>
175struct replace_process_parameter_builder: public Binder<Builder, replace_process_parameter_builder<Builder, Binder, Substitution> >
176{
177 typedef Binder<Builder, replace_process_parameter_builder<Builder, Binder, Substitution> > super;
178 using super::enter;
179 using super::leave;
180 using super::apply;
181 using super::update;
182 using super::is_bound;
183 using super::bound_variables;
184 using super::increase_bind_count;
185
186 Substitution sigma;
187 std::size_t count; // the bind count
188
189 explicit replace_process_parameter_builder(Substitution sigma_)
190 : sigma(sigma_), count(1)
191 {}
192
193 template <typename VariableContainer>
194 replace_process_parameter_builder(Substitution sigma_, const VariableContainer& bound_variables)
195 : sigma(sigma_), count(1)
196 {
197 increase_bind_count(bound_variables);
198 }
199
200 void apply(data::variable& result, const data::variable& x)
201 {
202 if (bound_variables().count(x) == count)
203 {
204 result = atermpp::down_cast<data::variable>(sigma(x));
205 return;
206 }
207 result = x;
208 }
209
210 template <class T>
211 void apply(T& result, const data::variable& x)
212 {
213 if (bound_variables().count(x) == count)
214 {
215 result = sigma(x);
216 return;
217 }
218 result = static_cast<data::data_expression>(x);
219 }
220
221 template <class T>
222 void apply(T& result, const data::assignment& x)
223 {
224 data::variable lhs;
225 apply(lhs, x.lhs());
226 data::data_expression rhs;
227 apply(rhs, x.rhs());
228 data::make_assignment(result, lhs, rhs);
229 }
230
231 void update(lps::deadlock_summand& x)
232 {
233 count = 1;
234 super::update(x);
235 }
236
237 void update(lps::action_summand& x)
238 {
239 count = 1;
240 super::update(x);
241 data::assignment_list assignments;
242 super::apply(assignments, x.assignments());
243 x.assignments() = assignments;
244 }
245
246 void update(lps::linear_process& x)
247 {
248 super::update(x);
249 count = 0;
250 data::variable_list process_parameters;
251 super::apply(process_parameters, x.process_parameters());
252 x.process_parameters() = process_parameters;
253 }
254};
255
256template <template <class> class Builder, template <template <class> class, class> class Binder, class Substitution>
257replace_process_parameter_builder<Builder, Binder, Substitution>
258make_replace_process_parameters_builder(Substitution sigma)
259{
260 return replace_process_parameter_builder<Builder, Binder, Substitution>(sigma);
261}
263
264} // namespace detail
265
267template <typename Substitution>
268void replace_process_parameters(specification& spec, Substitution sigma)
269{
270 lps::detail::make_replace_process_parameters_builder<lps::data_expression_builder, lps::add_data_variable_builder_binding>(sigma).update(spec);
271}
272
274inline
275void replace_summand_variables(specification& spec, data::mutable_map_substitution<>& sigma)
276{
277 data::set_identifier_generator id_generator;
278 for (const data::variable& v: data::substitution_variables(sigma))
279 {
280 id_generator.add_identifier(v.name());
281 }
282
283 for (action_summand& s: spec.process().action_summands())
284 {
285 s.summation_variables() = data::replace_variables(s.summation_variables(), sigma);
286 s.condition() = data::replace_variables_capture_avoiding(s.condition(), sigma, id_generator);
287 s.multi_action() = lps::replace_variables_capture_avoiding(s.multi_action(), sigma, id_generator);
288 s.assignments() = data::replace_variables_capture_avoiding(s.assignments(), sigma, id_generator);
289 }
290 for (deadlock_summand& s: spec.process().deadlock_summands())
291 {
292 s.summation_variables() = data::replace_variables(s.summation_variables(), sigma);
293 s.condition() = data::replace_variables_capture_avoiding(s.condition(), sigma, id_generator);
294 lps::replace_variables_capture_avoiding(s.deadlock(), sigma, id_generator);
295 }
296}
297
298} // namespace lps
299
300} // namespace mcrl2
301
302#endif // MCRL2_LPS_REPLACE_H
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
add your file description here.
add your file description here.
function_symbol count(const sort_expression &, const sort_expression &s0, const sort_expression &s1)
Definition bag1.h:298
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_capture_avoiding(T &x, Substitution &sigma, data::set_identifier_generator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
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
void replace_variables_capture_avoiding(T &x, Substitution &sigma, data::set_identifier_generator &id_generator, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.