mCRL2
Loading...
Searching...
No Matches
replace_capture_avoiding.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_CAPTURE_AVOIDING_H
13#define MCRL2_LPS_REPLACE_CAPTURE_AVOIDING_H
14
15#include "mcrl2/lps/builder.h"
16#include "mcrl2/lps/find.h"
18
19namespace mcrl2 {
20
21namespace lps {
22
23namespace detail {
24
25template <template <class> class Builder, class Derived, class Substitution>
27{
29 using super::enter;
30 using super::leave;
32 using super::update;
33 using super::sigma;
34
36 : super(sigma)
37 { }
38
39 template <typename ActionSummand>
40 void do_action_summand(ActionSummand& x, const data::variable_list& v)
41 {
42 x.summation_variables() = v;
43 data::data_expression condition;
45 data::assignment_list assignments;
46
47 apply(condition, x.condition());
49 apply(assignments, x.assignments());
50
51 x.condition() = condition;
52 x.multi_action() = multi_action;
53 x.assignments() = assignments;
54 }
55
57 {
59 data::variable_list v1 = sigma.add_fresh_variable_assignments(sumvars);
60 do_action_summand(x, v1);
61 sigma.remove_fresh_variable_assignments(sumvars);
62 }
63
65 {
67 data::variable_list v1 = sigma.add_fresh_variable_assignments(sumvars);
68 do_action_summand(x, v1);
69
71 apply(dist, x.distribution(), x.assignments());
72 x.distribution() = dist;
73 sigma.remove_fresh_variable_assignments(sumvars);
74 }
75
77 {
79 data::variable_list v1 = sigma.add_fresh_variable_assignments(sumvars);
80 x.summation_variables() = v1;
81
82 data::data_expression condition;
83 apply(condition, x.condition());
84 x.condition() = condition;
85
86 update(x.deadlock());
87 sigma.remove_fresh_variable_assignments(sumvars);
88 }
89
90 template <typename LinearProcess>
91 void do_linear_process(LinearProcess& x)
92 {
93 data::variable_list process_params = x.process_parameters();
94 data::variable_list v1 = sigma.add_fresh_variable_assignments(process_params);
95 x.process_parameters() = v1;
96 update(x.action_summands());
97 update(x.deadlock_summands());
98 sigma.remove_fresh_variable_assignments(process_params);
99 }
100
102 {
104 }
105
107 {
109 }
110
111 template <typename Specification>
112 void do_specification(Specification& x)
113 {
114 data::variable_list global_vars = x.global_variables();
115 data::variable_list v1 = sigma.add_fresh_variable_assignments(global_vars);
116 x.global_variables() = std::set<data::variable>(v1.begin(), v1.end());
117
118 typename Specification::process_type process;
119 process::action_label_list action_labels;
120 typename Specification::initial_process_type initial_process;
121
122 apply(process, x.process());
123 apply(action_labels, x.action_labels());
124 apply(initial_process, x.initial_process());
125 x.process() = process;
126 x.action_labels() = action_labels;
127 x.initial_process() = initial_process;
128
129 sigma.remove_fresh_variable_assignments(global_vars);
130 }
131
133 {
135 }
136
138 {
140 }
141
142 template<class T>
143 void apply(T& /* result */, const stochastic_distribution& /* x */)
144 {
145 assert(false); // This function should never be called. If a stochastic distribution is
146 // changed, the associated parameter list should be changed too.
147 }
148
150 template<class T>
151 void apply(T& result, const stochastic_distribution& x, data::assignment_list& assignments)
152 {
153 data::variable_list v1 = sigma.add_fresh_variable_assignments(x.variables());
154
156 apply(dist, x.distribution());
157 data::assignment_list aux_assignments;
158 apply(aux_assignments, assignments);
159 assignments = aux_assignments;
160 result = stochastic_distribution(v1, dist);
161 sigma.remove_fresh_variable_assignments(x.variables());
162 }
163
165 template<class T>
167 {
168 data::variable_list v1 = sigma.add_fresh_variable_assignments(x.variables());
169
171 apply(dist, x.distribution());
173 apply(aux_pars, pars);
174 pars = aux_pars;
175 result = stochastic_distribution(v1, dist);
176 sigma.remove_fresh_variable_assignments(x.variables());
177 }
178};
179
180} // namespace detail
181
182//--- start generated lps replace_capture_avoiding code ---//
187template <typename T, typename Substitution>
189 Substitution& sigma,
190 data::set_identifier_generator& id_generator,
191 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
192)
193{
195 data::detail::apply_replace_capture_avoiding_variables_builder<lps::data_expression_builder, lps::detail::add_capture_avoiding_replacement>(sigma1).update(x);
196}
197
202template <typename T, typename Substitution>
204 Substitution& sigma,
205 data::set_identifier_generator& id_generator,
206 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
207)
208{
210 T result;
211 data::detail::apply_replace_capture_avoiding_variables_builder<lps::data_expression_builder, lps::detail::add_capture_avoiding_replacement>(sigma1).apply(result, x);
212 return result;
213}
214
218template <typename T, typename Substitution>
220 Substitution& sigma,
221 typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
222)
223{
225 id_generator.add_identifiers(lps::find_identifiers(x));
226 for (const data::variable& v: substitution_variables(sigma))
227 {
228 id_generator.add_identifier(v.name());
229 }
231}
232
236template <typename T, typename Substitution>
238 Substitution& sigma,
239 typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr
240)
241{
243 id_generator.add_identifiers(lps::find_identifiers(x));
244 for (const data::variable& v: substitution_variables(sigma))
245 {
246 id_generator.add_identifier(v.name());
247 }
248 return lps::replace_variables_capture_avoiding(x, sigma, id_generator);
249}
250//--- end generated lps replace_capture_avoiding code ---//
251
258template <typename Substitution>
262 Substitution& sigma,
264)
265{
268 data::detail::apply_replace_capture_avoiding_variables_builder<lps::data_expression_builder, lps::detail::add_capture_avoiding_replacement>(sigma1).apply(result, x, pars);
269 return result;
270}
271
276template <typename Substitution>
280 Substitution& sigma
281)
282{
284 id_generator.add_identifiers(lps::find_identifiers(x));
285 for (const data::variable& v: substitution_variables(sigma))
286 {
287 id_generator.add_identifier(v.name());
288 }
289 return lps::replace_variables_capture_avoiding(x, pars, sigma, id_generator);
290}
291
292
293} // namespace lps
294
295} // namespace mcrl2
296
297#endif // MCRL2_LPS_REPLACE_CAPTURE_AVOIDING_H
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
void add_identifiers(const std::set< core::identifier_string > &ids)
Add a set of identifiers to the context.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
void add_identifier(const core::identifier_string &s) override
Adds the identifier s to the context.
\brief A data variable
Definition variable.h:28
LPS summand containing a multi-action.
const data::assignment_list & assignments() const
Returns the sequence of assignments.
LPS summand containing a deadlock.
const lps::deadlock & deadlock() const
Returns the deadlock of this summand.
\brief A timed multi-action
multi_action(const multi_action &) noexcept=default
Move semantics.
Linear process specification.
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
\brief A stochastic distribution
const data::variable_list & variables() const
const data::data_expression & distribution() const
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
data::variable_list & summation_variables()
Returns the sequence of summation variables.
Definition summand.h:46
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
add your file description here.
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 find_identifiers(const T &x, OutputIterator o)
Definition find.h:96
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.
process::detail::add_capture_avoiding_replacement< Builder, Derived, Substitution > super
void apply(T &result, const stochastic_distribution &x, data::data_expression_list &pars)
In the code below, it is essential that the assignments are also updated. They are passed by referenc...
void apply(T &result, const stochastic_distribution &x, data::assignment_list &assignments)
In the code below, it is essential that the assignments are also updated. They are passed by referenc...
void do_action_summand(ActionSummand &x, const data::variable_list &v)
add_capture_avoiding_replacement(data::detail::capture_avoiding_substitution_updater< Substitution > &sigma)
capture_avoiding_substitution_updater< Substitution > & sigma
void apply(T &result, const process::process_instance_assignment &x)