12#ifndef MCRL2_LPS_IS_WELL_TYPED_H
13#define MCRL2_LPS_IS_WELL_TYPED_H
15#include "mcrl2/data/detail/sequence_algorithm.h"
16#include "mcrl2/lps/detail/action_utility.h"
17#include "mcrl2/lps/stochastic_specification.h"
18#include <boost/iterator/transform_iterator.hpp>
37 error <<
"is_well_typed(" << type <<
") failed: time " << t <<
" doesn't have sort real." << std::endl;
48 error <<
"is_well_typed(" << type <<
") failed: condition " << t <<
" doesn't have sort bool." << std::endl;
57 if (!is_well_typed_container(l))
59 error <<
"is_well_typed(" << type <<
") failed: the assignments " << l <<
" are not well typed." << std::endl;
63 if (data::detail::sequence_contains_duplicates(
64 boost::make_transform_iterator(l.begin(), lhs),
65 boost::make_transform_iterator(l.end() , lhs)
69 error <<
"is_well_typed(" << type <<
") failed: data assignments " << l <<
" don't have unique left hand sides." << std::endl;
76 template <
typename Container>
79 for (
auto i = c.begin(); i != c.end(); ++i)
81 if (!is_well_typed(*i))
119 std::clog <<
"is_well_typed(data_assignment) failed: the left and right hand sides "
120 << a.lhs() <<
" and " << a.rhs() <<
" have different sorts." << std::endl;
152 check_time(d.time(),
"deadlock");
167 check_time(a.time(),
"multi_action");
176 if (!
data::
detail::unique_names(s.summation_variables()))
178 error <<
"is_well_typed(action_summand) failed: summation variables " << core::detail::print_list(s.summation_variables()) <<
" don't have unique names." << std::endl;
181 if (!check_condition(s.condition(),
"action_summand"))
189 if (!check_assignments(s.assignments(),
"action_summand"))
200 if (!check_condition(s.condition(),
"deadlock_summand"))
220 template <
typename ActionSummand>
224 if (!
data::
detail::unique_names(p.process_parameters()))
226 error <<
"is_well_typed(linear_process) failed: process parameters " << core::detail::print_list(p.process_parameters()) <<
" don't have unique names." << std::endl;
231 std::set<core::identifier_string> names;
232 for (
auto i = p.process_parameters().begin(); i != p.process_parameters().end(); ++i)
234 names.insert(i->name());
236 for (
auto i = p.action_summands().begin(); i != p.action_summands().end(); ++i)
238 if (!data::detail::check_variable_names(i->summation_variables(), names))
240 error <<
"is_well_typed(linear_process) failed: some of the names of the summation variables " << core::detail::print_list(i->summation_variables()) <<
" also appear as process parameters." << std::endl;
246 for (
auto i = p.action_summands().begin(); i != p.action_summands().end(); ++i)
250 error <<
"is_well_typed(linear_process) failed: some left hand sides of the assignments " << core::detail::print_list(i->assignments()) <<
" do not appear as process parameters." << std::endl;
256 if (!is_well_typed_container(p.action_summands()))
260 if (!is_well_typed_container(p.deadlock_summands()))
284 template <
typename LinearProcess,
typename InitialProcessExpression>
285 bool is_well_typed(
const specification_base<LinearProcess, InitialProcessExpression>& spec,
286 const std::set<data::variable>& free_variables)
const
288 std::set<data::sort_expression> declared_sorts = data::detail::make_set(spec.data().sorts());
289 std::set<process::action_label> declared_labels = data::detail::make_set(spec.action_labels());
290 auto const& action_summands = spec.process().action_summands();
293 for (
auto i = action_summands.begin(); i != action_summands.end(); ++i)
295 if (!(data::detail::check_variable_sorts(i->summation_variables(), declared_sorts)))
297 error <<
"is_well_typed(specification) failed: some of the sorts of the summation variables " << core::detail::print_list(i->summation_variables()) <<
" are not declared in the data specification " << core::detail::print_list(spec.data().sorts()) << std::endl;
303 if (!(data::detail::check_variable_sorts(spec.process().process_parameters(), declared_sorts)))
305 error <<
"is_well_typed(specification) failed: some of the sorts of the process parameters " << core::detail::print_list(spec.process().process_parameters()) <<
" are not declared in the data specification " << core::detail::print_list(spec.data().sorts()) << std::endl;
310 if (!(data::detail::check_variable_sorts(spec.global_variables(), declared_sorts)))
312 error <<
"is_well_typed(specification) failed: some of the sorts of the free variables " << core::detail::print_list(spec.global_variables()) <<
" are not declared in the data specification " << core::detail::print_list(spec.data().sorts()) << std::endl;
317 if (!(detail::check_action_label_sorts(spec.action_labels(), declared_sorts)))
319 error <<
"is_well_typed(specification) failed: some of the sorts occurring in the action labels " << core::detail::print_list(spec.action_labels()) <<
" are not declared in the data specification " << core::detail::print_list(spec.data().sorts()) << std::endl;
326 if (!(detail::check_action_labels(s.multi_action().actions(), declared_labels)))
328 error <<
"is_well_typed(specification) failed: some of the labels occurring in the actions " << core::detail::print_list(s.multi_action().actions()) <<
" are not declared in the action specification " << core::detail::print_list(spec.action_labels()) << std::endl;
332 if (!is_well_typed(spec.process()))
336 if (!spec.data().is_well_typed())
340 if (!free_variables.empty())
342 error <<
"is_well_typed(specification) failed: some of the free variables were not declared\n";
343 error <<
"declared global variables: " << core::detail::print_list(spec.global_variables()) << std::endl;
344 error <<
"occurring free variables: " << core::detail::print_list(free_variables) << std::endl;
349 if (!
data::
detail::unique_names(spec.global_variables()))
351 error <<
"is_well_typed(specification) failed: global variables " << core::detail::print_list(spec.global_variables()) <<
" don't have unique names." << std::endl;
360 std::set<data::variable> free_variables = lps::find_free_variables(spec);
361 return is_well_typed(spec, free_variables);
366 std::set<data::variable> free_variables = lps::find_free_variables(spec);
367 return is_well_typed(spec, free_variables);
370 template <
typename Term>
373 return is_well_typed(t);
390 bool result = checker(x);
393 mCRL2log(log::error) << checker.error.str();
\brief Assignment of a data expression to a variable
const data_expression & rhs() const
const variable & lhs() const
sort_expression sort() const
Returns the sort of the data expression.
const sort_expression & sort() const
Action rename specification.
process::action_label_list & action_labels()
Returns the sequence of action labels.
LPS summand containing a multi-action.
data::data_expression_list next_state(const data::variable_list &process_parameters) const
Returns the next state corresponding to this summand.
LPS summand containing a deadlock.
bool has_time() const
Returns true if time is available.
\brief A timed multi-action
bool has_time() const
Returns true if time is available.
multi_action & operator=(multi_action &&) noexcept=default
Linear process specification.
Linear process specification.
\brief An untyped multi action or data application
D_ParserTables parser_tables_mcrl2
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static data_specification const & default_specification()
bool check_assignment_variables(assignment_list const &assignments, variable_list const &variables)
Returns true if the left hand sides of assignments are contained in variables.
Namespace for system defined sort bool_.
bool is_bool(const sort_expression &e)
Recogniser for sort expression Bool.
Namespace for system defined sort real_.
bool is_real(const sort_expression &e)
Recogniser for sort expression Real.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
bool is_well_typed(const T &x)
Checks well typedness of an LPS object.
multi_action complete_multi_action(process::untyped_multi_action &x, const process::action_label_list &action_decls, const data::data_specification &data_spec=data::detail::default_specification())
bool check_well_typedness(const T &x)
Checks well typedness of an LPS object, and will print error messages to stderr.
void complete_action_rename_specification(action_rename_specification &x, const lps::stochastic_specification &spec)
process::untyped_multi_action parse_multi_action_new(const std::string &text)
multi_action complete_multi_action(process::untyped_multi_action &x, multi_action_type_checker &typechecker, const data::data_specification &data_spec=data::detail::default_specification())
action_rename_specification parse_action_rename_specification_new(const std::string &text)
The main namespace for the LPS library.
std::string pp(const lps::stochastic_specification &x, bool arg0)
std::set< data::variable > find_all_variables(const lps::linear_process &x)
std::string pp(const lps::specification &x, bool arg0)
std::set< data::sort_expression > find_sort_expressions(const lps::stochastic_specification &x)
std::string pp_extended(const lps::stochastic_specification &x, const std::string &process_name, bool precedence_aware=true)
std::set< process::action_label > find_action_labels(const lps::stochastic_specification &x)
std::set< data::variable > find_free_variables(const lps::stochastic_specification &x)
std::string pp(const lps::stochastic_distribution &x, bool arg0)
std::string pp_extended(const stochastic_specification &x, const std::string &process_name, bool precedence_aware, bool summand_numbers)
std::set< data::variable > find_all_variables(const lps::multi_action &x)
Returns all variables inside a multi-action.
std::set< data::variable > find_all_variables(const lps::stochastic_specification &x)
bool check_well_typedness(const specification &x)
std::set< data::variable > find_free_variables(const lps::linear_process &x)
bool check_well_typedness(const linear_process &x)
std::set< data::function_symbol > find_function_symbols(const lps::stochastic_specification &x)
std::string pp_extended(const specification &x, const std::string &process_name, bool precedence_aware, bool summand_numbers)
std::set< process::action_label > find_action_labels(const lps::process_initializer &x)
std::set< data::variable > find_free_variables(const lps::specification &x)
multi_action typecheck_multi_action(process::untyped_multi_action &mult_act, const data::data_specification &data_spec, const process::action_label_list &action_decls)
Type check a multi action Throws an exception if something went wrong.
void normalize_sorts(lps::specification &x, const data::sort_specification &)
std::set< data::variable > find_free_variables(const lps::deadlock &x)
std::string pp(const lps::deadlock_summand &x, bool arg0)
std::set< process::action_label > find_action_labels(const lps::linear_process &x)
lps::multi_action normalize_sorts(const lps::multi_action &x, const data::sort_specification &sortspec)
std::set< data::variable > find_free_variables(const lps::stochastic_linear_process &x)
multi_action typecheck_multi_action(process::untyped_multi_action &mult_act, multi_action_type_checker &typechecker)
Type check a multi action Throws an exception if something went wrong.
std::set< data::function_symbol > find_function_symbols(const lps::specification &x)
std::string pp(const lps::stochastic_linear_process &x, bool arg0)
std::set< data::variable > find_free_variables(const lps::stochastic_process_initializer &x)
std::set< data::variable > find_free_variables(const lps::multi_action &x)
std::string pp(const lps::deadlock &x, bool arg0)
void normalize_sorts(lps::stochastic_specification &x, const data::sort_specification &)
std::set< data::variable > find_free_variables(const lps::process_initializer &x)
std::string pp(const lps::stochastic_action_summand &x, bool arg0)
std::string pp(const lps::stochastic_process_initializer &x, bool arg0)
std::string pp(const lps::linear_process &x, bool arg0)
std::string pp(const lps::multi_action &x, bool arg0)
std::set< data::sort_expression > find_sort_expressions(const lps::specification &x)
std::string pp(const lps::action_summand &x, bool arg0)
std::set< data::variable > find_all_variables(const lps::specification &x)
bool check_well_typedness(const stochastic_specification &x)
std::set< data::variable > find_all_variables(const lps::deadlock &x)
action_rename_specification typecheck_action_rename_specification(const action_rename_specification &arspec, const lps::stochastic_specification &lpsspec)
Type checks an action rename specification.
std::set< data::variable > find_all_variables(const lps::stochastic_linear_process &x)
bool check_well_typedness(const stochastic_linear_process &x)
lps::multi_action translate_user_notation(const lps::multi_action &x)
std::set< core::identifier_string > find_identifiers(const lps::stochastic_specification &x)
std::set< core::identifier_string > find_identifiers(const lps::specification &x)
std::set< process::action_label > find_action_labels(const lps::specification &x)
std::string pp(const lps::process_initializer &x, bool arg0)
The main namespace for the Process library.
lps::action_rename_specification parse_ActionRenameSpec(const core::parse_node &node) const
action_rename_actions(const core::parser &parser_)
Function object for applying a substitution to LPS data types.
bool is_well_typed(const linear_process_base< ActionSummand > &p) const
Checks well typedness of a linear process.
bool is_well_typed(const process::action &a) const
Traverses an action.
bool is_well_typed(const action_summand &s) const
Checks well typedness of a summand.
bool check_time(const data::data_expression &t, const std::string &type) const
Checks if the sort of t has type real.
bool is_well_typed(const data::assignment &a) const
Traverses an assignment.
bool check_condition(const data::data_expression &t, const std::string &type) const
Checks if the sort of t has type bool.
bool operator()(const Term &t) const
bool is_well_typed(const stochastic_specification &spec) const
bool is_well_typed(const data::variable &d) const
Checks well typedness of a variable.
bool check_assignments(const data::assignment_list &l, const std::string &type) const
Checks if the assignments are well typed and have unique left hand sides.
bool is_well_typed(const specification &spec) const
bool is_well_typed(const data::sort_expression &d) const
Checks well typedness of a sort expression.
bool is_well_typed_container(const Container &c) const
Checks well typedness of the elements of a container.
bool is_well_typed(const process::action_label &d) const
Traverses an action label.
bool is_well_typed(const specification_base< LinearProcess, InitialProcessExpression > &spec, const std::set< data::variable > &free_variables) const
Checks well typedness of a linear process specification.
bool is_well_typed(const deadlock &d) const
Checks well typedness of a deadlock.
bool is_well_typed(const data::data_expression &d) const
Checks well typedness of a data expression.
bool is_well_typed(const deadlock_summand &s) const
Checks well typedness of a summand.
bool is_well_typed(const multi_action &a) const
Checks well typedness of a multi-action.
process::untyped_multi_action parse_MultAct(const core::parse_node &node) const
multi_action_actions(const core::parser &parser_)