9#include "mcrl2/atermpp/aterm_list.h"
10#include "mcrl2/data/assignment.h"
11#include "mcrl2/data/data_expression.h"
12#include "mcrl2/data/print.h"
13#include "mcrl2/data/sort_expression.h"
14#include "mcrl2/data/typecheck.h"
16using namespace mcrl2::log;
18using namespace mcrl2::
data;
30 typechecker
(v
, *
this);
35static bool includes(
const std::set<variable>& s1,
const std::set<variable>& s2,
variable& culprit)
37 for(
const variable& v: s1)
48static inline bool IsPos(
const core::identifier_string& Number)
50 char c=Number.function().name()[0];
51 return isdigit(c) && c>
'0';
53static inline bool IsNat(
const core::identifier_string& Number)
55 return isdigit(Number.function().name()[0]) != 0;
58static sort_expression_list
GetVarTypes(variable_list VarDecls);
68 if (std::find(list.begin(),list.end(), el) == list.end())
71 result.push_front(el);
92 assert(abstr.variables().size()>0);
112 for (
const assignment_expression& WhereElem : where_asss)
114 const assignment& t = down_cast<
const assignment>(WhereElem);
115 strict_type_check(t.rhs());
123 const application& appl=down_cast<application>(d);
135 for (
const data_expression& i: appl)
137 strict_type_check(i);
138 assert(i.sort()==s1);
149 for (
const data_expression& i: appl)
151 strict_type_check(i);
152 assert(i.sort()==s1);
163 for (application::const_iterator i=appl.begin(); i!=appl.end(); ++i)
165 strict_type_check(*i);
166 assert(i->sort()==s1);
169 strict_type_check(*i);
170 assert(i->sort()==sort_nat::nat());
181 sort_expression_list argument_sorts=function_sort(s).domain();
182 assert(appl.size()==argument_sorts.size());
183 application::const_iterator j=appl.begin();
184 for(sort_expression_list::const_iterator i=argument_sorts.begin(); i!=argument_sorts.end(); ++i,++j)
186 assert(UnwindType(j->sort())==UnwindType(*i));
187 strict_type_check(*j);
206 const bool strictly_ambiguous,
208 const bool print_cast_error)
const
235 const sort_expression_list& l=mps
.sorts();
236 for (
const sort_expression& i : l)
238 bool found_solution=
true;
242 r = UpCastNumericType(i, Type, Par, DeclaredVars, strictly_ambiguous, warn_upcasting, print_cast_error);
244 catch (mcrl2::runtime_error&)
246 found_solution=
false;
253 throw mcrl2::runtime_error(
"Cannot transform " + data::pp(Type) +
" to a number.");
256 if (warn_upcasting && data::is_function_symbol(Par) && utilities::is_numeric_string(down_cast<function_symbol>(Par).name().function().name()))
258 warn_upcasting=
false;
277#ifdef MCRL2_ENABLE_MACHINENUMBERS
278 Par=sort_nat::transform_positive_number_to_nat(Par);
285 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Nat by applying Pos2Nat to it." << std::endl;
301#ifdef MCRL2_ENABLE_MACHINENUMBERS
302 Par=application(sort_int::cint(),sort_nat::transform_positive_number_to_nat(Par));
309 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Int by applying Pos2Int to it." << std::endl;
320 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Int by applying Nat2Int to it." << std::endl;
336#ifdef MCRL2_ENABLE_MACHINENUMBERS
337 Par=application(sort_real::creal(),
338 application(sort_int::cint(), sort_nat::transform_positive_number_to_nat(Par)),
348 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Real by applying Pos2Real to it." << std::endl;
361 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Real by applying Nat2Real to it." << std::endl;
372 mCRL2log(log_level_t::warning) <<
"Upcasting " << OldPar <<
" to sort Real by applying Int2Real to it." << std::endl;
391 needed_argument_type
=argument_type;
394 if (needed_similar_container_type==NeededType)
396 throw mcrl2::runtime_error(
"Cannot typecast " + data::pp(Type) +
" into " + data::pp(NeededType) +
" for data expression " + data::pp(Par) +
".");
401 needed_similar_container_type
,strictly_ambiguous
,warn_upcasting
,print_cast_error
);
405 catch (mcrl2::runtime_error& e)
407 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while trying to match argument types of " + data::pp(NeededType) +
" and " +
408 data::pp(Type) +
" in data expression " + data::pp(Par) +
".");
424 if (Type==NeededType)
430 throw mcrl2::runtime_error(
"Upcasting " + data::pp(Type) +
" to " + data::pp(NeededType) +
" fails (1).");
446 if (Type==NeededType)
452 throw mcrl2::runtime_error(
"Upcasting " + data::pp(Type) +
" to " + data::pp(NeededType) +
" fails (1).");
465 assert(needed_function_type.domain().size()==1);
466 Par=sort_set::false_function(needed_function_type.domain().front());
471 assert(needed_function_type.domain().size()==1);
472 Par=sort_bag::zero_function(needed_function_type.domain().front());
478 throw mcrl2::runtime_error(
"Upcasting " + data::pp(Type) +
" to " + data::pp(NeededType) +
" fails (3).");
500 sort_expression_list NewPosTypes;
504 for (sort_expression_list PosTypes=mps.sorts(); !PosTypes.empty(); PosTypes=PosTypes.tail())
506 sort_expression NewPosType=PosTypes.front();
507 if (is_basic_sort(NewPosType))
509 NewPosType=UnwindType(NewPosType);
511 if (sort_fset::is_fset(sort_expression(NewPosType))|| (sort_set::is_set(sort_expression(NewPosType))))
513 NewPosType=down_cast<
const container_sort>(NewPosType).element_sort();
515 else if (!data::is_untyped_sort(data::sort_expression(NewPosType)))
519 NewPosTypes.push_front(NewPosType);
521 NewPosTypes=reverse(NewPosTypes);
522 result=untyped_possible_sorts(sort_expression_list(NewPosTypes));
546 sort_expression_list NewPosTypes;
550 for (sort_expression_list PosTypes=mps.sorts(); !PosTypes.empty(); PosTypes=PosTypes.tail())
552 sort_expression NewPosType=PosTypes.front();
553 if (is_basic_sort(NewPosType))
555 NewPosType=UnwindType(NewPosType);
557 if (sort_fbag::is_fbag(sort_expression(NewPosType))|| (sort_fbag::is_fbag(sort_expression(NewPosType))))
559 NewPosType=down_cast<
const container_sort>(NewPosType).element_sort();
561 else if (!data::is_untyped_sort(data::sort_expression(NewPosType)))
565 NewPosTypes.push_front(NewPosType);
567 NewPosTypes=reverse(NewPosTypes);
568 result=untyped_possible_sorts(sort_expression_list(NewPosTypes));
592 sort_expression_list NewPosTypes;
596 for (sort_expression_list PosTypes=mps.sorts(); !PosTypes.empty(); PosTypes=PosTypes.tail())
598 sort_expression NewPosType=PosTypes.front();
599 if (is_basic_sort(NewPosType))
601 NewPosType=UnwindType(NewPosType);
603 if (sort_list::is_list(NewPosType))
605 NewPosType=down_cast<
const container_sort>(NewPosType).element_sort();
607 else if (!data::is_untyped_sort(NewPosType))
611 NewPosTypes.push_front(NewPosType);
613 NewPosTypes=reverse(NewPosTypes);
614 result=untyped_possible_sorts(sort_expression_list(NewPosTypes));
634 const sort_expression_list& PosArgTypes=s
.domain();
636 if (PosArgTypes.size()!=ArgTypes.size())
640 sort_expression_list temp;
641 if (TypeMatchL(PosArgTypes,ArgTypes,temp))
649 TypeMatchL(ArgTypes,ExpandNumTypesUpL(PosArgTypes),temp);
660 sort_expression_list NewPosTypes;
664 for (sort_expression_list PosTypes=mps.sorts(); !PosTypes.empty(); PosTypes=PosTypes.tail())
666 sort_expression NewPosType=PosTypes.front();
667 if (is_basic_sort(NewPosType))
669 NewPosType=UnwindType(NewPosType);
671 if (is_function_sort(NewPosType))
673 const function_sort& s=down_cast<
const function_sort>(NewPosType);
674 const sort_expression_list& PosArgTypes=s.domain();
675 if (PosArgTypes.size()!=ArgTypes.size())
679 sort_expression_list temp_list;
680 if (TypeMatchL(PosArgTypes,ArgTypes,temp_list))
682 NewPosType=s.codomain();
685 else if (!data::is_untyped_sort(data::sort_expression(NewPosType)))
689 NewPosTypes=detail::insert_sort_unique(NewPosTypes,NewPosType);
691 NewPosTypes=reverse(NewPosTypes);
692 result=untyped_possible_sorts(sort_expression_list(NewPosTypes));
724 sort_expression_list Args=type.domain();
732 if (!UnifyMinType(Res,Args.front(),Res))
737 if (!UnifyMinType(Res,Args.front(),Res))
751 sort_expression_list Args=type.domain();
774 const sort_expression_list& Args=type
.domain();
806 sort_expression_list Args=type.domain();
854 sort_expression_list Args=type.domain();
903 sort_expression_list Args=type.domain();
955 const sort_expression_list& Args=type
.domain();
989 const sort_expression_list& Args=type
.domain();
1031 const sort_expression_list& Args=type
.domain();
1077 const sort_expression_list& Args=type
.domain();
1121 sort_expression_list Args=type.domain();
1145 const sort_expression_list Arg11l=down_cast<function_sort>(Arg1).domain();
1146 if (Arg11l.size()!=1)
1210 sort_expression_list Args=type.domain();
1234 const sort_expression_list Arg11l=down_cast<function_sort>(Arg1).domain();
1235 if (Arg11l.size()!=1)
1277 sort_expression_list Args=type.domain();
1309 sort_expression_list Args=type.domain();
1335 result
=function_sort({ Arg, fset_type },fset_type);
1345 const sort_expression_list& argument_types = type
.domain();
1346 if (argument_types.size() != 1)
1368 result_type
= new_result_type;
1385 sort_expression_list Args=type.domain();
1426 result
=function_sort({ Arg3r, Arg2r, fbag_type },fbag_type);
1456 sort_expression_list Args=type.domain();
1513 result
= function_sort({ Arg1, Arg2 }, Arg2);
1530 result
= function_sort({ Arg1, Arg2 }, Arg2);
1547 result
= function_sort({ Arg1, Arg2 }, Arg1);
1564 result
= function_sort({ Arg1, Arg2 }, Arg1);
1580 result
=function_sort({ Res,Res },Res);
1600 const sort_expression_list& Args=type
.domain();
1656 const sort_expression_list& Args=type
.domain();
1696 sort_expression_list Args=type.domain();
1697 if (!(Args.size()==2))
1734 sort_expression_list Args=type.domain();
1755 Arg1 = atermpp::down_cast<function_sort>(UnwindType(temp_result));
1758 sort_expression_list LA=Arg1.domain();
1882 sort_expression_vector result;
1883 for (
const sort_expression& i : type_list)
1885 result.push_back(ExpandNumTypesUp(i));
1887 return sort_expression_list(result.begin(),result.end());
1958 sort_expression_list NewTypeList;
1959 for (sort_expression_list TypeList=t.domain(); !TypeList.empty(); TypeList=TypeList.tail())
1961 NewTypeList.push_front(ExpandNumTypesUp(UnwindType(TypeList.front())));
1966 return function_sort(reverse(NewTypeList),ResultType);
1970 return function_sort(reverse(NewTypeList),ExpandNumTypesUp(UnwindType(ResultType)));
1989 bool function=
false;
1990 sort_expression_list Args;
2047 return (function)?function_sort(Args,Type):Type;
2053 for (
const sort_expression& s: Types)
2055 if (EqTypesA(Type,s))
2075 for (
const sort_expression_list&l: Types)
2077 if (EqTypesL(Type,l))
2091 if (Type1.size()!=Type2.size())
2095 sort_expression_list::const_iterator i=Type1.begin();
2096 for (
const sort_expression& s: Type2)
2098 if (!EqTypesA(*i,s))
2118 assert(proposed_type.defined());
2122 const core::identifier_string& data_term_name=data::is_untyped_identifier(d)?
2123 atermpp::down_cast<
const untyped_identifier>(d).name():
2124 (down_cast<
const data::function_symbol>(d).name());
2126 if (data::detail::if_symbol::is_symbol(data_term_name))
2129 if (!MatchIf(atermpp::down_cast<function_sort>(Type), NewType))
2131 throw mcrl2::runtime_error(
"The function if has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2136 if (data::detail::equal_symbol::is_symbol(data_term_name)
2137 || data::detail::not_equal_symbol::is_symbol(data_term_name)
2138 || data::detail::less_symbol::is_symbol(data_term_name)
2139 || data::detail::less_equal_symbol::is_symbol(data_term_name)
2140 || data::detail::greater_symbol::is_symbol(data_term_name)
2141 || data::detail::greater_equal_symbol::is_symbol(data_term_name)
2145 if (!MatchEqNeqComparison(atermpp::down_cast<function_sort>(Type), NewType))
2147 throw mcrl2::runtime_error(
"The function " + core::pp(data_term_name) +
" has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2155 if (!MatchSqrt(atermpp::down_cast<function_sort>(Type), NewType))
2157 throw mcrl2::runtime_error(
"The function sqrt has an incorrect argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2165 if (!MatchListOpCons(atermpp::down_cast<function_sort>(Type), NewType))
2167 throw mcrl2::runtime_error(
"The function |> has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2175 if (!MatchListOpSnoc(atermpp::down_cast<function_sort>(Type), NewType))
2177 throw mcrl2::runtime_error(
"The function <| has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2185 if (!MatchListOpConcat(atermpp::down_cast<function_sort>(Type), NewType))
2187 throw mcrl2::runtime_error(
"The function ++ has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2195 if (!MatchListOpEltAt(atermpp::down_cast<function_sort>(Type), NewType))
2197 throw mcrl2::runtime_error(
"The function @ has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2207 if (!MatchListOpHead(atermpp::down_cast<function_sort>(Type), NewType))
2209 throw mcrl2::runtime_error(
"The function {R,L}head has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2218 if (!MatchListOpTail(atermpp::down_cast<function_sort>(Type), NewType))
2220 throw mcrl2::runtime_error(
"The function {R,L}tail has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2228 if (!MatchSetOpSet2Bag(atermpp::down_cast<function_sort>(Type), NewType))
2230 throw mcrl2::runtime_error(
"The function Set2Bag has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2238 if (!MatchListSetBagOpIn(atermpp::down_cast<function_sort>(Type), NewType))
2240 throw mcrl2::runtime_error(
"The function {List,Set,Bag}In has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2250 if (!MatchSetBagOpUnionDiffIntersect(data_term_name, atermpp::down_cast<function_sort>(Type), NewType))
2252 throw mcrl2::runtime_error(
"The function {Set,Bag}{Union,Difference,Intersect} has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2261 if (!match_fset_insert(atermpp::down_cast<function_sort>(Type), NewType))
2263 throw mcrl2::runtime_error(
"Set enumeration has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2271 if (!match_fset_fbag_pick(atermpp::down_cast<function_sort>(Type), NewType))
2273 throw mcrl2::runtime_error(
"The function pick has incompatible argument type " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2281 if (!match_fbag_cinsert(atermpp::down_cast<function_sort>(Type), NewType))
2283 throw mcrl2::runtime_error(
"Bag enumeration has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2291 if (!MatchSetOpSetCompl(atermpp::down_cast<function_sort>(Type), NewType))
2293 throw mcrl2::runtime_error(
"The function SetCompl has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2301 if (!MatchBagOpBag2Set(atermpp::down_cast<function_sort>(Type), NewType))
2303 throw mcrl2::runtime_error(
"The function Bag2Set has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2311 if (!MatchBagOpBagCount(atermpp::down_cast<function_sort>(Type), NewType))
2313 throw mcrl2::runtime_error(
"The function BagCount has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2322 if (!MatchFuncUpdate(atermpp::down_cast<function_sort>(Type), NewType))
2324 throw mcrl2::runtime_error(
"Function update has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2332 if (!MatchSetConstructor(atermpp::down_cast<function_sort>(Type), NewType))
2334 throw mcrl2::runtime_error(
"Set constructor has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2343 if (!MatchBagConstructor(atermpp::down_cast<function_sort>(Type), NewType))
2345 throw mcrl2::runtime_error(
"Bag constructor has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2353 if (!MatchFalseFunction(atermpp::down_cast<function_sort>(Type), NewType))
2355 throw mcrl2::runtime_error(
"Bag constructor has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2363 if (!MatchBagConstructor(atermpp::down_cast<function_sort>(Type), NewType))
2365 throw mcrl2::runtime_error(
"Bag constructor has incompatible argument types " + data::pp(Type) +
" (while typechecking " + data::pp(d) +
").");
2379 const bool strictly_ambiguous,
2380 const std::size_t nFactPars,
2381 const bool warn_upcasting,
2382 const bool print_cast_error)
const
2387 core::identifier_string Name=data::is_untyped_identifier(DataTerm)?down_cast<
const untyped_identifier>(DataTerm).name():
2388 atermpp::down_cast<
const function_symbol>(DataTerm).name();
2390 bool variable_=
false;
2391 bool TypeADefined=
false;
2393 std::map<core::identifier_string,sort_expression>::const_iterator i=DeclaredVars.context().find(Name);
2395 if (i!=DeclaredVars.context().end())
2397 TypeA=normalize_sorts(i->second,get_sort_specification());
2400 if (is_function_sort(Type1)?(function_sort(Type1).domain().size()==nFactPars):(nFactPars==0))
2412 sort_expression_list ParList;
2415 std::map<core::identifier_string,sort_expression>::const_iterator i=DeclaredVars.context().find(Name);
2416 if (i!=DeclaredVars.context().end())
2418 TypeA=normalize_sorts(i->second,get_sort_specification());
2423 throw mcrl2::runtime_error(
"The type " + data::pp(TypeA) +
" of variable " + core::pp(Name)
2424 +
" is incompatible with " + data::pp(PosType) +
" (typechecking " + data::pp(DataTerm) +
").");
2431 std::map<core::identifier_string,sort_expression>::const_iterator i=user_constants.find(Name);
2432 if (i!=user_constants.end())
2439 throw mcrl2::runtime_error(
"The type " + data::pp(TypeA) +
" of constant " + core::pp(Name)
2440 +
" is incompatible with " + data::pp(PosType) +
" (typechecking " + data::pp(DataTerm) +
").");
2447 std::map<core::identifier_string,sort_expression_list>::const_iterator j=system_constants.find(Name);
2449 if (j!=system_constants.end())
2452 if (ParList.size()==1)
2461 throw mcrl2::runtime_error(
"Ambiguous system constant " +
core::pp(Name) +
".");
2466 throw mcrl2::runtime_error(
"Unknown constant " +
core::pp(Name) +
".");
2474 ParList = sort_expression_list({ UnwindType(TypeA) });
2478 const std::map <core::identifier_string,sort_expression_list>::const_iterator j_context=user_functions.find(Name);
2479 const std::map <core::identifier_string,sort_expression_list>::const_iterator j_gssystem=system_functions.find(Name);
2481 if (j_context==user_functions.end())
2483 if (j_gssystem!=system_functions.end())
2485 ParList=j_gssystem->second;
2489 if (nFactPars!=std::string::npos)
2491 throw mcrl2::runtime_error(
"Unknown operation " + core::pp(Name) +
" with " + std::to_string(nFactPars) +
" parameter" + ((nFactPars != 1)?
"s.":
"."));
2495 throw mcrl2::runtime_error(
"Unknown operation " +
core::pp(Name) +
".");
2499 else if (j_gssystem==system_functions.end())
2501 ParList=j_context->second;
2505 ParList=j_gssystem->second+j_context->second;
2509 sort_expression_list CandidateParList=ParList;
2513 sort_expression_list NewParList;
2514 if (nFactPars!=std::string::npos)
2516 for (; !ParList.empty(); ParList=ParList.tail())
2518 const sort_expression& Par=ParList.front();
2519 if (!is_function_sort(Par))
2523 if (down_cast<function_sort>(Par).domain().size()!=nFactPars)
2527 NewParList.push_front(Par);
2529 ParList=reverse(NewParList);
2532 if (!ParList.empty())
2534 CandidateParList=ParList;
2538 sort_expression_list BackupParList=ParList;
2539 NewParList=sort_expression_list();
2540 for (; !ParList.empty(); ParList=ParList.tail())
2542 const sort_expression& Par=ParList.front();
2545 PosType=determine_allowed_type(DataTerm, PosType);
2546 sort_expression result;
2547 if (TypeMatchA(Par,PosType,result))
2549 NewParList=detail::insert_sort_unique(NewParList,result);
2552 catch (mcrl2::runtime_error&)
2557 NewParList=reverse(NewParList);
2559 if (NewParList.empty())
2567 ParList=BackupParList;
2569 for (; !ParList.empty(); ParList=ParList.tail())
2571 const sort_expression& Par=ParList.front();
2572 sort_expression result;
2573 if (TypeMatchA(Par,PosType,result))
2575 NewParList=detail::insert_sort_unique(NewParList,result);
2578 NewParList=reverse(NewParList);
2579 if (NewParList.size()>1)
2581 NewParList = sort_expression_list({ detail::MinType(NewParList) });
2585 if (NewParList.empty())
2590 ParList=BackupParList;
2593 for (; !ParList.empty(); ParList=ParList.tail())
2595 const sort_expression& Par=ParList.front();
2596 sort_expression result;
2597 if (TypeMatchA(Par,PosType,result))
2599 NewParList=detail::insert_sort_unique(NewParList,result);
2602 NewParList=reverse(NewParList);
2603 if (NewParList.size()>1)
2605 NewParList = sort_expression_list({ detail::MinType(NewParList) });
2611 if (ParList.empty())
2615 if (CandidateParList.size()==1)
2617 Sort=CandidateParList.front();
2621 Sort=untyped_possible_sorts(sort_expression_list(CandidateParList));
2624 if (nFactPars!=std::string::npos)
2626 throw mcrl2::runtime_error(
"Unknown operation/variable " + core::pp(Name)
2627 +
" with " + std::to_string(nFactPars) +
" argument" + ((nFactPars != 1)?
"s":
"")
2628 +
" that matches type " + data::pp(PosType) +
".");
2632 throw mcrl2::runtime_error(
"Unknown operation/variable " + core::pp(Name) +
" that matches type " + data::pp(PosType) +
".");
2636 if (ParList.size()==1)
2643 assert(Type.defined());
2660 throw mcrl2::runtime_error(
"Fail to match sort " + data::pp(OldType) +
" with " + data::pp(PosType) +
".");
2679 assert(Type.defined());
2684 if (strictly_ambiguous)
2686 if (nFactPars!=std::string::npos)
2688 throw mcrl2::runtime_error(
"Ambiguous operation " + core::pp(Name) +
" with " + std::to_string(nFactPars) +
" parameter" + ((nFactPars != 1)?
"s.":
"."));
2692 throw mcrl2::runtime_error(
"Ambiguous operation " +
core::pp(Name) +
".");
2712 const bool strictly_ambiguous,
2713 const bool warn_upcasting,
2714 const bool print_cast_error)
const
2723 if (abstr.variables().size()==0)
2725 throw mcrl2::runtime_error(
"Binder " + data::pp(DataTerm) +
" should have at least one declared variable.");
2734 const variable_list& comprehension_variables=abstr
.variables();
2738 (*
this)
(comprehension_variables
,DeclaredVars
);
2740 catch (mcrl2::runtime_error& e)
2742 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking the bag/set " + data::pp(DataTerm) +
".");
2747 if (comprehension_variables.size()!=1)
2749 throw mcrl2::runtime_error(
"Set/bag comprehension " + data::pp(DataTerm) +
" should have exactly one declared variable.");
2752 const sort_expression element_sort=comprehension_variables.front().sort();
2755 CopyDeclaredVars.add_context_variables(comprehension_variables);
2763 ResType
=TraverseVarConsTypeD(CopyDeclaredVars,Data,
data::untyped_sort(),strictly_ambiguous,warn_upcasting,print_cast_error);
2765 catch (mcrl2::runtime_error& e)
2767 throw mcrl2::runtime_error(std::string(e.what()) +
"\nThe condition or count of a set/bag comprehension " + data::pp(DataTerm) +
" cannot be determined.");
2783#ifdef MCRL2_ENABLE_MACHINENUMBERS
2784 Data=sort_nat::transform_positive_number_to_nat(Data);
2792 throw mcrl2::runtime_error(
"The condition or count of a set/bag comprehension is not of sort Bool, Nat or Pos, but of sort " + data::pp(ResType) +
".");
2797 throw mcrl2::runtime_error(
"A set or bag comprehension of type " + data::pp(element_sort) +
" does not match possible type " +
2798 data::pp(PosType) +
" (while typechecking " + data::pp(DataTerm) +
").");
2806 const variable_list& bound_variables=abstr
.variables();
2811 (*
this)
(bound_variables
,DeclaredVars
);
2813 catch (mcrl2::runtime_error& e)
2815 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking the quantification " + data::pp(DataTerm) +
".");
2819 CopyDeclaredVars.add_context_variables(bound_variables);
2825 throw mcrl2::runtime_error(
"The type of an exist/forall for " + data::pp(DataTerm) +
" cannot be determined.");
2831 throw mcrl2::runtime_error(
"The type of an exist/forall for " + data::pp(DataTerm) +
" cannot be determined.");
2840 const variable_list& bound_variables=abstr
.variables();
2844 (*
this)
(bound_variables
,DeclaredVars
);
2846 catch (mcrl2::runtime_error& e)
2848 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking the lambda expression " + data::pp(DataTerm) +
".");
2852 CopyDeclaredVars.add_context_variables(bound_variables);
2854 sort_expression_list ArgTypes=detail::GetVarTypes(bound_variables);
2856 if (!UnArrowProd(ArgTypes,PosType,NewType))
2858 throw mcrl2::runtime_error(
"No functions with arguments " + data::pp(ArgTypes) +
" among " + data::pp(PosType) +
" (while typechecking " + data::pp(DataTerm) +
").");
2864 NewType
=TraverseVarConsTypeD(CopyDeclaredVars,Data,NewType,strictly_ambiguous,warn_upcasting,print_cast_error);
2866 catch (mcrl2::runtime_error& e)
2872 return function_sort(ArgTypes,NewType);
2879 variable_list WhereVarList;
2880 assignment_list NewWhereList;
2882 for (
const assignment_expression& WhereElem : where_asss)
2884 data_expression WhereTerm;
2885 variable NewWhereVar;
2886 if (data::is_untyped_identifier_assignment(WhereElem))
2888 const data::untyped_identifier_assignment& t=down_cast<
const data::untyped_identifier_assignment>(WhereElem);
2890 sort_expression WhereType=TraverseVarConsTypeD(DeclaredVars,WhereTerm,data::untyped_sort(),strictly_ambiguous,warn_upcasting,print_cast_error);
2893 NewWhereVar=variable(t.lhs(),WhereType);
2897 const assignment& t=down_cast<
const assignment>(WhereElem);
2899 NewWhereVar=t.lhs();
2900 sort_expression WhereType=TraverseVarConsTypeD(DeclaredVars,WhereTerm,NewWhereVar.sort(),strictly_ambiguous,warn_upcasting,print_cast_error);
2902 WhereVarList.push_front(NewWhereVar);
2903 NewWhereList.push_front(assignment(NewWhereVar,WhereTerm));
2905 NewWhereList=reverse(NewWhereList);
2907 variable_list where_variables=reverse(WhereVarList);
2911 (*
this)(where_variables,DeclaredVars);
2913 catch (mcrl2::runtime_error& e)
2915 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking the where expression " + data::pp(DataTerm) +
".");
2919 CopyDeclaredVars.add_context_variables(where_variables);
2922 sort_expression NewType=TraverseVarConsTypeD(CopyDeclaredVars,Data,PosType,strictly_ambiguous,warn_upcasting,print_cast_error);
2924 DataTerm=where_clause(Data,NewWhereList);
2931 const application& appl=down_cast<application>(DataTerm);
2932 std::size_t nArguments=appl.size();
2938 core::identifier_string Name = is_function_symbol(Arg0)?down_cast<function_symbol>(Arg0).name():
2939 atermpp::down_cast<untyped_identifier>(Arg0).name();
2945 throw mcrl2::runtime_error(
"It is not possible to cast list to " + data::pp(PosType) +
" (while typechecking " + data::pp(data_expression_list(appl.begin(),appl.end())) +
").");
2949 data_expression_list NewArguments;
2950 bool Type_is_stable=
true;
2951 for (data_expression Argument : appl)
2953 sort_expression Type0;
2956 Type0=TraverseVarConsTypeD(DeclaredVars,Argument,Type,strictly_ambiguous,warn_upcasting,
false);
2958 catch (mcrl2::runtime_error&)
2962 Type0=TraverseVarConsTypeD(DeclaredVars,Argument,data::untyped_sort(),strictly_ambiguous,warn_upcasting,print_cast_error);
2964 NewArguments.push_front(Argument);
2965 Type_is_stable=Type_is_stable && (Type==Type0);
2970 if (!Type_is_stable)
2972 NewArguments=data_expression_list();
2973 for (data_expression Argument : appl)
2975 sort_expression Type0 = TraverseVarConsTypeD(DeclaredVars,
2981 NewArguments.push_front(Argument);
2987 DataTerm=sort_list::list_enumeration(sort_expression(Type), data_expression_list(reverse(NewArguments)));
2995 throw mcrl2::runtime_error(
"It is not possible to cast set to " + data::pp(PosType) +
" (while typechecking " + data::pp(data_expression_list(appl.begin(),appl.end())) +
").");
2999 bool NewTypeDefined=
false;
3001 for (data_expression Argument : appl)
3003 sort_expression Type0;
3006 Type0=TraverseVarConsTypeD(DeclaredVars,Argument,Type,strictly_ambiguous,warn_upcasting,print_cast_error);
3008 catch (mcrl2::runtime_error& e)
3010 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast element to " + data::pp(Type) +
" (while typechecking " + data::pp(Argument) +
").");
3013 sort_expression OldNewType=NewType;
3014 if (!NewTypeDefined)
3017 NewTypeDefined=
true;
3021 sort_expression temp;
3022 if (!MaximumType(NewType,Type0,temp))
3024 throw mcrl2::runtime_error(
"Set contains incompatible elements of sorts " + data::pp(OldNewType) +
" and " + data::pp(Type0) +
" (while typechecking " + data::pp(Argument) +
".");
3027 NewTypeDefined=
true;
3033 assert(Type.defined());
3034 assert(NewTypeDefined);
3038 data_expression_list NewArguments;
3039 for (data_expression Argument : appl)
3041 sort_expression Type0;
3044 Type0=TraverseVarConsTypeD(DeclaredVars,Argument,Type,strictly_ambiguous,warn_upcasting,print_cast_error);
3046 catch (mcrl2::runtime_error& e)
3048 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast element to " + data::pp(Type) +
" (while typechecking " + data::pp(Argument) +
").");
3050 NewArguments.push_front(Argument);
3053 DataTerm=sort_set::set_enumeration(sort_expression(Type),data_expression_list(reverse(NewArguments)));
3067 throw mcrl2::runtime_error(
"Impossible to cast bag to " + data::pp(PosType) +
"(while typechecking " +
3068 data::pp(data_expression_list(appl.begin(),appl.end())) +
").");
3073 bool NewTypeDefined=
false;
3074 for (application::const_iterator i=appl.begin(); i!=appl.end(); ++i)
3076 data_expression Argument0= *i;
3078 data_expression Argument1= *i;
3079 sort_expression Type0;
3082 Type0=TraverseVarConsTypeD(DeclaredVars,Argument0,Type,strictly_ambiguous,warn_upcasting,print_cast_error);
3084 catch (mcrl2::runtime_error& e)
3086 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast element to " + data::pp(Type) +
" (while typechecking " + data::pp(Argument0) +
").");
3088 sort_expression Type1;
3091 Type1=TraverseVarConsTypeD(DeclaredVars,Argument1,sort_nat::nat(),strictly_ambiguous,warn_upcasting,print_cast_error);
3093 catch (mcrl2::runtime_error& e)
3095 if (print_cast_error)
3097 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast number to " + data::pp(sort_nat::nat()) +
" (while typechecking " + data::pp(Argument1) +
").");
3104 sort_expression OldNewType=NewType;
3105 if (!NewTypeDefined)
3108 NewTypeDefined=
true;
3112 sort_expression temp;
3113 if (!MaximumType(NewType,Type0,temp))
3115 throw mcrl2::runtime_error(
"Bag contains incompatible elements of sorts " + data::pp(OldNewType) +
" and " + data::pp(Type0) +
" (while typechecking " + data::pp(Argument0) +
").");
3119 NewTypeDefined=
true;
3122 assert(Type.defined());
3123 assert(NewTypeDefined);
3127 data_expression_list NewArguments;
3128 for (application::const_iterator i=appl.begin(); i!=appl.end(); ++i)
3130 data_expression Argument0= *i;
3132 data_expression Argument1= *i;
3133 sort_expression Type0;
3136 Type0=TraverseVarConsTypeD(DeclaredVars,Argument0,Type,strictly_ambiguous,warn_upcasting,print_cast_error);
3138 catch (mcrl2::runtime_error& e)
3140 if (print_cast_error)
3142 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast element to " + data::pp(Type) +
" (while typechecking " + data::pp(Argument0) +
").");
3149 sort_expression Type1;
3152 Type1=TraverseVarConsTypeD(DeclaredVars,Argument1,sort_nat::nat(),strictly_ambiguous,warn_upcasting,print_cast_error);
3154 catch (mcrl2::runtime_error& e)
3156 if (print_cast_error)
3158 throw mcrl2::runtime_error(std::string(e.what()) +
"\nImpossible to cast number to " + data::pp(sort_nat::nat()) +
" (while typechecking " + data::pp(Argument1) +
").");
3165 NewArguments.push_front(Argument0);
3166 NewArguments.push_front(Argument1);
3169 DataTerm=sort_bag::bag_enumeration(Type, data_expression_list(reverse(NewArguments)));
3179 sort_expression_list NewArgumentTypes;
3180 data_expression_list NewArguments;
3181 sort_expression_list argument_sorts;
3182 for (data_expression Arg : appl)
3184 sort_expression Type
3185 = TraverseVarConsTypeD(DeclaredVars, Arg, data::untyped_sort(),
false, warn_upcasting, print_cast_error);
3186 assert(Type.defined());
3187 NewArguments.push_front(Arg);
3188 NewArgumentTypes.push_front(Type);
3190 data_expression_list Arguments=reverse(NewArguments);
3191 sort_expression_list ArgumentTypes=reverse(NewArgumentTypes);
3197 NewType=TraverseVarConsTypeDN(DeclaredVars,
3200 function_sort(ArgumentTypes,PosType),
3201 false,nArguments,warn_upcasting,print_cast_error);
3203 catch (mcrl2::runtime_error& e)
3205 throw mcrl2::runtime_error(std::string(e.what()) +
"\nType error while trying to cast an application of " +
3206 data::pp(Data) +
" to arguments " + data::pp(Arguments) +
" to type " + data::pp(PosType) +
".");
3217 sort_expression_list NeededArgumentTypes=down_cast<function_sort>(UnwindType(NewType)).domain();
3219 if (NeededArgumentTypes.size()!=Arguments.size())
3221 throw mcrl2::runtime_error(
"Need argumens of sorts " + data::pp(NeededArgumentTypes) +
3222 " which does not match the number of provided arguments "
3223 + data::pp(Arguments) +
" (while typechecking "
3224 + data::pp(DataTerm) +
").");
3227 sort_expression_list NewArgumentTypes;
3228 data_expression_list NewArguments;
3229 for (; !Arguments.empty(); Arguments=Arguments.tail(),
3230 ArgumentTypes=ArgumentTypes.tail(),NeededArgumentTypes=NeededArgumentTypes.tail())
3232 assert(!Arguments.empty());
3233 assert(!NeededArgumentTypes.empty());
3234 data_expression Arg=Arguments.front();
3235 const sort_expression& NeededType=NeededArgumentTypes.front();
3236 sort_expression Type=ArgumentTypes.front();
3237 if (!EqTypesA(NeededType,Type))
3242 Type=UpCastNumericType(NeededType,Type,Arg,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3244 catch (mcrl2::runtime_error&)
3249 if (!EqTypesA(NeededType,Type))
3251 sort_expression NewArgType;
3252 if (!TypeMatchA(NeededType,Type,NewArgType))
3254 if (!TypeMatchA(NeededType,ExpandNumTypesUp(Type),NewArgType))
3256 NewArgType=NeededType;
3261 NewArgType=TraverseVarConsTypeD(DeclaredVars,Arg,NewArgType,strictly_ambiguous,warn_upcasting,print_cast_error);
3263 catch (mcrl2::runtime_error& e)
3265 throw mcrl2::runtime_error(std::string(e.what()) +
"\nRequired type " + data::pp(NeededType) +
" does not match possible type "
3266 + data::pp(Type) +
" (while typechecking " + data::pp(Arg) +
" in " + data::pp(DataTerm) +
").");
3270 NewArguments.push_front(Arg);
3271 NewArgumentTypes.push_front(Type);
3273 Arguments=reverse(NewArguments);
3274 ArgumentTypes=reverse(NewArgumentTypes);
3280 NewType=TraverseVarConsTypeDN(DeclaredVars,
3281 Data,function_sort(ArgumentTypes,PosType),
3282 strictly_ambiguous,nArguments,warn_upcasting,print_cast_error);
3284 catch (mcrl2::runtime_error& e)
3286 throw mcrl2::runtime_error(std::string(e.what()) +
"\nType error while trying to cast " +
3287 data::pp(application(Data,Arguments)) +
" to type " + data::pp(PosType) +
".");
3293 sort_expression_list NeededArgumentTypes=down_cast<function_sort>(UnwindType(NewType)).domain();
3294 sort_expression_list NewArgumentTypes;
3295 data_expression_list NewArguments;
3296 for (; !Arguments.empty(); Arguments=Arguments.tail(),
3297 ArgumentTypes=ArgumentTypes.tail(),NeededArgumentTypes=NeededArgumentTypes.tail())
3299 data_expression Arg=Arguments.front();
3300 const sort_expression& NeededType=NeededArgumentTypes.front();
3301 sort_expression Type=ArgumentTypes.front();
3303 if (!EqTypesA(NeededType,Type))
3308 Type=UpCastNumericType(NeededType,Type,Arg,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3310 catch (mcrl2::runtime_error&)
3315 if (!EqTypesA(NeededType,Type))
3317 sort_expression NewArgType;
3318 if (!TypeMatchA(NeededType,Type,NewArgType))
3320 if (!TypeMatchA(NeededType,ExpandNumTypesUp(Type),NewArgType))
3322 NewArgType=NeededType;
3327 NewArgType=TraverseVarConsTypeD(DeclaredVars,Arg,NewArgType,strictly_ambiguous,warn_upcasting,print_cast_error);
3329 catch (mcrl2::runtime_error& e)
3331 throw mcrl2::runtime_error(std::string(e.what()) +
"\nNeeded type " + data::pp(NeededType) +
" does not match possible type "
3332 + data::pp(Type) +
" (while typechecking " + data::pp(Arg) +
" in " + data::pp(DataTerm) +
").");
3337 NewArguments.push_front(Arg);
3338 NewArgumentTypes.push_front(Type);
3340 Arguments=reverse(NewArguments);
3341 ArgumentTypes=reverse(NewArgumentTypes);
3344 DataTerm=application(Data,Arguments);
3354 return UpCastNumericType(PosType, atermpp::down_cast<function_sort>(UnwindType(NewType)).codomain(),
3355 DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3358 return atermpp::down_cast<function_sort>(UnwindType(NewType)).codomain();
3362 if (!UnArrowProd(ArgumentTypes,NewType,temp_type))
3364 throw mcrl2::runtime_error(
"Fail to properly type " + data::pp(DataTerm) +
".");
3368 throw mcrl2::runtime_error(
"Fail to properly type " + data::pp(DataTerm) +
".");
3375 core::identifier_string Name=
3376 data::is_untyped_identifier(DataTerm)?down_cast<untyped_identifier>(DataTerm).name():
3377 is_function_symbol(DataTerm)?down_cast<function_symbol>(DataTerm).name():
3378 atermpp::down_cast<variable>(DataTerm).name();
3379 if (utilities::is_numeric_string(Name.function().name()))
3402 CastedNewType
=UpCastNumericType(PosType,Sort,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3404 catch (mcrl2::runtime_error& e)
3406 throw mcrl2::runtime_error(std::string(e.what()) +
"\nCannot (up)cast number " + data::pp(DataTerm) +
" to type " + data::pp(PosType) +
".");
3408 return CastedNewType;
3411 const std::map<core::identifier_string,sort_expression>::const_iterator it=DeclaredVars.context().find(Name);
3412 if (it!=DeclaredVars.context().end())
3414 sort_expression Type=normalize_sorts(it->second,get_sort_specification());
3428 CastedNewType
=UpCastNumericType(PosType,Type,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3430 catch (mcrl2::runtime_error& e)
3432 if (print_cast_error)
3434 throw mcrl2::runtime_error(std::string(e.what()) +
"\nCannot (up)cast variable " + data::pp(DataTerm) +
" to type " + data::pp(PosType) +
".");
3449 std::map<core::identifier_string,sort_expression>::const_iterator i=user_constants.find(Name);
3450 if (i!=user_constants.end())
3466 return UpCastNumericType(PosType,Type,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3468 catch (mcrl2::runtime_error& e)
3470 throw mcrl2::runtime_error(std::string(e.what()) +
"\nNo constant " + data::pp(DataTerm) +
" with type " + data::pp(PosType) +
".");
3475 std::map<core::identifier_string,sort_expression_list>::const_iterator j=system_constants.find(Name);
3476 if (j!=system_constants.end())
3478 sort_expression_list TypeList=j->second;
3479 sort_expression_list NewParList;
3480 for (
const sort_expression& Type: TypeList)
3482 sort_expression result;
3483 if (TypeMatchA(Type,PosType,result))
3485 DataTerm=data::function_symbol(Name,result);
3486 NewParList.push_front(result);
3489 sort_expression_list ParList=reverse(NewParList);
3490 if (ParList.empty())
3493 for (sort_expression Type : TypeList)
3495 if (is_untyped_identifier(DataTerm))
3497 DataTerm=data::function_symbol(Name,Type);
3499 Type=UpCastNumericType(PosType,Type,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3500 sort_expression result;
3501 if (TypeMatchA(Type,PosType,result))
3503 NewParList.push_front(result);
3506 ParList=reverse(NewParList);
3509 if (ParList.empty())
3511 throw mcrl2::runtime_error(
"No system constant " + data::pp(DataTerm) +
" with type " + data::pp(PosType) +
".");
3514 if (ParList.size()==1)
3525 sort_expression r= UpCastNumericType(PosType,Type,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3528 catch (mcrl2::runtime_error& e)
3530 throw mcrl2::runtime_error(std::string(e.what()) +
"\nNo constant " + data::pp(DataTerm) +
" with type " + data::pp(PosType) +
".");
3540 const std::map <core::identifier_string,sort_expression_list>::const_iterator j_context=user_functions.find(Name);
3541 const std::map <core::identifier_string,sort_expression_list>::const_iterator j_gssystem=system_functions.find(Name);
3543 sort_expression_list ParList;
3544 if (j_context==user_functions.end())
3546 if (j_gssystem!=system_functions.end())
3548 ParList=j_gssystem->second;
3552 throw mcrl2::runtime_error(
"Unknown operation " +
core::pp(Name) +
".");
3555 else if (j_gssystem==system_functions.end())
3557 ParList=j_context->second;
3561 ParList=j_gssystem->second+j_context->second;
3565 if (ParList.size()==1)
3571 return UpCastNumericType(PosType,Type,DataTerm,DeclaredVars,strictly_ambiguous,warn_upcasting,print_cast_error);
3573 catch (mcrl2::runtime_error& e)
3575 throw mcrl2::runtime_error(std::string(e.what()) +
"\nNo constant " + data::pp(DataTerm) +
" with type " + data::pp(PosType) +
".");
3580 return TraverseVarConsTypeDN(DeclaredVars, DataTerm, PosType, strictly_ambiguous, std::string::npos, warn_upcasting,print_cast_error);
3584#ifdef MCRL2_ENABLE_MACHINENUMBERS
3585 if (is_machine_number(DataTerm))
3587 return sort_machine_word::machine_word();
3591 throw mcrl2::runtime_error(
"Internal type checking error: " + data::pp(DataTerm) +
" does not match any type checking case." );
3596 std::size_t constr_number=constructors.size();
3597 function_symbol_vector functions_and_constructors=constructors;
3598 functions_and_constructors.insert(functions_and_constructors.end(),mappings.begin(),mappings.end());
3599 for (
const function_symbol& Func: functions_and_constructors)
3601 const core::identifier_string& FuncName=Func.name();
3602 sort_expression FuncType=Func.sort();
3604 check_sort_is_declared(FuncType);
3607 if (is_basic_sort(FuncType))
3609 const sort_expression NewFuncType=UnwindType(FuncType);
3610 if (is_function_sort(NewFuncType))
3612 FuncType=NewFuncType;
3616 if (is_function_sort(FuncType))
3618 add_function(data::function_symbol(FuncName,FuncType),
"function");
3624 add_constant(data::function_symbol(FuncName,FuncType),
"constant");
3626 catch (mcrl2::runtime_error& e)
3628 throw mcrl2::runtime_error(std::string(e.what()) +
"\nCould not add constant.");
3637 sort_expression ConstructorType=FuncType;
3638 if (is_function_sort(ConstructorType))
3640 ConstructorType=down_cast<function_sort>(ConstructorType).codomain();
3642 ConstructorType=UnwindType(ConstructorType);
3643 if (!is_basic_sort(ConstructorType) ||
3644 sort_bool::is_bool(sort_expression(ConstructorType)) ||
3645 sort_pos::is_pos(sort_expression(ConstructorType)) ||
3646 sort_nat::is_nat(sort_expression(ConstructorType)) ||
3647 sort_int::is_int(sort_expression(ConstructorType)) ||
3648 sort_real::is_real(sort_expression(ConstructorType))
3651 throw mcrl2::runtime_error(
"Could not add constructor " + core::pp(FuncName) +
" of sort " + data::pp(FuncType) +
". Constructors of built-in sorts are not allowed.");
3660 check_for_empty_constructor_domains(normalized_constructors);
3668 if (user_constants.count(Name)>0)
3670 throw mcrl2::runtime_error(
"Double declaration of " + msg +
" " + core::pp(Name) +
".");
3673 if (system_constants.count(Name)>0 || system_functions.count(Name)>0)
3675 throw mcrl2::runtime_error(
"Attempt to declare a constant with the name that is a built-in identifier (" +
core::pp(Name) +
").");
3678 user_constants[Name]=normalize_sorts(Sort,get_sort_specification());
3683 const sort_expression_list& TypeList,
3684 const sort_expression_list& PosTypeList,
3685 sort_expression_list& result)
const
3687 if (TypeList.size()!=PosTypeList.size())
3692 sort_expression_list Result;
3693 sort_expression_list::const_iterator j=PosTypeList.begin();
3694 for (sort_expression_list::const_iterator i=TypeList.begin(); i!=TypeList.end(); ++i, ++j)
3696 sort_expression Type;
3697 if (!TypeMatchA(*i,*j,Type))
3701 Result.push_front(Type);
3703 result=reverse(Result);
3746 sort_expression_list NewTypeList;
3748 for (sort_expression NewPosType : mps.sorts())
3750 sort_expression new_type;
3751 if (TypeMatchA(Type,NewPosType,new_type))
3753 NewPosType=new_type;
3755 if (std::find(NewTypeList.begin(),NewTypeList.end(),NewPosType)==NewTypeList.end())
3757 NewTypeList.push_front(NewPosType);
3761 if (NewTypeList.empty())
3765 if (NewTypeList.tail().empty())
3767 result=NewTypeList.front();
3771 result=untyped_possible_sorts(sort_expression_list(reverse(NewTypeList)));
3885 sort_expression_list ArgTypes;
3886 if (!TypeMatchL(fs.domain(),posfs.domain(),ArgTypes))
3895 result=function_sort(ArgTypes,ResType);
3908 const core::identifier_string& OpIdName = f
.name();
3911 std::map<core::identifier_string,sort_expression_list>::const_iterator i=system_constants.find(OpIdName);
3913 sort_expression_list Types;
3914 if (i!=system_constants.end())
3918 Types=push_back(Types,Type);
3919 system_constants[OpIdName]=Types;
3926 const core::identifier_string& OpIdName = f
.name();
3930 const std::map <core::identifier_string,sort_expression_list>::const_iterator j=system_functions.find(OpIdName);
3932 sort_expression_list Types;
3933 if (j!=system_functions.end())
3937 Types=Types + sort_expression_list({ Type });
3938 system_functions[OpIdName]=Types;
3943 for(
const function_symbol& f: v)
3945 if (is_function_sort(f.sort()))
3947 add_system_function(f);
3951 add_system_constant(f);
3970 add_system_constants_and_functions(sort_bool::bool_mCRL2_usable_constructors());
3971 add_system_constants_and_functions(sort_bool::bool_mCRL2_usable_mappings());
3974 add_system_constants_and_functions(sort_pos::pos_mCRL2_usable_constructors());
3975 add_system_constants_and_functions(sort_pos::pos_mCRL2_usable_mappings());
3976 assert(system_constants.find(sort_pos::c1().name())!=system_constants.end());
3979 add_system_constants_and_functions(sort_nat::nat_mCRL2_usable_constructors());
3980 add_system_constants_and_functions(sort_nat::nat_mCRL2_usable_mappings());
3981#ifdef MCRL2_ENABLE_MACHINENUMBERS
3982 assert(system_functions.find(sort_nat::pos2nat().name())!=system_functions.end());
3984 assert(system_functions.find(sort_nat::cnat().name())!=system_functions.end());
3988 add_system_constants_and_functions(sort_int::int_mCRL2_usable_constructors());
3989 add_system_constants_and_functions(sort_int::int_mCRL2_usable_mappings());
3990 assert(system_functions.find(sort_int::cint().name())!=system_functions.end());
3993 add_system_constants_and_functions(sort_real::real_mCRL2_usable_constructors());
3994 add_system_constants_and_functions(sort_real::real_mCRL2_usable_mappings());
3995 assert(system_functions.find(sort_real::creal().name())!=system_functions.end());
4000 add_system_constants_and_functions(sort_list::list_mCRL2_usable_constructors(data::untyped_sort()));
4001 add_system_constants_and_functions(sort_list::list_mCRL2_usable_mappings(data::untyped_sort()));
4004 add_system_constants_and_functions(sort_fset::fset_mCRL2_usable_constructors(data::untyped_sort()));
4005 add_system_constants_and_functions(sort_fset::fset_mCRL2_usable_mappings(data::untyped_sort()));
4025 add_system_constants_and_functions(sort_fbag::fbag_mCRL2_usable_constructors(data::untyped_sort()));
4026 add_system_constants_and_functions(sort_fbag::fbag_mCRL2_usable_mappings(data::untyped_sort()));
4028
4029
4052 add_system_constants_and_functions(data::function_update_mCRL2_usable_mappings(data::untyped_sort(),data::untyped_sort()));
4057 const sort_expression_list domain=function_sort(f.sort()).domain();
4061 if (system_constants.count(Name)>0)
4063 throw mcrl2::runtime_error(
"Attempt to redeclare the system constant with a " + msg +
" " + data::pp(f) +
".");
4066 if (system_functions.count(Name)>0)
4068 throw mcrl2::runtime_error(
"Attempt to redeclare a system function with a " + msg +
" " + data::pp(f) +
".");
4071 std::map <core::identifier_string,sort_expression_list>::const_iterator j=user_functions.find(Name);
4076 if (j!=user_functions.end())
4078 sort_expression_list Types=j->second;
4079 if (InTypesA(Sort, Types))
4081 if (!allow_double_decls)
4083 throw mcrl2::runtime_error(
"Double declaration of " + msg +
" " + core::pp(Name) +
".");
4086 Types = Types + sort_expression_list({ UnwindType(Sort) });
4087 user_functions[Name]=Types;
4091 user_functions[Name] = sort_expression_list({ UnwindType(Sort) });
4111 const function_sort& fs = atermpp::down_cast<function_sort>(sort_expr);
4114 for (
const sort_expression& s: fs.domain())
4125 std::map<core::identifier_string, sort_expression> duplicate_projections_warner;
4126 const structured_sort& struct_sort = atermpp::down_cast<structured_sort>(sort_expr);
4127 for (
const structured_sort_constructor& constr: struct_sort.constructors())
4130 core::identifier_string Name=constr.recogniser();
4131 if (Name!=core::empty_identifier_string())
4133 add_function(data::function_symbol(Name,function_sort(sort_expression_list({ sort_expr }),sort_bool::bool_())),
"recognizer");
4137 const structured_sort_constructor_argument_list& Projs=constr.arguments();
4141 add_constant(data::function_symbol(Name,sort_expr),
"constructor constant");
4145 sort_expression_list ConstructorType;
4146 for (
const structured_sort_constructor_argument& proj: Projs)
4148 if (!proj.name().empty() && duplicate_projections_warner.count(proj.name())>0 && duplicate_projections_warner[proj.name()]!=proj.sort())
4150 mCRL2log(log_level_t::warning) <<
"Warning. Projection function " << proj.name() <<
" occurs multiple times with different sorts in " << struct_sort <<
". " << std::endl;
4154 duplicate_projections_warner[proj.name()]=proj.sort();
4156 const sort_expression& proj_sort=proj.sort();
4159 read_sort(proj_sort);
4161 const core::identifier_string& proj_name=proj.name();
4162 if (proj_name!=core::empty_identifier_string())
4164 add_function(function_symbol(proj_name,function_sort(sort_expression_list({ sort_expr }),proj_sort)),
"projection",
true);
4166 ConstructorType.push_front(proj_sort);
4168 add_function(data::function_symbol(Name,function_sort(reverse(ConstructorType),sort_expr)),
"constructor");
4176 for (
const sort_expression& s: TypeList)
4178 if (EqTypesA(s,Type))
4183 sort_expression_list result=TypeList;
4184 result.push_front(Type);
4210 assert(TypeList.size()==PosTypeList.size());
4211 sort_expression_list::const_iterator j=PosTypeList.begin();
4212 for (sort_expression_list::const_iterator i = TypeList.begin(); i != TypeList.end(); ++i, ++j)
4214 if (!IsTypeAllowedA(*i,*j))
4224 for (
const sort_expression& Type: TypeList)
4226 if (is_untyped_sort(Type) || is_untyped_possible_sorts(Type))
4249 if (
InTypesL(PosTypeList,TypeListList))
4251 return std::make_pair(
true,PosTypeList);
4255 return std::make_pair(
false, sort_expression_list());
4260 term_list<sort_expression_list> NewTypeListList;
4261 for (
const term_list<sort_expression>& TypeList : TypeListList)
4263 if (IsTypeAllowedL(TypeList, PosTypeList))
4265 NewTypeListList.push_front(TypeList);
4268 if (NewTypeListList.empty())
4270 return std::make_pair(
false, sort_expression_list());
4272 if (NewTypeListList.size()==1)
4274 return std::make_pair(
true,NewTypeListList.front());
4278 return std::make_pair(
true,GetNotInferredList(reverse(NewTypeListList)));
4291 sort_expression_list Result;
4292 std::size_t nFormPars=TypeListList.front().size();
4293 std::vector<sort_expression_list> Pars(nFormPars);
4294 for (std::size_t i=0; i<nFormPars; i++)
4296 Pars[i]=sort_expression_list();
4299 for (term_list<sort_expression> TypeList : TypeListList)
4301 for (std::size_t i = 0; i < nFormPars; TypeList = TypeList.tail(), i++)
4303 Pars[i]=InsertType(Pars[i],TypeList.front());
4307 for (std::size_t i=nFormPars; i>0; i--)
4309 sort_expression Sort;
4310 if (Pars[i-1].size()==1)
4312 Sort=Pars[i-1].front();
4316 Sort=untyped_possible_sorts(sort_expression_list(reverse(Pars[i-1])));
4318 Result.push_front(Sort);
4330 for (
const alias& a: get_sort_specification().user_defined_aliases())
4332 read_sort(a.reference());
4334 read_constructors_and_mappings(data_spec.user_defined_constructors(),data_spec.user_defined_mappings(),data_spec.constructors());
4336 catch (mcrl2::runtime_error& e)
4338 throw mcrl2::runtime_error(std::string(e.what()) +
"\nType checking of data expression failed.");
4341 type_checked_data_spec=data_spec;
4346 TransformVarConsTypeData(type_checked_data_spec);
4348 catch (mcrl2::runtime_error& e)
4350 type_checked_data_spec=data_specification();
4351 throw mcrl2::runtime_error(std::string(e.what()) +
"\nFailed to type check data specification.");
4365 catch (mcrl2::runtime_error& e)
4367 throw mcrl2::runtime_error(std::string(e.what()) +
"\nType checking of data expression failed.");
4371 throw mcrl2::runtime_error(
"Type checking of data expression " + data::pp(data_expr) +
" failed. Result is an unknown sort.");
4383 const std::map<core::identifier_string,sort_expression_list>::const_iterator i1=system_constants.find(v.name());
4384 if (i1!=system_constants.end())
4386 throw mcrl2::runtime_error(
"The variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
4387 " clashes with the system defined constant " + core::pp(i1->first) +
":" + data::pp(i1->second.front()) +
".");
4389 const std::map<core::identifier_string,sort_expression_list>::const_iterator i2=system_functions.find(v.name());
4390 if (i2!=system_functions.end())
4392 throw mcrl2::runtime_error(
"The variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
4393 " clashes with the system defined function " + core::pp(i2->first) +
":" + data::pp(i2->second.front()) +
".");
4395 const std::map<core::identifier_string,sort_expression>::const_iterator i3=user_constants.find(v.name());
4396 if (i3!=user_constants.end())
4398 throw mcrl2::runtime_error(
"The variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
4399 " clashes with the user defined constant " + core::pp(i3->first) +
":" + data::pp(i3->second) +
".");
4401 const std::map<core::identifier_string,sort_expression_list>::const_iterator i4=user_functions.find(v.name());
4402 if (i4!=user_functions.end())
4404 throw mcrl2::runtime_error(
"The variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
4405 " clashes with the user defined function " + core::pp(i4->first) +
":" + data::pp(i4->second.front()) +
".");
4413 catch (mcrl2::runtime_error& e)
4415 throw mcrl2::runtime_error(std::string(e.what()) +
"\nType error while typechecking the data variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
".");
4419 const std::map<core::identifier_string,sort_expression>::const_iterator i=context_variables.context().find(v.name());
4421 if (i!=context_variables.context().end() && !TypeMatchA(i->second,v.sort(),temp))
4423 throw mcrl2::runtime_error(
"The variable " + core::pp(v.name()) +
":" + data::pp(v.sort()) +
4424 " is used in its surrounding context with a different sort " + core::pp(i->second) +
".");
4434 for (
const variable& v: l)
4436 (*
this)(v, context_variables);
4440 std::set<core::identifier_string> variable_names;
4441 for (
const variable& v: l)
4443 if (!variable_names.insert(v.name()).second)
4445 throw mcrl2::runtime_error(
"The variable " + data::pp(v) +
" occurs multiple times.");
4455 data_equation_vector resulting_equations;
4456 for (
const data_equation& eqn: eqns)
4458 const variable_list& vars=eqn.variables();
4462 (*
this)(vars,detail::variable_context());
4464 catch (mcrl2::runtime_error& e)
4466 throw mcrl2::runtime_error(std::string(e.what()) +
"\nThis error occurred while typechecking equation " + data::pp(eqn) +
".");
4469 detail::variable_context DeclaredVars;
4470 DeclaredVars.add_context_variables(vars);
4472 data_expression left=eqn.lhs();
4474 sort_expression leftType;
4477 leftType=TraverseVarConsTypeD(DeclaredVars,left,data::untyped_sort(),
true,
true);
4479 catch (mcrl2::runtime_error& e)
4481 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking " + data::pp(left) +
" as left hand side of equation " + data::pp(eqn) +
".");
4484 if (was_warning_upcasting)
4486 was_warning_upcasting=
false;
4487 mCRL2log(log_level_t::warning) <<
"Warning occurred while typechecking " << left <<
" as left hand side of equation " << eqn <<
"." << std::endl;
4490 data_expression cond=eqn.condition();
4491 TraverseVarConsTypeD(DeclaredVars,cond,sort_bool::bool_());
4493 data_expression right=eqn.rhs();
4494 sort_expression rightType;
4497 rightType=TraverseVarConsTypeD(DeclaredVars,right,leftType,
false);
4499 catch (mcrl2::runtime_error& e)
4501 throw mcrl2::runtime_error(std::string(e.what()) +
"\nError occurred while typechecking " + data::pp(right) +
" as right hand side of equation " + data::pp(eqn) +
".");
4505 if (!EqTypesA(leftType,rightType))
4507 sort_expression Type;
4508 if (!TypeMatchA(leftType,rightType,Type))
4510 throw mcrl2::runtime_error(
"Types of the left- (" + data::pp(leftType) +
") and right- (" + data::pp(rightType) +
") hand-sides of the equation " + data::pp(eqn) +
" do not match.");
4515 leftType=TraverseVarConsTypeD(DeclaredVars,left,Type,
true);
4517 catch (mcrl2::runtime_error& e)
4519 throw mcrl2::runtime_error(std::string(e.what()) +
"\nTypes of the left- and right-hand-sides of the equation " + data::pp(eqn) +
" do not match.");
4521 if (was_warning_upcasting)
4523 was_warning_upcasting=
false;
4524 mCRL2log(log_level_t::warning) <<
"Warning occurred while typechecking " << left <<
" as left hand side of equation " << eqn <<
"." << std::endl;
4529 rightType=TraverseVarConsTypeD(DeclaredVars,right,leftType);
4531 catch (mcrl2::runtime_error& e)
4533 throw mcrl2::runtime_error(std::string(e.what()) +
"\nTypes of the left- and right-hand-sides of the equation " + data::pp(eqn) +
" do not match.");
4535 if (!TypeMatchA(leftType,rightType,Type))
4537 throw mcrl2::runtime_error(
"Types of the left- (" + data::pp(leftType) +
") and right- (" + data::pp(rightType) +
") hand-sides of the equation " + data::pp(eqn) +
" do not match.");
4539 if (detail::HasUnknown(Type))
4541 throw mcrl2::runtime_error(
"Types of the left- (" + data::pp(leftType) +
") and right- (" + data::pp(rightType) +
") hand-sides of the equation " + data::pp(eqn) +
" cannot be uniquely determined.");
4544 const std::set<variable> vars_in_lhs=find_free_variables(left);
4545 const std::set<variable> vars_in_rhs=find_free_variables(right);
4548 if (!detail::includes(vars_in_rhs,vars_in_lhs,culprit))
4550 throw mcrl2::runtime_error(
"The variable " + data::pp(culprit) +
" in the right hand side is not included in the left hand side of the equation " + data::pp(eqn) +
".");
4553 const std::set<variable> vars_in_condition=find_free_variables(cond);
4554 if (!detail::includes(vars_in_condition,vars_in_lhs,culprit))
4556 throw mcrl2::runtime_error(
"The variable " + data::pp(culprit) +
" in the condition is not included in the left hand side of the equation " + data::pp(eqn) +
".");
4559 resulting_equations.emplace_back(vars, cond, left, right);
4561 eqns = resulting_equations;
4570 for(
const basic_sort& s: data_spec.user_defined_sorts())
4572 new_specification.add_sort(s);
4574 for(
const alias& a: data_spec.user_defined_aliases())
4576 new_specification.add_alias(a);
4578 for(
const function_symbol& f: data_spec.user_defined_constructors())
4580 new_specification.add_constructor(f);
4582 for(
const function_symbol& f: data_spec.user_defined_mappings())
4584 new_specification.add_mapping(f);
4587 data_equation_vector eqns=data_spec.user_defined_equations();
4589 for(
const data_equation& eqn: eqns)
4591 new_specification.add_equation(eqn);
4594 std::map<std::pair<data_expression, data_expression>, data_equation> lhs_map;
4595 for (
const data_equation& eqn: new_specification.user_defined_equations())
4597 const auto find_result = lhs_map.find(std::make_pair(eqn.condition(), eqn.lhs()));
4598 if(find_result != lhs_map.end())
4600 mCRL2log(log_level_t::warning) <<
"Warning: condition and left-hand side of equations " << find_result->second <<
" and " << eqn <<
" completely overlap." << std::endl;
4604 lhs_map[std::make_pair(eqn.condition(), eqn.lhs())] = eqn;
4607 data_spec=new_specification;
4612 return type_checked_data_spec;
4627 sort_expression_list Result;
4628 for (
const variable& VarDecl: VarDecls)
4630 Result.push_front(VarDecl.sort());
4632 return reverse(Result);
4641 return atermpp::down_cast<untyped_possible_sorts>(Type).sorts().front();
4665 sort_expression_list NewTypeList;
4666 for (
const sort_expression& TypeList : s.domain())
4668 NewTypeList.push_front(replace_possible_sorts(TypeList));
4671 return function_sort(reverse(NewTypeList),replace_possible_sorts(ResultType));
4690 return HasUnknown(down_cast<
container_sort>(Type).element_sort());
4700 for (
const sort_expression& TypeList: s.domain())
4702 if (HasUnknown(TypeList))
4731 return TypeList.front();
A unordered_map class in which aterms can be stored.
An abstraction expression.
const variable_list & variables() const
abstraction(const binder_type &binding_operator, const variable_list &variables, const data_expression &body)
Constructor.
const data_expression & body() const
const binder_type & binding_operator() const
\brief Binder for bag comprehension
bag_comprehension_binder()
\brief Default constructor X3.
\brief Container type for bags
bag_container()
\brief Default constructor X3.
container_sort(const container_type &container_name, const sort_expression &element_sort)
\brief Constructor Z14.
const container_type & container_name() const
const sort_expression & element_sort() const
container_sort(const atermpp::aterm &term)
data_expression & operator=(data_expression &&) noexcept=default
sort_expression sort() const
Returns the sort of the data expression.
bool IsNotInferredL(sort_expression_list TypeList) const
bool TypeMatchL(const sort_expression_list &TypeList, const sort_expression_list &PosTypeList, sort_expression_list &result) const
bool UnFBag(sort_expression PosType, sort_expression &result) const
bool MatchIf(const function_sort &type, sort_expression &result) const
bool MatchFalseFunction(const function_sort &type, sort_expression &result) const
bool MatchListOpCons(const function_sort &type, sort_expression &result) const
bool match_fset_fbag_pick(const function_sort &type, sort_expression &result) const
bool UnifyMinType(const sort_expression &Type1, const sort_expression &Type2, sort_expression &result) const
bool MatchListOpEltAt(const function_sort &type, sort_expression &result) const
bool EqTypesA(const sort_expression &Type1, const sort_expression &Type2) const
bool UnifyElementSort(sort_expression &Arg1, sort_expression &Arg2, sort_expression &result) const
void operator()(data_equation_vector &eqns)
Yields a type checked equation list, and sets the types in the equations right. If not successful an ...
bool MatchListSetBagOpIn(const function_sort &type, sort_expression &result) const
bool match_fbag_cinsert(const function_sort &type, sort_expression &result) const
bool MatchSqrt(const function_sort &type, sort_expression &result) const
bool MatchBagOpBag2Set(const function_sort &type, sort_expression &result) const
void read_constructors_and_mappings(const function_symbol_vector &constructors, const function_symbol_vector &mappings, const function_symbol_vector &normalized_constructors)
bool MatchEqNeqComparison(const function_sort &type, sort_expression &result) const
void operator()(const variable &v, const detail::variable_context &context) const
Type checks a variable. Throws an mcrl2::runtime_error exception if the variable is not well typed.
bool InTypesL(const sort_expression_list &Type, atermpp::term_list< sort_expression_list > Types) const
sort_expression UnwindType(const sort_expression &Type) const
bool strict_type_check(const data_expression &d) const
bool MatchBagConstructor(const function_sort &type, sort_expression &result) const
bool MatchBagOpBagCount(const function_sort &type, sort_expression &result) const
sort_expression ExpandNumTypesUp(sort_expression Type) const
sort_expression ExpandNumTypesDown(sort_expression Type) const
void initialise_system_defined_functions()
sort_expression_list ExpandNumTypesUpL(const sort_expression_list &type_list) const
void add_constant(const data::function_symbol &f, const std::string &msg)
bool MatchSetBagOpUnionDiffIntersect(const core::identifier_string &data_term_name, const function_sort &type, sort_expression &result) const
bool MatchListOpSnoc(const function_sort &type, sort_expression &result) const
bool UnFSet(sort_expression PosType, sort_expression &result) const
bool MatchListOpConcat(const function_sort &type, sort_expression &result) const
void add_system_function(const data::function_symbol &f)
void TransformVarConsTypeData(data_specification &data_spec)
void add_system_constants_and_functions(const std::vector< data::function_symbol > &v)
sort_expression TraverseVarConsTypeD(const detail::variable_context &DeclaredVars, data_expression &DataTerm, const sort_expression &PosType, bool strictly_ambiguous=true, bool warn_upcasting=false, bool print_cast_error=true) const
bool IsTypeAllowedA(const sort_expression &Type, const sort_expression &PosType) const
bool MatchSetOpSetCompl(const function_sort &type, sort_expression &result) const
bool InTypesA(const sort_expression &Type, sort_expression_list Types) const
bool MaximumType(const sort_expression &Type1, const sort_expression &Type2, sort_expression &result) const
bool was_warning_upcasting
data_type_checker(const data_specification &data_spec)
make a data type checker. Throws a mcrl2::runtime_error exception if the data_specification is not we...
bool UnList(sort_expression PosType, sort_expression &result) const
bool MatchFuncUpdate(const function_sort &type, sort_expression &result) const
void add_system_constant(const data::function_symbol &f)
bool MatchSetOpSet2Bag(const function_sort &type, sort_expression &result) const
std::pair< bool, sort_expression_list > AdjustNotInferredList(const sort_expression_list &PosTypeList, const atermpp::term_list< sort_expression_list > &TypeListList) const
bool EqTypesL(sort_expression_list Type1, sort_expression_list Type2) const
sort_expression determine_allowed_type(const data_expression &d, const sort_expression &proposed_type) const
data_specification operator()() const
Yields a type checked data specification, provided typechecking was successful. If not successful an ...
void add_function(const data::function_symbol &f, const std::string &msg, bool allow_double_decls=false)
sort_expression_list GetNotInferredList(const atermpp::term_list< sort_expression_list > &TypeListList) const
void operator()(const variable_list &l, const detail::variable_context &context) const
Type checks a variable list. Throws an mcrl2::runtime_error exception if the variables are not well t...
void read_sort(const sort_expression &SortExpr)
bool MatchListOpHead(const function_sort &type, sort_expression &result) const
bool match_fset_insert(const function_sort &type, sort_expression &result) const
sort_expression_list InsertType(const sort_expression_list &TypeList, const sort_expression &Type) const
bool UnArrowProd(const sort_expression_list &ArgTypes, sort_expression PosType, sort_expression &result) const
bool TypeMatchA(const sort_expression &Type_in, const sort_expression &PosType_in, sort_expression &result) const
data_expression operator()(const data_expression &data_expr, const detail::variable_context &context) const
Type check a data expression. Throws a mcrl2::runtime_error exception if the expression is not well t...
bool IsTypeAllowedL(const sort_expression_list &TypeList, const sort_expression_list &PosTypeList) const
bool MatchSetConstructor(const function_sort &type, sort_expression &result) const
bool MatchListOpTail(const function_sort &type, sort_expression &result) const
variable UnwindType(const variable &v) const
void typecheck_variable(const data_type_checker &typechecker, const variable &v) const
const sort_expression & codomain() const
function_sort(const sort_expression_list &domain, const sort_expression &codomain)
\brief Constructor Z14.
function_sort(const atermpp::aterm &term)
const sort_expression_list & domain() const
function_symbol(const core::identifier_string &name, const sort_expression &sort)
Constructor.
function_symbol(const atermpp::aterm &term)
Constructor.
const core::identifier_string & name() const
const sort_expression & sort() const
\brief Binder for set comprehension
set_comprehension_binder()
\brief Default constructor X3.
\brief Container type for sets
set_container()
\brief Default constructor X3.
sort_expression & operator=(const sort_expression &) noexcept=default
sort_expression(const sort_expression &) noexcept=default
Move semantics.
sort_expression & operator=(sort_expression &&) noexcept=default
sort_expression(sort_expression &&) noexcept=default
const sort_specification & get_sort_specification() const
void check_basic_sort_is_declared(const basic_sort &x) const
void check_sort_is_declared(const sort_expression &x) const
\brief An untyped identifier
untyped_identifier(const atermpp::aterm &term)
const core::identifier_string & name() const
\brief Multiple possible sorts
untyped_possible_sorts(const atermpp::aterm &term)
const sort_expression_list & sorts() const
\brief Unknown sort expression
untyped_sort()
\brief Default constructor X3.
const core::identifier_string & name() const
variable & operator=(variable &&) noexcept=default
const sort_expression & sort() const
variable(const core::identifier_string &name, const sort_expression &sort)
Constructor.
variable(const atermpp::aterm &term)
Constructor.
\brief A where expression
const data_expression & body() const
const assignment_expression_list & declarations() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static bool HasUnknown(const sort_expression &Type)
static bool includes(const std::set< variable > &s1, const std::set< variable > &s2, variable &culprit)
atermpp::term_list< S > insert_sort_unique(const atermpp::term_list< S > &list, const S &el)
static bool IsPos(const core::identifier_string &Number)
static sort_expression MinType(const sort_expression_list &TypeList)
static bool IsNat(const core::identifier_string &Number)
static bool IsNumericType(const sort_expression &Type)
static sort_expression replace_possible_sorts(const sort_expression &Type)
static sort_expression_list GetVarTypes(variable_list VarDecls)
Namespace for system defined sort bag.
function_symbol difference(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
const core::identifier_string & set2bag_name()
Generate identifier Set2Bag.
const core::identifier_string & zero_function_name()
Generate identifier @zero_.
function_symbol bag2set(const sort_expression &s)
Constructor for function symbol Bag2Set.
function_symbol intersection(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
function_symbol count(const sort_expression &, const sort_expression &s0, const sort_expression &s1)
function_symbol set2bag(const sort_expression &s)
Constructor for function symbol Set2Bag.
const core::identifier_string & bag2set_name()
Generate identifier Bag2Set.
application constructor(const sort_expression &s, const data_expression &arg0, const data_expression &arg1)
Application of function symbol @bag.
core::identifier_string const & bag_enumeration_name()
Generate identifier bag_enumeration.
function_symbol constructor(const sort_expression &s)
Constructor for function symbol @bag.
const core::identifier_string & constructor_name()
Generate identifier @bag.
function_symbol in(const sort_expression &, const sort_expression &s0, const sort_expression &s1)
function_symbol union_(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
const core::identifier_string & count_name()
Generate identifier count.
bool is_bag(const sort_expression &e)
Recogniser for sort expression Bag(s)
container_sort bag(const sort_expression &s)
Constructor for sort expression Bag(S)
function_symbol zero_function(const sort_expression &s)
Constructor for function symbol @zero_.
Namespace for system defined sort bool_.
bool is_bool(const sort_expression &e)
Recogniser for sort expression Bool.
const basic_sort & bool_()
Constructor for sort expression Bool.
Namespace for system defined sort fbag.
container_sort fbag(const sort_expression &s)
Constructor for sort expression FBag(S)
const core::identifier_string & cinsert_name()
Generate identifier @fbag_cinsert.
bool is_fbag(const sort_expression &e)
Recogniser for sort expression FBag(s)
Namespace for system defined sort fset.
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
const core::identifier_string & pick_name()
Generate identifier pick.
const core::identifier_string & insert_name()
Generate identifier @fset_insert.
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Namespace for system defined sort int_.
bool is_int(const sort_expression &e)
Recogniser for sort expression Int.
const function_symbol & cint()
Constructor for function symbol @cInt.
const basic_sort & int_()
Constructor for sort expression Int.
Namespace for system defined sort list.
const core::identifier_string & rtail_name()
Generate identifier rtail.
const core::identifier_string & snoc_name()
Generate identifier <|.
const core::identifier_string & tail_name()
Generate identifier tail.
const core::identifier_string & rhead_name()
Generate identifier rhead.
const core::identifier_string & in_name()
Generate identifier in.
const core::identifier_string & head_name()
Generate identifier head.
const core::identifier_string & cons_name()
Generate identifier |>.
const core::identifier_string & concat_name()
Generate identifier ++.
const core::identifier_string & element_at_name()
Generate identifier ..
container_sort list(const sort_expression &s)
Constructor for sort expression List(S)
core::identifier_string const & list_enumeration_name()
Generate identifier list_enumeration.
bool is_list(const sort_expression &e)
Recogniser for sort expression List(s)
Namespace for system defined sort nat.
const function_symbol & cnat()
Constructor for function symbol @cNat.
const basic_sort & nat()
Constructor for sort expression Nat.
bool is_nat(const sort_expression &e)
Recogniser for sort expression Nat.
const core::identifier_string & sqrt_name()
Generate identifier sqrt.
Namespace for system defined sort pos.
bool is_pos(const sort_expression &e)
Recogniser for sort expression Pos.
const function_symbol & c1()
Constructor for function symbol @c1.
const basic_sort & pos()
Constructor for sort expression Pos.
Namespace for system defined sort real_.
const function_symbol & creal()
Constructor for function symbol @cReal.
const basic_sort & real_()
Constructor for sort expression Real.
bool is_real(const sort_expression &e)
Recogniser for sort expression Real.
Namespace for system defined sort set_.
const core::identifier_string & constructor_name()
Generate identifier @set.
bool is_set(const sort_expression &e)
Recogniser for sort expression Set(s)
core::identifier_string const & set_enumeration_name()
Generate identifier set_enumeration.
const core::identifier_string & false_function_name()
Generate identifier @false_.
const core::identifier_string & complement_name()
Generate identifier !.
function_symbol intersection(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
container_sort set_(const sort_expression &s)
Constructor for sort expression Set(S)
const core::identifier_string & intersection_name()
Generate identifier *.
function_symbol constructor(const sort_expression &s)
Constructor for function symbol @set.
function_symbol false_function(const sort_expression &s)
Constructor for function symbol @false_.
const core::identifier_string & union_name()
Generate identifier +.
function_symbol in(const sort_expression &, const sort_expression &s0, const sort_expression &s1)
function_symbol union_(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
const core::identifier_string & difference_name()
Generate identifier -.
function_symbol difference(const sort_expression &s, const sort_expression &s0, const sort_expression &s1)
function_symbol complement(const sort_expression &s)
Constructor for function symbol !.
application constructor(const sort_expression &s, const data_expression &arg0, const data_expression &arg1)
Application of function symbol @set.
bool is_structured_sort(const atermpp::aterm &x)
Returns true if the term t is a structured sort.
function_symbol less_equal(const sort_expression &s)
Constructor for function symbol <=.
bool is_set_container(const atermpp::aterm &x)
function_symbol not_equal_to(const sort_expression &s)
Constructor for function symbol !=.
bool is_application(const data_expression &t)
Returns true if the term t is an application.
bool is_list_container(const atermpp::aterm &x)
function_symbol less(const sort_expression &s)
Constructor for function symbol <.
bool is_where_clause(const atermpp::aterm &x)
Returns true if the term t is a where clause.
const core::identifier_string & function_update_name()
Generate identifier @func_update.
bool is_untyped_possible_sorts(const atermpp::aterm &x)
Returns true if the term t is an expression for multiple possible sorts.
bool is_untyped_sort(const atermpp::aterm &x)
Returns true if the term t is the unknown sort.
function_symbol less_total(const sort_expression &s)
Constructor for function symbol less_total.
bool is_abstraction(const atermpp::aterm &x)
Returns true if the term t is an abstraction.
bool is_untyped_identifier(const atermpp::aterm &x)
Returns true if the term t is an identifier.
bool is_set_comprehension_binder(const atermpp::aterm &x)
bool is_exists_binder(const atermpp::aterm &x)
function_symbol greater_equal(const sort_expression &s)
Constructor for function symbol >=.
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
bool is_lambda_binder(const atermpp::aterm &x)
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
bool is_fset_container(const atermpp::aterm &x)
bool is_basic_sort(const atermpp::aterm &x)
Returns true if the term t is a basic sort.
bool is_untyped_set_or_bag_comprehension_binder(const atermpp::aterm &x)
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
bool is_bag_container(const atermpp::aterm &x)
bool is_machine_number(const atermpp::aterm &x)
Returns true if the term t is a machine_number.
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
bool is_fbag_container(const atermpp::aterm &x)
bool is_forall_binder(const atermpp::aterm &x)
bool is_bag_comprehension_binder(const atermpp::aterm &x)
function_symbol if_(const sort_expression &s)
Constructor for function symbol if.
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
function_symbol greater(const sort_expression &s)
Constructor for function symbol >