mCRL2
Loading...
Searching...
No Matches
has_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_MODAL_FORMULA_HAS_NAME_CLASHES_H
13#define MCRL2_MODAL_FORMULA_HAS_NAME_CLASHES_H
14
16
17namespace mcrl2::state_formulas {
18
19namespace detail
20{
21
23class state_variable_name_clash_checker: public state_formulas::state_formula_traverser<state_variable_name_clash_checker>
24{
25 public:
27
28 using super::apply;
29 using super::enter;
30 using super::leave;
31
33 std::vector<core::identifier_string> m_name_stack;
34
36 void pop()
37 {
38 m_name_stack.pop_back();
39 }
40
42 void push(const core::identifier_string& name)
43 {
45 if (contains(m_name_stack, name))
46 {
47 throw mcrl2::runtime_error("nested propositional variable " + std::string(name) + " clashes");
48 }
49 m_name_stack.push_back(name);
50 }
51
52 void enter(const mu& x)
53 {
54 push(x.name());
55 }
56
57 void leave(const mu&)
58 {
59 pop();
60 }
61
62 void enter(const nu& x)
63 {
64 push(x.name());
65 }
66
67 void leave(const nu&)
68 {
69 pop();
70 }
71};
72
74class state_formula_data_variable_name_clash_checker: public state_formulas::state_formula_traverser<state_formula_data_variable_name_clash_checker>
75{
76 public:
78
79 using super::apply;
80 using super::enter;
81 using super::leave;
82
83 std::set<core::identifier_string> m_names;
84
85 // throws an exception if name was already present in m_names
86 void insert(const core::identifier_string& name, const state_formula& x)
87 {
88 auto p = m_names.insert(name);
89 if (!p.second)
90 {
91 throw mcrl2::runtime_error("Data parameter " + data::pp(name) + " in subformula " + state_formulas::pp(x) + " clashes with a data parameter in an enclosing formula.");
92 }
93 }
94
96 {
97 m_names.erase(name);
98 }
99
100 void enter(const mu& x)
101 {
102 for (const data::assignment& a: x.assignments())
103 {
104 insert(a.lhs().name(), x);
105 }
106 }
107
108 void leave(const mu& x)
109 {
110 for (const data::assignment& a: x.assignments())
111 {
112 erase(a.lhs().name());
113 }
114 }
115
116 void enter(const nu& x)
117 {
118 for (const data::assignment& a: x.assignments())
119 {
120 insert(a.lhs().name(), x);
121 }
122 }
123
124 void leave(const nu& x)
125 {
126 for (const data::assignment& a: x.assignments())
127 {
128 erase(a.lhs().name());
129 }
130 }
131
132 void enter(const forall& x)
133 {
134 for (const data::variable& v: x.variables())
135 {
136 insert(v.name(), x);
137 }
138 }
139
140 void leave(const forall& x)
141 {
142 for (const data::variable& v: x.variables())
143 {
144 erase(v.name());
145 }
146 }
147
148 void enter(const exists& x)
149 {
150 for (const data::variable& v: x.variables())
151 {
152 insert(v.name(), x);
153 }
154 }
155
156 void leave(const exists& x)
157 {
158 for (const data::variable& v: x.variables())
159 {
160 erase(v.name());
161 }
162 }
163};
164
165} // namespace detail
166
168inline
170{
172 checker.apply(x);
173}
174
176inline
178{
179 try
180 {
182 }
183 catch (const mcrl2::runtime_error&)
184 {
185 return true;
186 }
187 return false;
188}
189
191inline
193{
195 checker.apply(x);
196}
197
199inline
201{
202 try
203 {
205 }
206 catch (const mcrl2::runtime_error&)
207 {
208 return true;
209 }
210 return false;
211}
212
213} // namespace mcrl2::state_formulas
214
215#endif // MCRL2_MODAL_FORMULA_HAS_NAME_CLASHES_H
Term containing a string.
\brief Assignment of a data expression to a variable
Definition assignment.h:91
\brief A data variable
Definition variable.h:28
Standard exception class for reporting runtime errors.
Definition exception.h:27
Traverser that checks for name clashes in parameters of nested mu's/nu's and forall/exists.
state_formulas::state_formula_traverser< state_formula_data_variable_name_clash_checker > super
void insert(const core::identifier_string &name, const state_formula &x)
Traverser that checks for name clashes in nested mu's/nu's.
void push(const core::identifier_string &name)
Pushes name on the stack.
state_formulas::state_formula_traverser< state_variable_name_clash_checker > super
std::vector< core::identifier_string > m_name_stack
The stack of names.
\brief The existential quantification operator for state formulas
const data::variable_list & variables() const
\brief The universal quantification operator for state formulas
const data::variable_list & variables() const
\brief The mu operator for state formulas
const core::identifier_string & name() const
const data::assignment_list & assignments() const
\brief The nu operator for state formulas
const core::identifier_string & name() const
const data::assignment_list & assignments() const
add your file description here.
std::string pp(const abstraction &x)
Definition data.cpp:39
void check_data_variable_name_clashes(const state_formula &x)
Throws an exception if the formula contains name clashes in the parameters of mu/nu/exists/forall.
bool has_data_variable_name_clashes(const state_formula &x)
Returns true if the formula contains parameter name clashes.
void check_state_variable_name_clashes(const state_formula &x)
Throws an exception if the formula contains name clashes.
bool has_state_variable_name_clashes(const state_formula &x)
Returns true if the formula contains name clashes.
void pp(const T &t, std::ostream &out)
Prints the object t to a stream.
Definition print.h:668
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