12#ifndef MCRL2_DATA_EXPERIMENTAL_TYPE_CHECK_TREE_H
13#define MCRL2_DATA_EXPERIMENTAL_TYPE_CHECK_TREE_H
24typedef std::pair<sort_substitution, int>
solution;
41 return atermpp::down_cast<untyped_sort_variable>(x);
49 auto i =
sigma.find(v);
58template <
typename Container>
59std::string
print_node_vector(
const std::string& name,
const Container& nodes,
const std::string& sep =
", ",
const std::string& first =
"",
const std::string& last =
"")
61 std::vector<std::string> s;
62 for (
auto i = nodes.begin(); i != nodes.end(); ++i)
64 s.push_back((*i)->print());
66 std::ostringstream out;
67 out << name <<
"(" << first;
73template <
typename Container>
74std::string
print_vector(
const std::string& name,
const Container& nodes)
76 std::ostringstream out;
78 for (
auto i = nodes.begin(); i != nodes.end(); ++i)
80 if (i != nodes.begin())
90struct type_check_node;
118 std::pair<function_sort_list, function_sort_list>
find_matching_functions(
const std::string& name, std::size_t arity)
const;
148 if (i->second.size() <= 1)
154 i->second.pop_back();
170 std::vector<function_sort> result;
176 result.push_back(f1);
187struct type_check_constraint;
199 virtual std::string
print()
const = 0;
228 return "false(" +
message +
")";
256 if (
sorts.size() == 1)
267 auto const& domain1 = f1.
domain();
272 const function_sort& f2 = atermpp::down_cast<function_sort>(s2);
273 auto const& domain2 = f2.
domain();
274 if (domain1.size() != domain1.size())
278 std::vector<constraint_ptr> alternatives;
280 auto i1 = domain1.begin();
281 auto i2 = domain2.begin();
282 for (; i1 != domain1.end(); ++i1, ++i2)
297 if (std::find(sorts.begin(), sorts.end(),
untyped_sort()) != sorts.end())
303 const function_sort& f1 = atermpp::down_cast<function_sort>(s);
304 std::vector<constraint_ptr> alternatives;
311 if (std::find(sorts.begin(), sorts.end(), s) != sorts.end())
388 const container_sort& c1 = atermpp::down_cast<container_sort>(s1);
389 const container_sort& c2 = atermpp::down_cast<container_sort>(s2);
409 const function_sort& f1 = atermpp::down_cast<function_sort>(s1);
410 const function_sort& f2 = atermpp::down_cast<function_sort>(s2);
411 auto const& domain1 = f1.
domain();
412 auto const& domain2 = f2.
domain();
414 if (domain1.size() != domain1.size())
419 std::vector<constraint_ptr> alternatives;
421 auto i1 = domain1.begin();
422 auto i2 = domain2.begin();
423 for (; i1 != domain1.end(); ++i1, ++i2)
469 std::vector<constraint_ptr> result;
470 std::map<untyped_sort_variable, std::set<sort_expression> > is_element_of_constraints;
477 is_element_of_constraints[x_is_element_of->
s].insert(x_is_element_of->
sorts.begin(), x_is_element_of->
sorts.end());
484 for (
const auto& i: is_element_of_constraints)
508 std::vector<constraint_ptr> v;
558 std::vector<constraint_ptr> v;
614 child->apply_substitution(
sigma);
623 child->set_constraint(
context);
631 virtual std::string
print()
const = 0;
644 std::vector<constraint_ptr> alternatives;
648 if (variable_sorts.size() == 1)
667 if (alternatives.empty())
679 return "id(" +
value +
")";
709 return "number(" +
value +
")";
726 std::vector<constraint_ptr> alternatives;
737 return "constant(" +
name +
")";
805 std::vector<constraint_ptr> alternatives;
831 std::vector<constraint_ptr> alternatives;
833 for (std::size_t i = 0; i <
children.size(); i++)
864 std::vector<constraint_ptr> alternatives;
894 auto element_sort =
v.
sort();
937 for (
const auto& arg: arguments)
948 std::vector<constraint_ptr> alternatives;
949 std::vector<sort_expression> domain;
950 for (std::size_t i = 0; i <
arity; i++)
988 std::vector<constraint_ptr> alternatives;
1002 std::ostringstream out;
1003 out <<
"unary_operator(" <<
name <<
", " <<
children.front()->print() <<
")";
1027 std::ostringstream out;
1052 std::ostringstream out;
1077 std::ostringstream out;
1096 std::vector<constraint_ptr> alternatives;
1099 auto i = s.domain().begin();
1114 std::ostringstream out;
1115 out <<
"binary_operator(" <<
name <<
", " <<
children[0]->print() <<
", " <<
children[1]->print() <<
")";
1128 for (
const std::pair<std::string, type_check_node_ptr>& a: assignments)
1142 std::vector<constraint_ptr> constraints;
1155 std::ostringstream out;
1186 return parse_vector<std::pair<std::string, type_check_node_ptr> >(node,
"Assignment", [&](
const core::parse_node& node) {
return parse_Assignment(node); });
1245 system_result = i->second;
1250 user_result = { j->second };
1252 return std::make_pair(system_result, user_result);
1258 std::vector<function_sort> result;
1261 if (sort.domain().size() == arity)
1263 result.push_back(sort);
1295 system_result = i->second;
1300 user_result = j->second;
1308 std::vector<sort_expression> result;
1312 result.push_back(i->second.back());
1320 std::cout <<
"\nnode = " << node->print() << std::endl;
1321 std::cout <<
"sort = " << node->sort << std::endl;
1322 std::cout <<
"constraint = " << node->constraint->print() << std::endl;
Term containing a string.
const container_type & container_name() const
const sort_expression & element_sort() const
const sort_expression & codomain() const
const sort_expression_list & domain() const
const std::map< core::identifier_string, sort_expression > & user_constants() const
const std::map< core::identifier_string, sort_expression_list > & system_constants() const
const std::map< core::identifier_string, function_sort_list > & user_functions() const
const std::map< core::identifier_string, function_sort_list > & system_functions() const
\brief Untyped sort variable
\brief Unknown sort expression
const core::identifier_string & name() const
const sort_expression & sort() const
Standard exception class for reporting runtime errors.
Parser for data specifications.
add your file description here.
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
std::string print_set(const Container &v, const std::string &message="", bool print_index=false, bool boundary_spaces=true)
Creates a string representation of a container.
bool is_nat(const core::identifier_string &Number)
bool is_pos(const core::identifier_string &Number)
container_sort bag(const sort_expression &s)
Constructor for sort expression Bag(S)
bool is_bool(const sort_expression &e)
Recogniser for sort expression Bool.
const basic_sort & bool_()
Constructor for sort expression Bool.
bool is_int(const sort_expression &e)
Recogniser for sort expression Int.
const basic_sort & int_()
Constructor for sort expression Int.
container_sort list(const sort_expression &s)
Constructor for sort expression List(S)
const basic_sort & nat()
Constructor for sort expression Nat.
bool is_nat(const sort_expression &e)
Recogniser for sort expression Nat.
bool is_pos(const sort_expression &e)
Recogniser for sort expression Pos.
const basic_sort & pos()
Constructor for sort expression Pos.
const basic_sort & real_()
Constructor for sort expression Real.
bool is_real(const sort_expression &e)
Recogniser for sort expression Real.
container_sort set_(const sort_expression &s)
Constructor for sort expression Set(S)
atermpp::term_list< function_sort > function_sort_list
list of function sorts
const untyped_sort_variable & make_untyped_sort_variable(const sort_expression &x)
std::pair< sort_substitution, int > solution
bool has_untyped_sort(const T &x)
constraint_ptr substitute_constraint(constraint_ptr p, const sort_substitution &sigma)
constraint_ptr make_is_element_of_constraint(const sort_expression &s, const std::vector< sort_expression > &sorts, int cost=0)
bool is_untyped_sort(const atermpp::aterm &x)
Returns true if the term t is the unknown sort.
sort_expression substitute(const sort_expression &x, const sort_substitution &sigma)
void print_node(const type_check_node_ptr &node)
constraint_ptr make_true_constraint(int cost=0)
T replace_untyped_sort(const T &x, const sort_expression &replacement)
std::string print_node_vector(const std::string &name, const Container &nodes, const std::string &sep=", ", const std::string &first="", const std::string &last="")
constraint_ptr make_subsort_constraint(const sort_expression &s1, const sort_expression &s2, int cost=0)
atermpp::term_list< sort_expression > sort_expression_list
\brief list of sort_expressions
std::map< untyped_sort_variable, sort_expression > sort_substitution
std::string pp(const abstraction &x)
void replace_sort_expressions(T &x, const Substitution &sigma, bool innermost, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
bool search_sort_expression(Container const &container, const sort_expression &s)
Returns true if the term has a given sort expression as subterm.
constraint_ptr make_false_constraint(const std::string &message)
constraint_ptr make_or_constraint(const std::vector< constraint_ptr > &alternatives)
std::shared_ptr< type_check_node > type_check_node_ptr
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
function_sort_list filter_sorts(const function_sort_list &sorts, std::size_t arity)
constraint_ptr make_and_constraint(const std::vector< constraint_ptr > &alternatives)
bool is_untyped_sort_variable(const atermpp::aterm &x)
constraint_ptr make_is_equal_to_constraint(const sort_expression &s1, const sort_expression &s2, int cost=0)
std::string print_vector(const std::string &name, const Container &nodes)
constraint_ptr make_function_sort_constraint(const function_sort &f1, const sort_expression &s2)
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
std::vector< constraint_ptr > join_or_is_element_of_constraints(const std::vector< constraint_ptr > &constraints)
std::shared_ptr< type_check_constraint > constraint_ptr
std::string string_join(const Container &c, const std::string &separator)
Joins a sequence of strings. This is a replacement for boost::algorithm::join, since it gives stack o...
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
core::identifier_string parse_Id(const parse_node &node) const
core::identifier_string parse_Number(const parse_node &node) const
parse_node child(int i) const
std::string string() const
std::string symbol_name(const parse_node &node) const
Wrapper for D_Parser and its corresponding D_ParserTables.
std::string print() const override
and_constraint(const std::vector< constraint_ptr > &alternatives_)
std::vector< constraint_ptr > alternatives
void set_constraint(type_check_context &context) override
application_node(type_check_context &context, type_check_node_ptr head, const std::vector< type_check_node_ptr > &arguments)
std::string print() const override
std::string print() const override
void set_constraint(type_check_context &context) override
bag_enumeration_node(type_check_context &context, const std::vector< type_check_node_ptr > &children)
std::string print() const override
void set_constraint(type_check_context &context) override
bag_or_set_enumeration_node(type_check_context &context, const variable &v_, type_check_node_ptr x)
void set_constraint(type_check_context &context) override
binary_operator_node(type_check_context &context, const std::string &name_, type_check_node_ptr left, type_check_node_ptr right)
std::string print() const override
constant_node(type_check_context &context, const std::string &name_)
std::string print() const override
void set_constraint(type_check_context &context) override
data::variable_list parse_VarsDeclList(const core::parse_node &node) const
data_expression_actions(const core::parser &parser_)
data::variable parse_VarDecl(const core::parse_node &node) const
empty_bag_node(type_check_context &context)
void set_constraint(type_check_context &context) override
void set_constraint(type_check_context &context) override
empty_list_node(type_check_context &context)
empty_set_node(type_check_context &context)
void set_constraint(type_check_context &context) override
std::string print() const override
void set_constraint(type_check_context &context) override
exists_node(type_check_context &context, const variable_list &variables_, type_check_node_ptr arg)
std::string print() const override
false_constraint(const std::string &message_)
false_node(type_check_context &context)
forall_node(type_check_context &context, const variable_list &variables_, type_check_node_ptr arg)
std::string print() const override
void set_constraint(type_check_context &context) override
function_update_node(type_check_context &context, type_check_node_ptr x1, type_check_node_ptr x2, type_check_node_ptr x3)
std::string print() const override
id_node(type_check_context &context, const std::string &value_)
std::string print() const override
void set_constraint(type_check_context &context) override
std::string print() const override
std::vector< sort_expression > sorts
is_element_of_constraint(const untyped_sort_variable &s_, const std::vector< sort_expression > &sorts_, int cost=0)
is_equal_to_constraint(const untyped_sort_variable &s1_, const sort_expression &s2_, int cost=0)
std::string print() const override
void set_constraint(type_check_context &context) override
std::string print() const override
lambda_node(type_check_context &context, const variable_list &variables_, type_check_node_ptr arg)
list_enumeration_node(type_check_context &context, const std::vector< type_check_node_ptr > &children)
void set_constraint(type_check_context &context) override
std::string print() const override
void set_constraint(type_check_context &) override
number_node(type_check_context &context, const std::string &value_)
std::string print() const override
std::string print() const
or_constraint(const std::vector< constraint_ptr > &alternatives_)
std::vector< constraint_ptr > alternatives
std::string print() const override
set_enumeration_node(type_check_context &context, const std::vector< type_check_node_ptr > &children)
void set_constraint(type_check_context &context) override
subsort_constraint(const sort_expression &s1_, const sort_expression &s2_, int cost=0)
std::string print() const override
std::string print() const override
true_constraint(int cost=0)
true_node(type_check_context &context)
virtual std::string print() const =0
type_check_constraint(int cost_=0)
void add_context_variable(const variable &v)
std::map< core::identifier_string, std::vector< sort_expression > > declared_variables
void remove_context_variables(const variable_list &variables)
void add_context_variables(const variable_list &variables)
std::pair< sort_expression_list, sort_expression_list > find_matching_constants(const std::string &name) const
std::map< core::identifier_string, sort_expression > user_constants
void remove_context_variable(const variable &v)
std::vector< sort_expression > find_matching_variables(const std::string &name) const
std::size_t sort_variable_index
function_sort_list replace_untyped_sorts(const function_sort_list &sorts) const
untyped_sort_variable create_sort_variable() const
std::pair< function_sort_list, function_sort_list > find_matching_functions(const std::string &name, std::size_t arity) const
std::map< core::identifier_string, function_sort_list > user_functions
type_check_context(const data::data_specification &dataspec=data::data_specification())
std::map< core::identifier_string, sort_expression_list > system_constants
std::map< core::identifier_string, function_sort_list > system_functions
virtual void set_constraint(type_check_context &)
std::vector< type_check_node_ptr > children
virtual std::string print() const =0
untyped_sort_variable sort
constraint_ptr constraint
virtual void apply_substitution(const sort_substitution &sigma)
virtual ~type_check_node()
virtual void check_well_typedness(const type_check_context &)
void set_children_constraints(type_check_context &context)
type_check_context & context
type_check_node(type_check_context &context_, const std::vector< type_check_node_ptr > &children_)
type_check_context & context
type_check_node_ptr parse_DataExpr(const core::parse_node &node) const
std::vector< std::pair< std::string, type_check_node_ptr > > parse_AssignmentList(const core::parse_node &node) const
type_check_tree_generator(type_check_context &context_, const core::parser &parser_)
std::vector< type_check_node_ptr > parse_DataExprList(const core::parse_node &node) const
std::pair< std::string, type_check_node_ptr > parse_Assignment(const core::parse_node &node) const
std::vector< type_check_node_ptr > parse_BagEnumEltList(const core::parse_node &node) const
virtual ~unary_operator_node()
unary_operator_node(type_check_context &context, const std::string &name_, type_check_node_ptr arg)
std::string print() const override
void set_constraint(type_check_context &context) override
std::vector< variable > variables
where_clause_node(type_check_context &context, type_check_node_ptr body, const std::vector< std::pair< std::string, type_check_node_ptr > > &assignments)
std::string print() const override
void set_constraint(type_check_context &context) override
add your file description here.