9#ifndef MCRL2_SMT_UTILITIES_H
10#define MCRL2_SMT_UTILITIES_H
14#include "mcrl2/smt/native_translation.h"
15#include "mcrl2/smt/translation_error.h"
23std::string translate_identifier(
const std::string& id)
25 std::string result = id;
26 for(std::size_t i = 0; i < result.size(); i++)
39 return translate_identifier(core::pp(id));
45 auto find_result = nt.symbols.find(f);
46 return find_result != nt.symbols.end() ? find_result->second : translate_identifier(f.name());
53 if(
data::pp(cons) ==
"|>")
55 return i == 0 ?
"head" :
"tail";
58 if(translate_symbol(cons, nt) ==
"@id")
62 return "@proj-" + translate_symbol(cons, nt) +
"-" + std::to_string(i);
69 return data::function_symbol(make_projection_name(cons, i, nt), sort);
75 auto find_result = nt.special_recogniser.find(cons);
76 if(find_result != nt.special_recogniser.end())
78 return find_result->second;
81 return "is-" + translate_symbol(cons, nt);
88 return data::function_symbol(make_recogniser_name(cons, nt), sort);
94 std::queue<T> vertices_without_dependencies;
95 std::map<T, std::set<T> > reverse_dependencies;
96 for (
const auto& p: dependencies)
98 const T& node = p.first;
99 const std::set<T>& successors = p.second;
100 for (
const T& succ: successors)
102 reverse_dependencies[succ].insert(node);
105 if (successors.empty())
107 vertices_without_dependencies.push(node);
111 std::vector<T> output;
112 output.reserve(dependencies.size());
114 while (!vertices_without_dependencies.empty())
116 T vertex = vertices_without_dependencies.front();
117 vertices_without_dependencies.pop();
118 output.push_back(vertex);
120 const std::set<T>& successors = reverse_dependencies[vertex];
121 for (
const T& succ: successors)
123 dependencies[succ].erase(vertex);
124 if (dependencies[succ].empty())
126 vertices_without_dependencies.push(succ);
131 if (output.size() != dependencies.size())
133 for (
const T& node: output)
135 dependencies.erase(node);
137 assert(!dependencies.empty());
139 std::ostringstream out;
140 for(
const auto& p: dependencies)
142 out << p.first <<
", ";
144 throw translation_error(
"Dependency loop trying to resolve dependencies: {" + out.str() +
"}");
152template <
typename OutStream>
172 m_stack.push(buf.tellp());
182 assert(!m_stack.empty());
183 return buf.tellp() - m_stack.top();
186 void copy_top(
std::string& dest)
188 dest = buf.str().substr(m_stack.top(), std::string::npos);
191 template <
typename T>
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
const variable_list & variables() const
const data_expression & body() const
const container_type & container_name() const
const data_expression & lhs() const
const data_expression & condition() const
const data_expression & rhs() const
const variable_list & variables() const
data_expression & operator=(data_expression &&) noexcept=default
sort_expression sort() const
Returns the sort of the data expression.
application operator()(const data_expression &e) const
Apply a data expression to a data expression.
existential quantification.
universal quantification.
function_sort(const sort_expression_list &domain, const sort_expression &codomain)
\brief Constructor Z14.
const sort_expression & sort() const
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
const sort_expression & target_sort() const
Returns the target sort of this expression.
const sort_expression & sort() const
\brief A where expression
const data_expression & body() const
answer solve(const data::variable_list &vars, const data::data_expression &expr, const std::chrono::microseconds &timeout=std::chrono::microseconds::zero())
answer execute_and_check(const std::string &command, const std::chrono::microseconds &timeout) const
smt_solver(const data::data_specification &dataspec)
OutStream::pos_type top_size()
std::stack< typename OutStream::pos_type > m_stack
stack_outstream(OutStream &out)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
The main namespace for the aterm++ library.
atermpp::aterm_string identifier_string
String type of the LPS library. Identifier strings are represented internally as ATerms.
A collection of utilities for lazy expression construction.
data_expression implies(data_expression const &p, data_expression const &q)
Returns an expression equivalent to p implies q.
data_expression and_(data_expression const &p, data_expression const &q)
Returns an expression equivalent to p or q.
Namespace for system defined sort bool_.
const basic_sort & bool_()
Constructor for sort expression Bool.
const function_symbol & implies()
Constructor for function symbol =>.
const function_symbol & and_()
Constructor for function symbol &&.
const function_symbol & false_()
Constructor for function symbol false.
const function_symbol & or_()
Constructor for function symbol ||.
const function_symbol & not_()
Constructor for function symbol !.
const function_symbol & true_()
Constructor for function symbol true.
Namespace for system defined sort int_.
const function_symbol & pos2int()
Constructor for function symbol Pos2Int.
const function_symbol & int2nat()
Constructor for function symbol Int2Nat.
const function_symbol & nat2int()
Constructor for function symbol Nat2Int.
const function_symbol & cneg()
Constructor for function symbol @cNeg.
const function_symbol & int2pos()
Constructor for function symbol Int2Pos.
const function_symbol & cint()
Constructor for function symbol @cInt.
const basic_sort & int_()
Constructor for sort expression Int.
Namespace for system defined sort nat.
const function_symbol & c0()
Constructor for function symbol @c0.
const function_symbol & cnat()
Constructor for function symbol @cNat.
const basic_sort & nat()
Constructor for sort expression Nat.
const function_symbol & nat2pos()
Constructor for function symbol Nat2Pos.
const function_symbol & pos2nat()
Constructor for function symbol Pos2Nat.
Namespace for system defined sort pos.
const function_symbol & c1()
Constructor for function symbol @c1.
const function_symbol & cdub()
Constructor for function symbol @cDub.
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 function_symbol & pos2real()
Constructor for function symbol Pos2Real.
const function_symbol & real2nat()
Constructor for function symbol Real2Nat.
const function_symbol & real2int()
Constructor for function symbol Real2Int.
const basic_sort & real_()
Constructor for sort expression Real.
const function_symbol & nat2real()
Constructor for function symbol Nat2Real.
const function_symbol & int2real()
Constructor for function symbol Int2Real.
const function_symbol & real2pos()
Constructor for function symbol Real2Pos.
Namespace for all data library functionality.
bool is_application(const data_expression &t)
Returns true if the term t is an application.
atermpp::term_list< sort_expression > sort_expression_list
\brief list of sort_expressions
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
atermpp::term_list< variable > variable_list
\brief list of variables
application greater_equal(const data_expression &arg0, const data_expression &arg1)
Application of function symbol >=.
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
application equal_to(const data_expression &arg0, const data_expression &arg1)
Application of function symbol ==.
void translate_sort_definitions(const data::data_specification &dataspec, OutputStream &out, const native_translations &nt, data::set_identifier_generator &id_gen, std::map< data::structured_sort, std::string > &struct_name_map)
void translate_sort_definition(const std::string &sort_name, const data::sort_expression &s, const data::data_specification &dataspec, OutputStream &out, const native_translations &nt, std::map< data::structured_sort, std::string > &struct_name_map)
static const std::map< data::structured_sort, std::string > & empty_name_map()
void translate_mapping(const data::function_symbol &f, OutputStream &out, const native_translations &nt, const std::map< data::structured_sort, std::string > &snm, bool check_native=true)
static const native_translation_t pp_real_translation
void translate_equation(const data::data_equation &eq, OutputStream &out, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt)
std::string translate_symbol_disambiguate(const data::function_symbol &f, const native_translations &nt)
data::data_expression declare_variables_binder(const data::variable_list &vars, OutputStream &out, const native_translations &nt)
Declare variables to be used in binder such as exists or forall and print the declaration to out.
static const native_translation_t pp_translation
bool is_higher_order(const data::application &a)
bool is_higher_order(const data::function_symbol &f)
translate_sort_expression_traverser< Traverser, OutputStream > make_translate_sort_expression_traverser(OutputStream &out, const native_translations &nt, const std::map< data::structured_sort, std::string > &snm)
std::map< data::sort_expression, std::set< data::sort_expression > > find_sorts_and_dependencies(const data::data_specification &dataspec, std::map< data::structured_sort, std::string > &struct_name_map)
void translate_alias(const data::alias &s, OutputStream &out, const native_translations &nt, const std::map< data::structured_sort, std::string > &struct_name_map)
void translate_sort_definition(const data::basic_sort &s, const data::data_specification &dataspec, OutputStream &out, const native_translations &nt, std::map< data::structured_sort, std::string > &struct_name_map)
static const native_translation_t reconstruct_divmod
static std::set< data::sort_expression > find_dependencies(const data::data_specification &dataspec, const data::sort_expression &sort)
bool is_higher_order(const data::data_equation &eq)
void translate_native_mappings(OutputStream &out, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt, const std::map< data::structured_sort, std::string > &snm)
void translate_sort_expression(const T &x, OutputStream &o, const native_translations &nt, const std::map< data::structured_sort, std::string > &snm=detail::empty_name_map())
std::string make_projection_name(const data::function_symbol &cons, std::size_t i, const native_translations &nt)
void translate_assertion(const T &x, OutputStream &o, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt)
native_translations initialise_native_translation(const data::data_specification &dataspec)
data::function_symbol make_recogniser_func(const data::function_symbol &cons, const native_translations &nt)
data::function_symbol make_projection_func(const data::function_symbol &cons, const data::sort_expression &arg_sort, std::size_t i, const native_translations &nt)
std::string make_recogniser_name(const data::function_symbol &cons, const native_translations &nt)
void translate_data_specification(const data::data_specification &dataspec, OutputStream &o, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt)
void unfold_pattern_matching(const data::data_specification &dataspec, native_translations &nt)
void translate_variable_declaration(const Container &vars, OutputStream &o, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt)
void translate_data_expression(const T &x, OutputStream &o, std::unordered_map< data::data_expression, std::string > &c, const native_translations &nt)
std::string translate_symbol(const data::function_symbol &f, const native_translations &nt)
std::vector< T > topological_sort(std::map< T, std::set< T > > dependencies)
std::string translate_identifier(const core::identifier_string &id)
std::function< void(data::data_expression, std::function< void(std::string)>, std::function< void(data::data_expression)>)> native_translation_t
fixed_string_translation(const std::string &s)
void operator()(const data::data_expression &, const std::function< void(std::string)> &output_func, const std::function< void(data::data_expression)> &) const
const native_translations & m_native
stack_outstream< OutputStream > out
void apply(const data::where_clause &v)
void apply(const data::variable &v)
void apply(const data::application &v)
void apply(const data::forall &v)
void apply(const data::data_expression &d)
Traverser< translate_data_expression_traverser< Traverser, OutputStream > > super
translate_data_expression_traverser(OutputStream &out_, std::unordered_map< data::data_expression, std::string > &cache, const native_translations &nt)
void apply(const data::exists &v)
std::unordered_map< data::data_expression, std::string > & m_cache
void apply(const data::function_symbol &v)
void apply(const data::container_sort &s)
void apply(const data::structured_sort &s)
const std::map< data::structured_sort, std::string > & m_struct_names
translate_sort_expression_traverser(OutputStream &out_, const native_translations &nt, const std::map< data::structured_sort, std::string > &snm)
void apply(const data::basic_sort &s)
Traverser< translate_sort_expression_traverser< Traverser, OutputStream > > super
void apply(const data::function_sort &s)
const native_translations & m_native
bool is_ambiguous(const data::function_symbol &f) const
void set_native_definition(const data::function_symbol &f)
Record that the mapping and equations for f should not be translated.
bool has_native_definition(const data::function_symbol &f) const
bool has_native_definition(const data::data_equation &eq) const
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const