mCRL2
Loading...
Searching...
No Matches
load_aterm.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \file mcrl2/core/load_aterm.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_CORE_LOAD_ATERM_H
13#define MCRL2_CORE_LOAD_ATERM_H
14
15#include "mcrl2/atermpp/aterm_io_binary.h"
16#include "mcrl2/atermpp/aterm_io_text.h"
17
18namespace mcrl2::core
19{
20
21namespace detail {
22
23inline
25{
26 if (filename.empty() || filename == "-")
27 {
28 return "standard input";
29 }
30 return filename;
31}
32
33} // namespace detail
34
35/// \brief Attempts to read an aterm from a stream.
36/// \param[in] stream The stream from which the term is read.
37/// \param[in] binary A boolean indicating whether the stream is in binary of textual format.
38/// \param[in] format The format that is being read (for example "LPS" or "PBES").
39/// \param[in] source The source from which the stream originates (the empty string is used for an unknown source).
40/// \param[in] transformer A funtion that is applied to every subterm of the read term.
41/// \exception Throws a mcrl2 runtime error when an error occurs when reading the term.
42inline
43atermpp::aterm load_aterm(std::istream& stream,
44 bool binary = true,
45 const std::string& format = "aterm",
46 const std::string& source = "",
47 atermpp::aterm_transformer transformer = atermpp::identity)
48{
49 atermpp::aterm result;
50 try
51 {
52 if (binary)
53 {
54 atermpp::binary_aterm_istream(stream) >> transformer >> result;
55 }
56 else
57 {
58 atermpp::text_aterm_istream(stream) >> transformer >> result;
59 }
60 }
61 catch (std::exception &e)
62 {
63 if (source.empty())
64 {
65 throw mcrl2::runtime_error("Failed to read a valid " + format + " from the input.\n" + e.what());
66 }
67 else
68 {
69 throw mcrl2::runtime_error("Failed to read a valid " + format + " from the input " + source + ".\n" + e.what());
70 }
71 }
72 return result;
73}
74
75} // namespace mcrl2::core
76
77#endif // MCRL2_CORE_LOAD_ATERM_H
A list of aterm objects.
Definition aterm_list.h:26
A unordered_map class in which aterms can be stored.
\brief A sort alias
Definition alias.h:23
\brief A basic sort
Definition basic_sort.h:25
basic_sort(const atermpp::aterm &term)
Definition basic_sort.h:34
\brief A container sort
const container_type & container_name() const
const sort_expression & element_sort() const
container_sort(const atermpp::aterm &term)
data_specification(const basic_sort_vector &sorts, const alias_vector &aliases, const function_symbol_vector &constructors, const function_symbol_vector &user_defined_mappings, const data_equation_vector &user_defined_equations)
Constructor from its members.
bool is_well_typed() const
Returns true if.
bool is_certainly_finite(const sort_expression &s) const
Checks whether a sort is certainly finite.
bool is_finite(const container_sort &s)
bool is_finite(const basic_sort &s)
bool is_finite_aux(const sort_expression &s)
bool is_finite(const sort_expression &s)
std::set< sort_expression > m_visiting
bool is_finite(const function_sort &s)
const data_specification & m_specification
finiteness_helper(const data_specification &specification)
bool is_finite(const structured_sort &s)
\brief Container type for finite sets
fset_container()
\brief Default constructor X3.
\brief A function sort
const sort_expression & codomain() const
function_sort(const atermpp::aterm &term)
const sort_expression_list & domain() const
\brief Container type for sets
set_container()
\brief Default constructor X3.
\brief A sort expression
sort_expression & operator=(const sort_expression &) noexcept=default
sort_expression(const sort_expression &) noexcept=default
Move semantics.
void add_system_defined_sort(const sort_expression &s)
Adds a sort to this specification, and marks it as system defined.
void sorts_are_not_necessarily_normalised_anymore() const
void import_system_defined_sort(const sort_expression &sort)
Adds the system defined sorts in a sequence. The second argument is used to check which sorts are add...
structured_sort(const atermpp::aterm &term)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
aterm identity(const aterm &x)
The default transformer that maps each term to itself.
Definition aterm_io.h:26
std::string file_source(const std::string &filename)
Definition load_aterm.h:24
atermpp::aterm load_aterm(std::istream &stream, bool binary=true, const std::string &format="aterm", const std::string &source="", atermpp::aterm_transformer transformer=atermpp::identity)
Attempts to read an aterm from a stream.
Definition load_aterm.h:43
Namespace for system defined sort bag.
Definition bag1.h:35
bool is_bag(const sort_expression &e)
Recogniser for sort expression Bag(s)
Definition bag1.h:52
Namespace for system defined sort bool_.
Definition bool.h:29
const basic_sort & bool_()
Constructor for sort expression Bool.
Definition bool.h:41
Namespace for system defined sort fbag.
Definition fbag1.h:34
container_sort fbag(const sort_expression &s)
Constructor for sort expression FBag(S)
Definition fbag1.h:40
bool is_fbag(const sort_expression &e)
Recogniser for sort expression FBag(s)
Definition fbag1.h:51
Namespace for system defined sort fset.
Definition fset1.h:32
bool is_fset(const sort_expression &e)
Recogniser for sort expression FSet(s)
Definition fset1.h:49
container_sort fset(const sort_expression &s)
Constructor for sort expression FSet(S)
Definition fset1.h:38
Namespace for system defined sort int_.
const basic_sort & int_()
Constructor for sort expression Int.
Definition int1.h:44
Namespace for system defined sort list.
Definition list1.h:33
bool is_list(const sort_expression &e)
Recogniser for sort expression List(s)
Definition list1.h:50
Namespace for system defined sort nat.
const basic_sort & nat()
Constructor for sort expression Nat.
Definition nat1.h:43
const basic_sort & natpair()
Constructor for sort expression @NatPair.
Definition nat1.h:72
Namespace for system defined sort pos.
const basic_sort & pos()
Constructor for sort expression Pos.
Definition pos1.h:42
Namespace for system defined sort real_.
const basic_sort & real_()
Constructor for sort expression Real.
Definition real1.h:45
Namespace for system defined sort set_.
Definition set1.h:33
bool is_set(const sort_expression &e)
Recogniser for sort expression Set(s)
Definition set1.h:50
container_sort set_(const sort_expression &s)
Constructor for sort expression Set(S)
Definition set1.h:39
bool is_structured_sort(const atermpp::aterm &x)
Returns true if the term t is a structured sort.
static sort_expression find_normal_form(const sort_expression &e, const std::multimap< sort_expression, sort_expression > &map1, std::set< sort_expression > sorts_already_seen=std::set< sort_expression >())
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.
bool is_container_sort(const atermpp::aterm &x)
Returns true if the term t is a container sort.
bool is_basic_sort(const atermpp::aterm &x)
Returns true if the term t is a basic sort.
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.