mCRL2
Loading...
Searching...
No Matches
sort_specification.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
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// which contains declared sorts and sort aliases.
12
13#ifndef MCRL2_DATA_SORT_SPECIFICATION_H
14#define MCRL2_DATA_SORT_SPECIFICATION_H
15
16#include "mcrl2/data/alias.h"
18
19namespace mcrl2
20{
21namespace data
22{
23
25namespace detail
26{
27
28 template < typename Container, typename T >
29 inline
30 void remove(Container& container, const T& t)
31 {
32 typename Container::iterator i = std::find(container.begin(), container.end(), t);
33 if(i != container.end())
34 {
35 container.erase(i);
36 }
37 }
38
39} // end namespace detail
41
42class sort_specification;
43sort_expression normalize_sorts(const sort_expression& x, const data::sort_specification& sortspec);
44
46{
47 protected:
48
53
59
62
64 mutable std::set<sort_expression> m_normalised_sorts;
65
71 std::set< sort_expression > m_sorts_in_context;
72
75
77 mutable std::map< sort_expression, sort_expression > m_normalised_aliases;
78
79 public:
80
85 {
87 }
88
92 {
94
95 for(const basic_sort& sort: sorts)
96 {
97 add_sort(sort);
98 }
99 for(const alias& a: aliases)
100 {
101 add_alias(a);
102 }
103 }
104
105
108 void add_sort(const basic_sort& s)
109 {
110 if (std::find(m_user_defined_sorts.begin(),m_user_defined_sorts.end(),s)==m_user_defined_sorts.end())
111 {
112 m_user_defined_sorts.push_back(s);
115 }
116 }
117
126 {
128 }
129
136 {
139 }
140
146 template <typename Container>
147 void add_context_sorts(const Container& c, typename atermpp::enable_if_container<Container>::type* = nullptr)
148 {
149 for(typename Container::const_iterator i=c.begin(); i!=c.end(); ++i)
150 {
152 }
153 }
154
162 {
163 detail::remove(m_user_defined_sorts,s);
165 }
166
179 inline
180 const std::set<sort_expression>& sorts() const
181 {
183 return m_normalised_sorts;
184 }
185
189 const std::set<sort_expression>& context_sorts() const
190 {
191 return m_sorts_in_context;
192 }
193
198 inline
200 {
202 }
203
206 void add_alias(const alias& a)
207 {
208 if (std::find(m_user_defined_aliases.begin(),m_user_defined_aliases.end(),a)==m_user_defined_aliases.end())
209 {
210 m_user_defined_aliases.push_back(a);
214 }
215 }
216
217
221 void remove_alias(const alias& a)
222 {
223 detail::remove(m_user_defined_sorts, a.name());
224 detail::remove(m_user_defined_aliases, a);
226 }
227
228
231 inline
233 {
235 }
236
237
245 const std::map< sort_expression, sort_expression >& sort_alias_map() const
246 {
249 }
250
251 bool operator==(const sort_specification& other) const
252 {
256 }
257
258 // Below are auxiliary functions for this class.
259 protected:
261 {
264 }
265
267 {
269 }
270
272 {
274 {
276 m_normalised_sorts.clear();
278 for (const sort_expression& s: m_sorts_in_context)
279 {
280 m_normalised_sorts.insert(normalize_sorts(s,*this));
281 }
283 {
284 m_normalised_sorts.insert(normalize_sorts(s,*this));
285 }
287 }
288 }
289
291
292 template <class CONTAINER>
293 void import_system_defined_sorts(const CONTAINER& sorts)
294 {
295 for(const sort_expression& sort: sorts)
296 {
298 }
299 }
300
309
310 // The function below recalculates m_normalised_aliases, such that
311 // it forms a confluent terminating rewriting system using which
312 // sorts can be normalised.
314
315 // The function below checks whether there is an alias loop, e.g. aliases
316 // of the form A=B; B=A; or more complex A=B->C; B=Set(D); D=List(A); Loops
317 // through structured sorts are allowed. If a loop is detected, an exception
318 // is thrown.
320 const sort_expression& s,
321 std::set<sort_expression> sorts_already_seen,
322 const bool toplevel=true) const;
323
324
325}
326;
327
328} // namespace data
329
330} // namespace mcrl2
331
332#endif // MCRL2_DATA_SORT_SPECIFICATION_H
The class alias.
\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
\brief A sort expression
std::map< sort_expression, sort_expression > m_normalised_aliases
Table containing how sorts should be mapped to normalised sorts.
const std::set< sort_expression > & context_sorts() const
Return the user defined context sorts of the current specification.
void remove_sort(const sort_expression &s)
Removes sort from the user defined sorts in the specification. Note that this does not remove aliases...
void add_system_defined_sort(const sort_expression &s)
Adds a sort to this specification, and marks it as system defined.
basic_sort_vector m_user_defined_sorts
The basic sorts and structured sorts in the specification.
bool operator==(const sort_specification &other) const
std::set< sort_expression > m_sorts_in_context
The sorts that occur are needed in this sort specification but are not explicitly defined as user def...
const std::map< sort_expression, sort_expression > & sort_alias_map() const
Gets a normalisation mapping that maps each sort to its unique normalised sort.
const std::set< sort_expression > & sorts() const
Gets the normalised sort declarations including those that are system defined. This is the set with a...
void add_context_sorts(const Container &c, typename atermpp::enable_if_container< Container >::type *=nullptr)
Adds the sorts in c to the context sorts.
const basic_sort_vector & user_defined_sorts() const
Gets all sorts defined by a user (excluding the system defined sorts).
bool m_normalised_data_is_up_to_date
The variable below indicates whether a surrounding data specification is up to data with respect to s...
alias_vector m_user_defined_aliases
The basic sorts and structured sorts in the specification.
sort_specification()
Default constructor.
void sorts_are_not_necessarily_normalised_anymore() const
void data_is_not_necessarily_normalised_anymore() const
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.
sort_specification(const basic_sort_vector &sorts, const alias_vector &aliases)
std::set< sort_expression > m_normalised_sorts
Set containing all the sorts, including the system defined ones.
void remove_alias(const alias &a)
Removes a user defined //alias from specification.
void add_context_sort(const sort_expression &s)
Adds the sort s to the context sorts.
void check_for_alias_loop(const sort_expression &s, std::set< sort_expression > sorts_already_seen, const bool toplevel=true) const
void import_system_defined_sorts(const CONTAINER &sorts)
const alias_vector & user_defined_aliases() const
Gets the user defined aliases.
bool m_normalised_sorts_are_up_to_date
This boolean indicates whether the variables m_normalised_constructors, m_mappings,...
void import_system_defined_sort(const sort_expression &sort)
Adds the system defined sorts in a sequence. The second argument is used to check which sorts are add...
std::vector< alias > alias_vector
\brief vector of aliass
Definition alias.h:75
data_expression normalize_sorts(const data_expression &x, const data::sort_specification &sortspec)
Definition data.cpp:86
std::vector< basic_sort > basic_sort_vector
vector of basic sorts
Definition basic_sort.h:94
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
The class structured_sort.