mCRL2
Loading...
Searching...
No Matches
state_formula_rename.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_MODAL_FORMULA_STATE_FORMULA_RENAME_H
13#define MCRL2_MODAL_FORMULA_STATE_FORMULA_RENAME_H
14
16
17namespace mcrl2
18{
19
20namespace state_formulas
21{
22
25template <typename IdentifierGenerator>
26struct state_formula_predicate_variable_rename_builder: public state_formulas::state_formula_builder<state_formula_predicate_variable_rename_builder<IdentifierGenerator> >
27{
29 using super::enter;
30 using super::leave;
31 using super::update;
32 using super::apply;
33
35 IdentifierGenerator& generator;
36
38 std::deque<std::pair<core::identifier_string, core::identifier_string> > replacements;
39
44 {}
45
50 {
52 replacements.push_front(std::make_pair(n, new_name));
53 return new_name;
54 }
55
57 void pop()
58 {
59 replacements.pop_front();
60 }
61
65 template <class T>
66 void apply(T& result, const variable& x)
67 {
68 core::identifier_string new_name = x.name();
69 for (std::deque<std::pair<core::identifier_string, core::identifier_string> >::iterator i = replacements.begin(); i != replacements.end(); ++i)
70 {
71 if (i->first == x.name())
72 {
73 new_name = i->second;
74 break;
75 }
76 }
77 result = variable(new_name, x.arguments());
78 }
79
83 template <class T>
84 void apply(T& result, const mu& x)
85 {
86 core::identifier_string new_name = push(x.name());
87 state_formula new_formula;
88 apply(new_formula, x.operand());
89 pop();
90 make_mu(result, new_name, x.assignments(), new_formula);
91 }
92
96 template <class T>
97 void apply(T& result, const nu& x)
98 {
99 core::identifier_string new_name = push(x.name());
100 state_formula new_formula;
101 apply(new_formula, x.operand());
102 pop();
103 make_nu(result, new_name, x.assignments(), new_formula);
104 }
105};
106
110template <typename IdentifierGenerator>
112{
114}
115
121template <typename IdentifierGenerator>
122state_formula rename_predicate_variables(const state_formula& f, IdentifierGenerator& generator)
123{
124 state_formula result;
126 return result;
127}
128
130struct state_formula_variable_rename_builder: public state_formulas::sort_expression_builder<state_formula_variable_rename_builder>
131{
133
134 using super::enter;
135 using super::leave;
136 using super::update;
137 using super::apply;
138
140 const std::set<core::identifier_string>& forbidden_identifiers;
141
142 std::map<core::identifier_string, core::identifier_string> generated_identifiers;
143
145
147 {
148 std::map<core::identifier_string, core::identifier_string>::iterator i = generated_identifiers.find(x);
149 if (i != generated_identifiers.end())
150 {
151 return i->second;
152 }
153 std::string name = generator(std::string(x));
155 return core::identifier_string(name);
156 }
157
159 state_formula_variable_rename_builder(const std::set<core::identifier_string>& forbidden_identifiers_)
160 : forbidden_identifiers(forbidden_identifiers_)
161 {
163 {
164 generator.add_identifier(std::string(id));
165 }
166 }
167
168 // do not traverse sorts
169 template <class T>
170 void apply(T& result, const data::sort_expression& x)
171 {
172 result = x;
173 }
174
175 template <class T>
176 void apply(T& result, const data::variable& x)
177 {
179 if (!contains(forbidden_identifiers, x.name()))
180 {
181 result = x;
182 return;
183 }
184 data::make_variable(result, create_name(x.name()), x.sort());
185 }
186};
187
192inline
193state_formula rename_variables(const state_formula& f, const std::set<core::identifier_string>& forbidden_identifiers)
194{
195 state_formula result;
196 state_formula_variable_rename_builder(forbidden_identifiers).apply(result, f);
197 return result;
198}
199
200} // namespace state_formulas
201
202} // namespace mcrl2
203
204#endif // MCRL2_MODAL_FORMULA_STATE_FORMULA_RENAME_H
Term containing a string.
\brief A sort expression
\brief A data variable
Definition variable.h:28
const core::identifier_string & name() const
Definition variable.h:38
const sort_expression & sort() const
Definition variable.h:43
\brief The mu operator for state formulas
const core::identifier_string & name() const
const data::assignment_list & assignments() const
const state_formula & operand() const
\brief The nu operator for state formulas
const core::identifier_string & name() const
const state_formula & operand() const
const data::assignment_list & assignments() const
\brief The state formula variable
const core::identifier_string & name() const
const data::data_expression_list & arguments() const
Identifier generator that generates names consisting of a prefix followed by a number....
void add_identifier(const std::string &id)
Adds the strings in the range [first, last) to the context.
add your file description here.
atermpp::aterm_string identifier_string
String type of the LPS library. Identifier strings are represented internally as ATerms.
void make_variable(atermpp::aterm &t, const ARGUMENTS &... args)
Definition variable.h:80
state_formula rename_variables(const state_formula &f, const std::set< core::identifier_string > &forbidden_identifiers)
Renames all data variables in the formula f such that the forbidden identifiers are not used.
state_formula rename_predicate_variables(const state_formula &f, IdentifierGenerator &generator)
Renames predicate variables of the formula f using the specified identifier generator.
state_formula_predicate_variable_rename_builder< IdentifierGenerator > make_state_formula_predicate_variable_rename_builder(IdentifierGenerator &generator)
Utility function for creating a state_formula_predicate_variable_rename_builder.
void make_nu(atermpp::aterm &t, const ARGUMENTS &... args)
void make_mu(atermpp::aterm &t, const ARGUMENTS &... args)
bool contains(const atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable > &c, const typename atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable >::key_type &v, const std::size_t thread_index=0)
Definition indexed_set.h:86
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
void apply(T &result, const state_formulas::true_ &x)
Definition builder.h:1202
void update(state_formulas::state_formula_specification &x)
Definition builder.h:1425
void update(state_formulas::state_formula_specification &x)
Definition builder.h:2526
void apply(T &result, const state_formulas::true_ &x)
Definition builder.h:2297
core::identifier_string push(const core::identifier_string &n)
Generates a new name for n, and adds a replacement to the replacement stack.
state_formulas::state_formula_builder< state_formula_predicate_variable_rename_builder< IdentifierGenerator > > super
std::deque< std::pair< core::identifier_string, core::identifier_string > > replacements
A stack of replacements. It may contain pairs with identical values.
state_formula_predicate_variable_rename_builder(IdentifierGenerator &generator)
Constructor.
Visitor that renames variables using the specified identifier generator. Also bound variables are ren...
state_formulas::sort_expression_builder< state_formula_variable_rename_builder > super
void apply(T &result, const data::sort_expression &x)
state_formula_variable_rename_builder(const std::set< core::identifier_string > &forbidden_identifiers_)
Constructor.
const std::set< core::identifier_string > & forbidden_identifiers
The set of identifiers that may not be used as a variable name.
core::identifier_string create_name(const core::identifier_string &x)
std::map< core::identifier_string, core::identifier_string > generated_identifiers