mCRL2
Loading...
Searching...
No Matches
find.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink, Jeroen van der Wulp
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_DATA_FIND_H
13#define MCRL2_DATA_FIND_H
14
18
19namespace mcrl2
20{
21
22namespace data
23{
24
25namespace detail
26{
28template <template <class> class Traverser, class OutputIterator>
29struct find_identifiers_traverser: public Traverser<find_identifiers_traverser<Traverser, OutputIterator> >
30{
31 typedef Traverser<find_identifiers_traverser<Traverser, OutputIterator> > super;
32
33 using super::enter;
34 using super::leave;
35 using super::apply;
36
37 OutputIterator out;
38
39 explicit find_identifiers_traverser(OutputIterator out_)
40 : out(out_)
41 {}
42
43 void apply(const core::identifier_string& v)
44 {
45 *out = v;
46 }
47};
48
49template <template <class> class Traverser, class OutputIterator>
50find_identifiers_traverser<Traverser, OutputIterator>
51make_find_identifiers_traverser(OutputIterator out)
52{
53 return find_identifiers_traverser<Traverser, OutputIterator>(out);
54}
55
56template <template <class> class Traverser, class OutputIterator>
57struct find_function_symbols_traverser: public Traverser<find_function_symbols_traverser<Traverser, OutputIterator> >
58{
59 typedef Traverser<find_function_symbols_traverser<Traverser, OutputIterator> > super;
60 using super::enter;
61 using super::leave;
62 using super::apply;
63
64 OutputIterator out;
65
66 explicit find_function_symbols_traverser(OutputIterator out_)
67 : out(out_)
68 {}
69
70 void apply(const function_symbol& v)
71 {
72 *out = v;
73 }
74};
75
76template <template <class> class Traverser, class OutputIterator>
77find_function_symbols_traverser<Traverser, OutputIterator>
78make_find_function_symbols_traverser(OutputIterator out)
79{
80 return find_function_symbols_traverser<Traverser, OutputIterator>(out);
81}
82
83template <template <class> class Traverser, class OutputIterator>
84struct find_sort_expressions_traverser: public Traverser<find_sort_expressions_traverser<Traverser, OutputIterator> >
85{
86 typedef Traverser<find_sort_expressions_traverser<Traverser, OutputIterator> > super;
87 using super::enter;
88 using super::leave;
89 using super::apply;
90
91 OutputIterator out;
92
93 explicit find_sort_expressions_traverser(OutputIterator out_)
94 : out(out_)
95 {
96 }
97
98 void apply(const data::sort_expression& v)
99 {
100 *out = v;
101
102 // also traverse sub-expressions!
103 super::apply(v);
104 }
105};
106
107template <template <class> class Traverser, class OutputIterator>
108find_sort_expressions_traverser<Traverser, OutputIterator>
109make_find_sort_expressions_traverser(OutputIterator out)
110{
111 return find_sort_expressions_traverser<Traverser, OutputIterator>(out);
112}
113
114template <template <class> class Traverser, class OutputIterator>
115struct find_data_expressions_traverser: public Traverser<find_data_expressions_traverser<Traverser, OutputIterator> >
116{
117 typedef Traverser<find_data_expressions_traverser<Traverser, OutputIterator> > super;
118 using super::enter;
119 using super::leave;
120 using super::apply;
121
122 OutputIterator out;
123
124 explicit find_data_expressions_traverser(OutputIterator out_)
125 : out(out_)
126 {}
127
128 void apply(const data::data_expression& v)
129 {
130 *out = v;
131
132 // also traverse sub-expressions!
133 super::apply(v);
134 }
135};
136
137template <template <class> class Traverser, class OutputIterator>
138find_data_expressions_traverser<Traverser, OutputIterator>
139make_find_data_expressions_traverser(OutputIterator out)
140{
141 return find_data_expressions_traverser<Traverser, OutputIterator>(out);
142}
143
144template <template <class> class Traverser, class OutputIterator>
145struct find_all_variables_traverser: public Traverser<find_all_variables_traverser<Traverser, OutputIterator> >
146{
147 typedef Traverser<find_all_variables_traverser<Traverser, OutputIterator> > super;
148 using super::enter;
149 using super::leave;
150 using super::apply;
151
152 OutputIterator out;
153
154 explicit find_all_variables_traverser(OutputIterator out_)
155 : out(out_)
156 {}
157
158 void apply(const variable& v)
159 {
160 *out = v;
161 }
162};
163
164template <template <class> class Traverser, class OutputIterator>
165find_all_variables_traverser<Traverser, OutputIterator>
166make_find_all_variables_traverser(OutputIterator out)
167{
168 return find_all_variables_traverser<Traverser, OutputIterator>(out);
169}
170
171template <typename T, typename OutputIterator> void find_free_variables(const T& x, OutputIterator o);
172
173template <template <class> class Traverser, template <template <class> class, class> class Binder, class OutputIterator>
174struct find_free_variables_traverser: public Binder<Traverser, find_free_variables_traverser<Traverser, Binder, OutputIterator> >
175{
176 typedef Binder<Traverser, find_free_variables_traverser<Traverser, Binder, OutputIterator> > super;
177 using super::enter;
178 using super::leave;
179 using super::apply;
180 using super::is_bound;
181 using super::bound_variables;
182 using super::increase_bind_count;
183
184 OutputIterator out;
185
186 explicit find_free_variables_traverser(OutputIterator out_)
187 : out(out_)
188 {}
189
190 template <typename VariableContainer>
191 find_free_variables_traverser(OutputIterator out_, const VariableContainer& v)
192 : out(out_)
193 {
194 increase_bind_count(v);
195 }
196
197 void apply(const variable& v)
198 {
199 if (!is_bound(v))
200 {
201 *out = v;
202 }
203 }
204};
205
206template <template <class> class Traverser, template <template <class> class, class> class Binder, class OutputIterator>
207find_free_variables_traverser<Traverser, Binder, OutputIterator>
208make_find_free_variables_traverser(OutputIterator out)
209{
210 return find_free_variables_traverser<Traverser, Binder, OutputIterator>(out);
211}
212
213template <template <class> class Traverser, template <template <class> class, class> class Binder, class OutputIterator, class VariableContainer>
214find_free_variables_traverser<Traverser, Binder, OutputIterator>
215make_find_free_variables_traverser(OutputIterator out, const VariableContainer& v)
216{
217 return find_free_variables_traverser<Traverser, Binder, OutputIterator>(out, v);
218}
219
220template <template <class> class Traverser>
221struct search_variable_traverser: public Traverser<search_variable_traverser<Traverser> >
222{
223 typedef Traverser<search_variable_traverser<Traverser> > super;
224 using super::enter;
225 using super::leave;
226 using super::apply;
227
228 bool found;
229 const variable& v;
230
231 explicit search_variable_traverser(const variable& v_)
232 : found(false), v(v_)
233 {}
234
235 void apply(const variable& x)
236 {
237 if (x == v)
238 {
239 found = true;
240 }
241 }
242};
243
244template <template <class> class Traverser>
245search_variable_traverser<Traverser>
246make_search_variable_traverser(const data::variable& v)
247{
248 return search_variable_traverser<Traverser>(v);
249}
250
251template <template <class> class Traverser, template <template <class> class, class> class Binder>
252struct search_free_variable_traverser: public Binder<Traverser, search_free_variable_traverser<Traverser, Binder> >
253{
254 typedef Binder<Traverser, search_free_variable_traverser<Traverser, Binder> > super;
255 using super::enter;
256 using super::leave;
257 using super::apply;
258 using super::is_bound;
259 using super::bound_variables;
260 using super::increase_bind_count;
261
262 bool found;
263 const data::variable& v;
264
265 explicit search_free_variable_traverser(const data::variable& v_)
266 : found(false), v(v_)
267 {}
268
269 void apply(const variable& x)
270 {
271 if (v == x && !is_bound(x))
272 {
273 found = true;
274 }
275 }
276};
277
278template <template <class> class Traverser, template <template <class> class, class> class Binder>
279search_free_variable_traverser<Traverser, Binder>
280make_search_free_variable_traverser(const data::variable& v)
281{
282 return search_free_variable_traverser<Traverser, Binder>(v);
283}
285
286} // namespace detail
287
288//--- start generated data find code ---//
293template <typename T, typename OutputIterator>
294void find_all_variables(const T& x, OutputIterator o)
295{
296 data::detail::make_find_all_variables_traverser<data::variable_traverser>(o).apply(x);
297}
298
302template <typename T>
303std::set<data::variable> find_all_variables(const T& x)
304{
305 std::set<data::variable> result;
306 data::find_all_variables(x, std::inserter(result, result.end()));
307 return result;
308}
309
314template <typename T, typename OutputIterator>
315void find_free_variables(const T& x, OutputIterator o)
316{
317 data::detail::make_find_free_variables_traverser<data::data_expression_traverser, data::add_data_variable_traverser_binding>(o).apply(x);
318}
319
325template <typename T, typename OutputIterator, typename VariableContainer>
326void find_free_variables_with_bound(const T& x, OutputIterator o, const VariableContainer& bound)
327{
328 data::detail::make_find_free_variables_traverser<data::data_expression_traverser, data::add_data_variable_traverser_binding>(o, bound).apply(x);
329}
330
334template <typename T>
335std::set<data::variable> find_free_variables(const T& x)
336{
337 std::set<data::variable> result;
338 data::find_free_variables(x, std::inserter(result, result.end()));
339 return result;
340}
341
346template <typename T, typename VariableContainer>
347std::set<data::variable> find_free_variables_with_bound(const T& x, VariableContainer const& bound)
348{
349 std::set<data::variable> result;
350 data::find_free_variables_with_bound(x, std::inserter(result, result.end()), bound);
351 return result;
352}
353
358template <typename T, typename OutputIterator>
359void find_identifiers(const T& x, OutputIterator o)
360{
361 data::detail::make_find_identifiers_traverser<data::identifier_string_traverser>(o).apply(x);
362}
363
367template <typename T>
368std::set<core::identifier_string> find_identifiers(const T& x)
369{
370 std::set<core::identifier_string> result;
371 data::find_identifiers(x, std::inserter(result, result.end()));
372 return result;
373}
374
379template <typename T, typename OutputIterator>
380void find_sort_expressions(const T& x, OutputIterator o)
381{
382 data::detail::make_find_sort_expressions_traverser<data::sort_expression_traverser>(o).apply(x);
383}
384
388template <typename T>
389std::set<data::sort_expression> find_sort_expressions(const T& x)
390{
391 std::set<data::sort_expression> result;
392 data::find_sort_expressions(x, std::inserter(result, result.end()));
393 return result;
394}
395
400template <typename T, typename OutputIterator>
401void find_function_symbols(const T& x, OutputIterator o)
402{
403 data::detail::make_find_function_symbols_traverser<data::data_expression_traverser>(o).apply(x);
404}
405
409template <typename T>
410std::set<data::function_symbol> find_function_symbols(const T& x)
411{
412 std::set<data::function_symbol> result;
413 data::find_function_symbols(x, std::inserter(result, result.end()));
414 return result;
415}
416//--- end generated data find code ---//
417
422template <typename T, typename OutputIterator>
423void find_data_expressions(const T& x, OutputIterator o)
424{
425 data::detail::make_find_data_expressions_traverser<data::data_expression_traverser>(o).apply(x);
426}
427
431template <typename T>
432std::set<data::data_expression> find_data_expressions(const T& x)
433{
434 std::set<data::data_expression> result;
435 data::find_data_expressions(x, std::inserter(result, result.end()));
436 return result;
437}
438
443template <typename T>
444bool search_variable(const T& x, const variable& v)
445{
446 data::detail::search_variable_traverser<data::variable_traverser> f(v);
447 f.apply(x);
448 return f.found;
449}
450
455template <typename T>
456bool search_free_variable(const T& x, const variable& v)
457{
458 data::detail::search_free_variable_traverser<data::data_expression_traverser, data::add_data_variable_traverser_binding> f(v);
459 f.apply(x);
460 return f.found;
461}
462
467template <typename Container>
468bool search_sort_expression(Container const& container, const sort_expression& s)
469{
470 std::set<data::sort_expression> sort_expressions = data::find_sort_expressions(container);
471 return sort_expressions.find(s) != sort_expressions.end();
472}
473
478template <typename Container>
479bool search_data_expression(Container const& container, const data_expression& s)
480{
481 std::set<data::data_expression> data_expressions = data::find_data_expressions(container);
482 return data_expressions.find(s) != data_expressions.end();
483}
484
485} // namespace data
486
487} // namespace mcrl2
488
489#endif // MCRL2_DATA_FIND_H
\brief A sort expression
\brief A data variable
Definition variable.h:28
add your file description here.
add your file description here.
Add your file description here.
void find_identifiers(const T &x, OutputIterator o)
Definition find.h:359
void find_free_variables_with_bound(const T &x, OutputIterator o, const VariableContainer &bound)
Definition find.h:326
bool search_data_expression(Container const &container, const data_expression &s)
Returns true if the term has a given data expression as subterm.
Definition find.h:479
std::set< data::variable > find_all_variables(const data::data_expression &x)
Definition data.cpp:94
bool search_free_variable(const T &x, const variable &v)
Returns true if the term has a given free variable as subterm.
Definition find.h:456
bool search_sort_expression(Container const &container, const sort_expression &s)
Returns true if the term has a given sort expression as subterm.
Definition find.h:468
std::set< data::sort_expression > find_sort_expressions(const data::data_equation &x)
Definition data.cpp:91
std::set< data::function_symbol > find_function_symbols(const data::data_equation &x)
Definition data.cpp:101
std::set< data::variable > find_free_variables(const data::data_expression &x)
Definition data.cpp:99
void find_data_expressions(const T &x, OutputIterator o)
Returns all data expressions that occur in an object.
Definition find.h:423
bool search_variable(const data::data_expression &x, const data::variable &v)
Definition data.cpp:103
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72