mCRL2
Loading...
Searching...
No Matches
translate_user_notation.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_TRANSLATE_USER_NOTATION_H
13#define MCRL2_DATA_TRANSLATE_USER_NOTATION_H
14
15#include "mcrl2/data/builder.h"
18
19namespace mcrl2
20{
21
22namespace data
23{
24
25namespace detail
26{
27
28template <typename Derived>
30{
31public:
33
34 using super::enter;
35 using super::leave;
36 using super::apply;
37 using super::update;
38
39 inline
40 Derived& derived()
41 {
42 return static_cast<Derived&>(*this);
43 }
44
45 template <class T>
46 void apply(T& result, const abstraction& x)
47 {
48 const variable_list& bound_variables = x.variables();
49
51 {
52 sort_expression element_sort(x.variables().begin()->sort());
53 data_expression body;
54 derived().apply(body, x.body());
55 result = sort_set::constructor(element_sort, lambda(bound_variables, body),
56 sort_fset::empty(element_sort));
57 return;
58 }
59 else if (is_bag_comprehension(x))
60 {
61 sort_expression element_sort(x.variables().begin()->sort());
62 data_expression body;
63 derived().apply(body, x.body());
64 result = sort_bag::constructor(element_sort, lambda(bound_variables, body),
65 sort_fbag::empty(element_sort));
66 return;
67 }
68 data_expression body;
69 derived().apply(body, x.body());
70 result = abstraction(x.binding_operator(), bound_variables, body);
71 }
72
73 template <class T>
74 void apply(T& result, const function_symbol& x)
75 {
76 derived().enter(x);
77 const std::string& name(x.name());
78 if (is_system_defined(x.sort()) && (name.find_first_not_of("-/0123456789") == std::string::npos)) // crude but efficient
79 {
80 result = number(x.sort(), name);
81 }
82 else
83 {
84 result=x;
85 }
86 derived().leave(x);
87 }
88
89 template <class T>
90 void apply(T& result, const application& x)
91 {
92 derived().enter(x);
93 if (is_function_symbol(x.head()))
94 {
95 function_symbol head(x.head());
96
98 {
99 // convert to snoc list
100 sort_expression element_sort(*function_sort(head.sort()).domain().begin());
101
102 // result = sort_list::list(element_sort, derived().apply(data_expression_list(x.begin(), x.end())));
103 result = sort_list::list(element_sort,
105 x.begin(),
106 x.end(),
107 [&](const data_expression& t) { data_expression r; derived().apply(r, t); return r;} ));
108 return;
109 }
110 else if (head.name() == sort_set::set_enumeration_name())
111 {
112 // convert to finite set
113 sort_expression element_sort(*function_sort(head.sort()).domain().begin());
114 result = sort_fset::fset(element_sort,
116 x.begin(),
117 x.end(),
118 [&](const data_expression& t) { data_expression r; derived().apply(r, t); return r;} ));
119 return;
120 }
121 else if (head.name() == sort_bag::bag_enumeration_name())
122 {
123 // convert to finite bag
124 sort_expression element_sort(*function_sort(head.sort()).domain().begin());
125 result = sort_fbag::fbag(element_sort,
127 x.begin(),
128 x.end(),
129 [&](const data_expression& t) { data_expression r; derived().apply(r, t); return r;} ));
130 return;
131 }
132#ifdef MCRL2_ENABLE_MACHINENUMBERS
133 else if (head.name() == sort_nat::pos2nat_name())
134 {
135 // convert pos2nat(number) to a natural number.
137 derived().apply(n, x[0]);
138 assert(n.sort()==sort_pos::pos());
139 result=sort_nat::transform_positive_number_to_nat(n);
140 }
141#endif
142 }
143
144 make_application(result,
145 x.head(),
146 x.begin(),
147 x.end(),
148 [&](data_expression& r, const data_expression& t){ return derived().apply(r, t); }
149 );
150 derived().leave(x);
151 }
152};
153
155{
158
160 {
161 data_expression result;
162 core::make_apply_builder<translate_user_notation_builder>().apply(result, x);
163 return result;
164 }
165};
166
167} // namespace detail
168
169template <typename T>
171 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type* = 0
172 )
173{
174 core::make_update_apply_builder<data::data_expression_builder>(detail::translate_user_notation_function()).update(x);
175}
176
177template <typename T>
179 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
180 )
181{
182 T result;
183 core::make_update_apply_builder<data::data_expression_builder>(detail::translate_user_notation_function()).apply(result, x);
184 return result;
185}
186
187namespace detail
188{
189// added to avoid circular header problems in data_specification.h
190inline
192{
193 return translate_user_notation(x);
194}
195} // namespace detail
196
197} // namespace data
198
199} // namespace mcrl2
200
201#endif // MCRL2_DATA_TRANSLATE_USER_NOTATION_H
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
An abstraction expression.
Definition abstraction.h:26
const variable_list & variables() const
Definition abstraction.h:63
const data_expression & body() const
Definition abstraction.h:68
const binder_type & binding_operator() const
Definition abstraction.h:58
An application of a data expression to a number of arguments.
const_iterator end() const
Returns an iterator pointing past the last argument of the application.
const_iterator begin() const
Returns an iterator pointing to the first argument of the application.
const data_expression & head() const
Get the function at the head of this expression.
\brief A data equation
sort_expression sort() const
Returns the sort of the data expression.
Definition data.cpp:108
void apply(T &result, const function_symbol &x)
\brief A function sort
const sort_expression_list & domain() const
\brief A function symbol
const core::identifier_string & name() const
const sort_expression & sort() const
function symbol.
Definition lambda.h:27
\brief A sort expression
add your file description here.
data_equation translate_user_notation_data_equation(const data_equation &x)
core::identifier_string const & bag_enumeration_name()
Generate identifier bag_enumeration.
function_symbol constructor(const sort_expression &s)
Constructor for function symbol @bag.
Definition bag1.h:78
container_sort fbag(const sort_expression &s)
Constructor for sort expression FBag(S)
Definition fbag1.h:43
function_symbol empty(const sort_expression &s)
Constructor for function symbol {:}.
Definition fbag1.h:77
function_symbol empty(const sort_expression &s)
Constructor for function symbol {}.
Definition fset1.h:75
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Definition fset1.h:41
container_sort list(const sort_expression &s)
Constructor for sort expression List(S)
Definition list1.h:42
core::identifier_string const & list_enumeration_name()
Generate identifier list_enumeration.
const core::identifier_string & pos2nat_name()
Generate identifier Pos2Nat.
Definition nat1.h:290
const basic_sort & pos()
Constructor for sort expression Pos.
Definition pos1.h:45
core::identifier_string const & set_enumeration_name()
Generate identifier set_enumeration.
function_symbol constructor(const sort_expression &s)
Constructor for function symbol @set.
Definition set1.h:76
data_expression number(const sort_expression &s, const std::string &n)
Construct numeric expression from a string representing a number in decimal notation.
data::data_equation translate_user_notation(const data::data_equation &x)
Definition data.cpp:90
bool is_system_defined(const sort_expression &s)
Returns true iff the expression represents a standard sort.
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
atermpp::term_list< data_expression > data_expression_list
\brief list of data_expressions
bool is_bag_comprehension(const atermpp::aterm &x)
Returns true if the term t is a bag comprehension.
bool is_set_comprehension(const atermpp::aterm &x)
Returns true if the term t is a set comprehension.
void make_application(atermpp::aterm &result)
Make function for an application.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
Provides utilities for working with data expressions of standard container sorts.
Provides utilities for working with data expressions of standard sorts.
void apply(T &result, const data::variable &x)
Definition builder.h:443
data_expression operator()(const data_expression &x) const