mCRL2
Loading...
Searching...
No Matches
anonymize.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_DATA_ANONYMIZE_H
13#define MCRL2_DATA_ANONYMIZE_H
14
16#include "mcrl2/data/builder.h"
18
19namespace mcrl2 {
20
21namespace data {
22
23namespace detail {
24
25template <typename Derived>
27{
29 using super::enter;
30 using super::leave;
31 using super::apply;
32 using super::update;
33
35 std::map<core::identifier_string, core::identifier_string> sort_name_substitution;
36 std::map<core::identifier_string, core::identifier_string> variable_name_substitution;
37 std::map<core::identifier_string, core::identifier_string> function_symbol_name_substitution;
38
39 Derived& derived()
40 {
41 return static_cast<Derived&>(*this);
42 }
43
44 void add_name(const core::identifier_string& name, std::map<core::identifier_string, core::identifier_string>& substitution, const std::string& hint)
45 {
47
48 // do not rename numeric values
49 if (std::isdigit(std::string(name)[0]))
50 {
51 substitution[name] = name;
52 }
53
54 if (!has_key(substitution, name))
55 {
56 substitution[name] = id_generator(hint);
57 }
58 }
59
61 const basic_sort_vector& user_defined_sorts,
62 const function_symbol_vector& user_defined_constructors,
63 const function_symbol_vector& user_defined_mappings,
64 const alias_vector& user_defined_aliases,
65 const data_equation_vector& user_defined_equations
66 )
67 {
68 data_specification result;
69 for (const auto& x: user_defined_sorts) { result.add_sort(x); }
70 for (const auto& x: user_defined_constructors) { result.add_constructor(x); }
71 for (const auto& x: user_defined_mappings) { result.add_mapping(x); }
72 for (const auto& x: user_defined_aliases) { result.add_alias(x); }
73 for (const auto& x: user_defined_equations) { result.add_equation(x); }
74 return result;
75 }
76
78 {
79 std::set<sort_expression> system_defined_sorts;
80 std::set<function_symbol> system_defined_constructors;
81 std::set<function_symbol> system_defined_mappings;
82 x.get_system_defined_sorts_constructors_and_mappings(system_defined_sorts, system_defined_constructors, system_defined_mappings);
83
84 // prevent system defined sorts from being renamed
85 for (const auto& s: system_defined_sorts)
86 {
87 if (is_basic_sort(s))
88 {
89 const auto& name = atermpp::down_cast<basic_sort>(s).name();
90 sort_name_substitution[name] = name;
91 }
92 }
93
94 // prevent system defined functions from being renamed
95 for (const auto& f: system_defined_constructors)
96 {
97 function_symbol_name_substitution[f.name()] = f.name();
98 }
99 for (const auto& f: system_defined_mappings)
100 {
101 function_symbol_name_substitution[f.name()] = f.name();
102 }
103
104 auto user_defined_sorts = x.user_defined_sorts();
105 auto user_defined_constructors = x.user_defined_constructors();
106 auto user_defined_mappings = x.user_defined_mappings();
107 auto user_defined_aliases = x.user_defined_aliases();
108 auto user_defined_equations = x.user_defined_equations();
109
110 derived().update(user_defined_sorts );
111 derived().update(user_defined_constructors);
112 derived().update(user_defined_mappings );
113 derived().update(user_defined_aliases );
114 derived().update(user_defined_equations );
116 user_defined_sorts ,
117 user_defined_constructors,
118 user_defined_mappings ,
119 user_defined_aliases ,
120 user_defined_equations
121 );
122 }
123
124 void enter(const variable& x)
125 {
127 }
128
129 template <class T>
130 void apply(T& result, const variable& x)
131 {
132 derived().enter(x);
133 sort_expression sort;
134 derived().apply(sort, x.sort());
136 derived().leave(x);
137 }
138
139 void enter(const function_symbol& x)
140 {
142 }
143
144 template <class T>
145 void apply(T& result, const function_symbol& x)
146 {
147 derived().enter(x);
148 sort_expression sort;
149 derived().apply(sort, x.sort());
151 derived().leave(x);
152 }
153
154 void enter(const basic_sort& x)
155 {
157 }
158
159 template <class T>
160 void apply(T& result, const basic_sort& x)
161 {
162 derived().enter(x);
164 derived().leave(x);
165 }
166
168 {
171 {
173 }
174 }
175
176 template <class T>
177 void apply(T& result, const structured_sort_constructor& x)
178 {
179 derived().enter(x);
181 derived().apply(arguments, x.arguments());
184 arguments,
186 derived().leave(x);
187 }
188
190 {
192 }
193
194 template <class T>
196 {
197 derived().enter(x);
198 sort_expression sort;
199 derived().apply(sort, x.sort());
201 derived().leave(x);
202 }
203
204 template <class T>
205 void apply(T& result, const alias& x)
206 {
207 derived().enter(x);
208 sort_expression sort;
209 derived().apply(sort, x.reference());
210 basic_sort name;
211 derived().apply(name, x.name());
212 make_alias(result, name, sort);
213 derived().leave(x);
214 }
215};
216
217struct anonymize_builder_instance: public anonymize_builder<anonymize_builder_instance>
218{
219};
220
221} // namespace detail
222
223inline
225{
227 f.update(dataspec);
228 std::cout << dataspec << std::endl;
229}
230
231} // namespace data
232
233} // namespace mcrl2
234
235#endif // MCRL2_DATA_ANONYMIZE_H
Term containing a string.
A list of aterm objects.
Definition aterm_list.h:24
\brief A sort alias
Definition alias.h:26
const basic_sort & name() const
Definition alias.h:52
const sort_expression & reference() const
Definition alias.h:57
\brief A basic sort
Definition basic_sort.h:26
const core::identifier_string & name() const
Definition basic_sort.h:57
const function_symbol_vector & user_defined_constructors() const
Gets the constructors defined by the user, excluding those that are system defined.
void add_mapping(const function_symbol &f)
Adds a mapping to this specification.
void add_equation(const data_equation &e)
Adds an equation to this specification.
const function_symbol_vector & user_defined_mappings() const
Gets all user defined mappings in this specification.
const data_equation_vector & user_defined_equations() const
Gets all user defined equations.
void add_constructor(const function_symbol &f)
Adds a constructor to this specification.
void get_system_defined_sorts_constructors_and_mappings(std::set< sort_expression > &sorts, std::set< function_symbol > &constructors, std::set< function_symbol > &mappings) const
This function provides a sample of all system defined sorts, constructors and mappings that contains ...
\brief A function symbol
const core::identifier_string & name() const
const sort_expression & sort() const
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A sort expression
const basic_sort_vector & user_defined_sorts() const
Gets all sorts defined by a user (excluding the system defined sorts).
void add_alias(const alias &a)
Adds an alias (new name for a sort) to this specification.
void add_sort(const basic_sort &s)
Adds a sort to this specification.
const alias_vector & user_defined_aliases() const
Gets the user defined aliases.
\brief An argument of a constructor of a structured sort
\brief A constructor for a structured sort
const core::identifier_string & name() const
const core::identifier_string & recogniser() const
const structured_sort_constructor_argument_list & arguments() const
\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
add your file description here.
add your file description here.
The class data_specification.
const aterm_string & empty_string()
Returns the empty aterm_string.
void make_function_symbol(atermpp::aterm &t, const ARGUMENTS &... args)
std::vector< alias > alias_vector
\brief vector of aliass
Definition alias.h:75
void make_basic_sort(atermpp::aterm &t, const ARGUMENTS &... args)
Definition basic_sort.h:66
void make_variable(atermpp::aterm &t, const ARGUMENTS &... args)
Definition variable.h:80
std::vector< data_equation > data_equation_vector
\brief vector of data_equations
void make_alias(atermpp::aterm &t, const ARGUMENTS &... args)
Definition alias.h:66
bool is_basic_sort(const atermpp::aterm &x)
Returns true if the term t is a basic sort.
void anonymize(data_specification &dataspec)
Definition anonymize.h:224
std::vector< basic_sort > basic_sort_vector
vector of basic sorts
Definition basic_sort.h:94
void make_structured_sort_constructor(atermpp::aterm &t, const ARGUMENTS &... args)
std::vector< function_symbol > function_symbol_vector
\brief vector of function_symbols
bool has_key(const std::map< Key, T > &c, const Key &v)
Returns the value corresponding to the given key in the set m. If the key is not present,...
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 data::variable &x)
Definition builder.h:55
void add_name(const core::identifier_string &name, std::map< core::identifier_string, core::identifier_string > &substitution, const std::string &hint)
Definition anonymize.h:44
void apply(T &result, const structured_sort_constructor &x)
Definition anonymize.h:177
std::map< core::identifier_string, core::identifier_string > variable_name_substitution
Definition anonymize.h:36
void enter(const basic_sort &x)
Definition anonymize.h:154
data::set_identifier_generator id_generator
Definition anonymize.h:34
void apply(T &result, const alias &x)
Definition anonymize.h:205
data::sort_expression_builder< Derived > super
Definition anonymize.h:28
data_specification make_data_specification(const basic_sort_vector &user_defined_sorts, const function_symbol_vector &user_defined_constructors, const function_symbol_vector &user_defined_mappings, const alias_vector &user_defined_aliases, const data_equation_vector &user_defined_equations)
Definition anonymize.h:60
void apply(T &result, const function_symbol &x)
Definition anonymize.h:145
std::map< core::identifier_string, core::identifier_string > sort_name_substitution
Definition anonymize.h:35
void apply(T &result, const structured_sort_constructor_argument &x)
Definition anonymize.h:195
void enter(const structured_sort_constructor &x)
Definition anonymize.h:167
void enter(const function_symbol &x)
Definition anonymize.h:139
void apply(T &result, const variable &x)
Definition anonymize.h:130
void apply(T &result, const basic_sort &x)
Definition anonymize.h:160
std::map< core::identifier_string, core::identifier_string > function_symbol_name_substitution
Definition anonymize.h:37
void enter(const structured_sort_constructor_argument &x)
Definition anonymize.h:189
void update(data_specification &x)
Definition anonymize.h:77
void enter(const variable &x)
Definition anonymize.h:124