mCRL2
Loading...
Searching...
No Matches
resolve_name_clashes.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_RESOLVE_NAME_CLASHES_H
13#define MCRL2_LPS_RESOLVE_NAME_CLASHES_H
14
15#include "mcrl2/lps/replace.h"
16
17namespace mcrl2 {
18
19namespace lps {
20
21namespace detail {
22
23// returns the names of the variables in v
24template <typename VariableContainer>
25std::set<core::identifier_string> variable_names(const VariableContainer& vars)
26{
27 std::set<core::identifier_string> result;
28 for (const data::variable& v: vars)
29 {
30 result.insert(v.name());
31 }
32 return result;
33}
34
35// returns the names of variables in v that are also in w
36template <typename VariableContainer>
37std::set<core::identifier_string> variable_name_clashes(const VariableContainer& vars, const std::set<core::identifier_string>& w)
38{
39 std::set<core::identifier_string> result;
40 for (const data::variable& v: vars)
41 {
42 if (w.find(v.name()) != w.end())
43 {
44 result.insert(v.name());
45 }
46 }
47 return result;
48}
49
50inline
52 const std::set<core::identifier_string>& process_parameter_names,
54{
55 const data::variable_list& summation_variables = summand.summation_variables();
56 std::set<core::identifier_string> names = variable_name_clashes(summation_variables, process_parameter_names);
57 if (!names.empty())
58 {
60 for (const data::variable& v: summation_variables)
61 {
62 if (process_parameter_names.find(v.name()) != process_parameter_names.end())
63 {
64 sigma[v] = data::variable(generator(v.name()), v.sort());
65 }
66 }
67 lps::replace_all_variables(summand, sigma);
68 }
69}
70
71inline
73 const std::set<core::identifier_string>& process_parameter_names,
75{
76 const data::variable_list& summation_variables = summand.summation_variables();
77 std::set<core::identifier_string> names = variable_name_clashes(summation_variables, process_parameter_names);
78 if (!names.empty())
79 {
81 for (const data::variable& v: summation_variables)
82 {
83 if (process_parameter_names.find(v.name()) != process_parameter_names.end())
84 {
85 sigma[v] = data::variable(generator(v.name()), v.sort());
86 }
87 }
88 lps::replace_all_variables(summand, sigma);
89 }
90}
91
92inline
94 const std::set<core::identifier_string>& process_parameter_names,
96{
98 std::set<core::identifier_string> summation_names;
99
100 // handle the summation variables
101 for (const data::variable& v: summand.summation_variables())
102 {
103 if (process_parameter_names.find(v.name()) != process_parameter_names.end())
104 {
105 sigma[v] = data::variable(generator(v.name()), v.sort());
106 }
107 summation_names.insert(v.name());
108 }
109 if (!sigma.empty())
110 {
111 lps::replace_all_variables(summand, sigma);
112 }
113
114 // handle the distribution variables
115 sigma.clear();
116
117 for (const data::variable& v: summand.distribution().variables())
118 {
119 if (process_parameter_names.find(v.name()) != process_parameter_names.end() ||
120 summation_names.find(v.name()) != summation_names.end()) // Check stochastic variables also with respect to the summand variables.
121 {
122 sigma[v] = data::variable(generator(v.name()), v.sort());
123 }
124 }
125 if (!sigma.empty())
126 {
127 summand.distribution() = lps::replace_all_variables(summand.distribution(), sigma);
128 summand.assignments() = lps::replace_all_variables(summand.assignments(), sigma);
129 }
130}
131
132} // namespace detail
133
135template <typename Specification>
137{
138 typename Specification::process_type& proc = spec.process();
139 std::set<core::identifier_string> process_parameter_names = detail::variable_names(proc.process_parameters());
140
142 generator.add_identifiers(lps::find_identifiers(spec));
144
145 for (typename Specification::process_type::action_summand_type& s: proc.action_summands())
146 {
147 detail::resolve_summand_variable_name_clashes(s, process_parameter_names, generator);
148 }
149
150 for (deadlock_summand& s: proc.deadlock_summands())
151 {
152 detail::resolve_summand_variable_name_clashes(s, process_parameter_names, generator);
153 }
154}
155
156} // namespace lps
157
158} // namespace mcrl2
159
160#endif // MCRL2_LPS_RESOLVE_NAME_CLASHES_H
void add_identifiers(const std::set< core::identifier_string > &ids)
Add a set of identifiers to the context.
Generic substitution function. The substitution is stored as a mapping of variables to expressions....
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\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.
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
const data::variable_list & variables() const
data::variable_list & summation_variables()
Returns the sequence of summation variables.
Definition summand.h:46
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
@ proc
Definition linearise.cpp:79
add your file description here.
std::set< core::identifier_string > function_and_mapping_identifiers(const data_specification &dataspec)
Returns the names of functions and mappings that occur in a data specification.
void resolve_summand_variable_name_clashes(action_summand &summand, const std::set< core::identifier_string > &process_parameter_names, data::set_identifier_generator &generator)
std::set< core::identifier_string > variable_name_clashes(const VariableContainer &vars, const std::set< core::identifier_string > &w)
std::set< core::identifier_string > variable_names(const VariableContainer &vars)
void resolve_summand_variable_name_clashes(Specification &spec)
Renames summand variables such that there are no name clashes between summand variables and process p...
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