mCRL2
Loading...
Searching...
No Matches
data_utility.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_DETAIL_DATA_UTILITY_H
13#define MCRL2_DATA_DETAIL_DATA_UTILITY_H
14
15#include "mcrl2/data/alias.h"
20
21namespace mcrl2
22{
23
24namespace data
25{
26
27namespace detail
28{
29
31template <typename Container>
32data::sort_expression_list parameter_sorts(const Container& parameters)
33{
35 for (auto const& param: parameters)
36 {
37 sorts.push_front(param.sort());
38 }
39 return atermpp::reverse(sorts);
40}
41
45template <class VariableContainer>
46inline
47bool unique_names(const VariableContainer& variables)
48{
49 std::set<core::identifier_string> variable_names;
50 for (auto const& var: variables)
51 {
52 variable_names.insert(var.name());
53 }
54 return variable_names.size() == variables.size();
55}
56
61inline
62bool check_assignment_variables(assignment_list const& assignments, variable_list const& variables)
63{
65
66 std::set<variable> v(variables.begin(), variables.end());
67 for (const assignment& a: assignments)
68 {
69 if (!contains(v, a.lhs()))
70 {
71 return false;
72 }
73 }
74 return true;
75}
76
81template <typename SortContainer>
82inline bool check_sort(const sort_expression& s, const SortContainer& sorts)
83{
85
86 std::set<sort_expression> s_sorts = data::find_sort_expressions(s);
87 remove_if(s_sorts, [](const sort_expression& x) { return !is_function_sort(x); });
88 for (const sort_expression& sort: s_sorts)
89 {
90 if (std::find(sorts.begin(), sorts.end(), sort) == sorts.end())
91 {
92 // sort *i is not well-typed, a system defined sort or an alias
93 if (!(is_system_defined(sort)) && is_alias(sort))
94 {
95 alias sort_alias(sort);
96
97 if (std::find(sorts.begin(), sorts.end(), sort_alias.name()) == sorts.end())
98 {
99 // sort_alias.reference() is a basic, structured or container sort
100 const sort_expression& sort_reference(sort_alias.reference());
101
102 if (std::find(sorts.begin(), sorts.end(), sort_reference) == sorts.end())
103 {
104 // sort_reference is structured or container sort
105 if (is_structured_sort(sort_reference))
106 {
107 assert(false);
108 }
109 else if (is_container_sort(sort_reference))
110 {
111 if (std::find(sorts.begin(), sorts.end(), container_sort(sort_reference).element_sort()) == sorts.end())
112 {
113 return false;
114 }
115 }
116 else
117 {
118 assert(false);
119 }
120 }
121 }
122 }
123 }
124 }
125
126 return true;
127}
128
135template <typename Iterator, typename SortContainer>
136bool check_sorts(Iterator first, Iterator last, const SortContainer& sorts)
137{
138 for (Iterator i = first; i != last; ++i)
139 {
140 if (!check_sort(*i, sorts))
141 {
142 return false;
143 }
144 }
145 return true;
146}
147
152template <typename VariableContainer, typename SortContainer>
153bool check_variable_sorts(const VariableContainer& variables, const SortContainer& sorts)
154{
155 for (typename VariableContainer::const_iterator i = variables.begin(); i != variables.end(); ++i)
156 {
157 if (!check_sort(i->sort(), sorts))
158 {
159 return false;
160 }
161 }
162 return true;
163}
164
169inline
170bool check_variable_names(variable_list const& variables, const std::set<core::identifier_string>& names)
171{
173
174 for (const variable& v: variables)
175 {
176 if (contains(names, v.name()))
177 {
178 return false;
179 }
180 }
181 return true;
182}
183
188template < typename Container, typename SortContainer >
189inline
190bool check_data_spec_sorts(const Container& container, const SortContainer& sorts)
191{
192 for (typename Container::const_iterator i = container.begin(); i != container.end(); ++i)
193 {
194 if (!check_sort(i->sort(), sorts))
195 {
196 return false;
197 }
198 }
199 return true;
200}
201
202} // namespace detail
203
204} // namespace data
205
206} // namespace mcrl2
207
208#endif // MCRL2_DATA_DETAIL_DATA_UTILITY_H
The class alias.
The class assignment.
A list of aterm objects.
Definition aterm_list.h:24
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
void push_front(const Term &el)
Inserts a new element at the beginning of the current list.
\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 Assignment of a data expression to a variable
Definition assignment.h:91
\brief A container sort
\brief A sort expression
\brief A data variable
Definition variable.h:28
Add your file description here.
term_list< Term > reverse(const term_list< Term > &l)
Returns the list with the elements in reversed order.
bool check_variable_sorts(const VariableContainer &variables, const SortContainer &sorts)
Returns true if the domain sorts and the range sort of the given variables are contained in sorts.
bool check_variable_names(variable_list const &variables, const std::set< core::identifier_string > &names)
Returns true if names of the given variables are not contained in names.
bool check_assignment_variables(assignment_list const &assignments, variable_list const &variables)
Returns true if the left hand sides of assignments are contained in variables.
bool check_sort(const sort_expression &s, const SortContainer &sorts)
Returns true if the domain sorts and the codomain sort of the given sort s are contained in sorts.
bool check_data_spec_sorts(const Container &container, const SortContainer &sorts)
Returns true if the domain sorts and range sort of the given functions are contained in sorts.
data::sort_expression_list parameter_sorts(const Container &parameters)
Returns the sorts of a sequence of parameters.
std::set< core::identifier_string > variable_names(const std::set< data::variable > &variables)
Returns the names of a set of data variables.
Definition find.h:26
bool check_sorts(Iterator first, Iterator last, const SortContainer &sorts)
Returns true if the domain sorts and the range sort of the sorts in the sequence [first,...
bool unique_names(const VariableContainer &variables)
Returns true if the names of the given variables are unique.
bool is_structured_sort(const atermpp::aterm &x)
Returns true if the term t is a structured sort.
bool is_system_defined(const sort_expression &s)
Returns true iff the expression represents a standard sort.
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
std::set< data::sort_expression > find_sort_expressions(const data::data_equation &x)
Definition data.cpp:91
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
bool is_alias(const atermpp::aterm &x)
Definition alias.h:81
bool contains(const atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable > &c, const typename atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable >::key_type &v, const std::size_t thread_index=0)
Definition indexed_set.h:86
void remove_if(ContainerT &items, const PredicateT &predicate)
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 sorts.