mCRL2
Loading...
Searching...
No Matches
normalize_sorts.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_NORMALIZE_SORTS_H
13#define MCRL2_DATA_NORMALIZE_SORTS_H
14
15#include "mcrl2/data/builder.h"
17
18namespace mcrl2
19{
20
21namespace data
22{
23
24namespace detail
25{
26
28{
31
32 /* const sort_specification& m_sort_spec; */
33 const std::map< sort_expression, sort_expression >& m_normalised_aliases;
34
36 : m_normalised_aliases(sort_spec.sort_alias_map())
37 {
38 }
39
42 {
43 // This routine takes the map m_normalised_aliases which contains pairs of sort expressions
44 // <A,B> and takes all these pairs as rewrite rules, which are applied to e using an innermost
45 // strategy. Note that it is assumed that m_normalised_aliases contain rewrite rules <A,B>, such
46 // that B is a normal form. This allows to check that if e matches A, then we can return B.
47
48 const std::map< sort_expression, sort_expression >::const_iterator i1=m_normalised_aliases.find(e);
49 if (i1!=m_normalised_aliases.end())
50 {
51 return i1->second;
52 }
53
54 sort_expression new_sort=e; // This will be a placeholder for the sort of which all
55 // arguments will be normalised.
56
57 // We do not have to do anything if e is a basic sort, as new_sort=e.
58 if (is_function_sort(e))
59 {
60 // Rewrite the arguments into normal form.
61 std::vector< sort_expression > new_domain;
62 sort_expression_list e_domain(function_sort(e).domain());
63 for (const sort_expression& sort: e_domain)
64 {
65 new_domain.push_back(this->operator()(sort));
66 }
67 new_sort=function_sort(new_domain, this->operator()(function_sort(e).codomain()));
68 }
69 else if (is_container_sort(e))
70 {
71 // Rewrite the argument of the container sort to normal form.
72 new_sort=container_sort(
73 container_sort(e).container_name(),
74 this->operator()(container_sort(e).element_sort()));
75
76 }
77 else if (is_structured_sort(e))
78 {
79 // Rewrite the argument sorts to normal form.
80 std::vector< structured_sort_constructor > new_constructors;
81 const structured_sort_constructor_list& e_constructors(static_cast<const structured_sort&>(e).constructors());
82 for (const structured_sort_constructor& e_constructor: e_constructors)
83 {
84 std::vector<structured_sort_constructor_argument> new_arguments;
85 const structured_sort_constructor_argument_list& i_arguments(e_constructor.arguments());
86 for (const structured_sort_constructor_argument& i_argument : i_arguments)
87 {
88 new_arguments.push_back(structured_sort_constructor_argument(
89 i_argument.name(),
90 this->operator()(i_argument.sort())));
91 }
92 new_constructors.push_back(structured_sort_constructor(e_constructor.name(), new_arguments, e_constructor.recogniser()));
93 }
94 new_sort=structured_sort(new_constructors);
95 }
96
97 // The arguments of new_sort are now in normal form.
98 // Rewrite it to normal form.
99 const std::map< sort_expression, sort_expression >::const_iterator i2=m_normalised_aliases.find(new_sort);
100 if (i2!=m_normalised_aliases.end())
101 {
102 new_sort=this->operator()(i2->second); // rewrite the result until normal form.
103 }
104 return new_sort;
105 }
106
107};
108
109} // namespace detail
110
111
112template <typename T>
114 const data::sort_specification& sort_spec,
115 typename std::enable_if< !std::is_base_of<atermpp::aterm, T>::value >::type* = nullptr
116 )
117{
118 core::make_update_apply_builder<data::sort_expression_builder>
119 (data::detail::normalize_sorts_function(sort_spec)).update(x);
120}
121
122template <typename T>
123T normalize_sorts(const T& x,
124 const data::sort_specification& sort_spec,
125 typename std::enable_if< std::is_base_of<atermpp::aterm, T>::value >::type* = nullptr
126 )
127{
128 T result;
129 core::make_update_apply_builder<data::sort_expression_builder>
130 (data::detail::normalize_sorts_function(sort_spec)).apply(result, x);
131 return result;
132}
133
134/* The functions below are defined as the function normalize_sorts
135 above does not work on other sorts than sort expressions.
136
137inline sort_expression normalize_sorts(const basic_sort& x,
138 const data::sort_specification& sort_spec)
139{
140 return normalize_sorts(static_cast<sort_expression>(x),sort_spec);
141}
142
143inline sort_expression normalize_sorts(const function_sort& x,
144 const data::sort_specification& sort_spec)
145{
146 return normalize_sorts(static_cast<sort_expression>(x),sort_spec);
147}
148
149inline sort_expression normalize_sorts(const container_sort& x,
150 const data::sort_specification& sort_spec)
151{
152 return normalize_sorts(static_cast<sort_expression>(x),sort_spec);
153}
154
155inline sort_expression normalize_sorts(const structured_sort& x,
156 const data::sort_specification& sort_spec)
157{
158 return normalize_sorts(static_cast<sort_expression>(x),sort_spec);
159}
160*/
161
162} // namespace data
163
164} // namespace mcrl2
165
166#endif // MCRL2_DATA_NORMALIZE_SORTS_H
A list of aterm objects.
Definition aterm_list.h:24
\brief A container sort
\brief A function sort
\brief A sort expression
\brief An argument of a constructor of a structured sort
\brief A constructor for a structured sort
add your file description here.
bool is_structured_sort(const atermpp::aterm &x)
Returns true if the term t is a structured sort.
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
data_expression normalize_sorts(const data_expression &x, const data::sort_specification &sortspec)
Definition data.cpp:86
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
This file describes the a sort_specification,.
normalize_sorts_function(const sort_specification &sort_spec)
sort_expression operator()(const sort_expression &e) const
Normalise sorts.
const std::map< sort_expression, sort_expression > & m_normalised_aliases