12#include "mcrl2/atermpp/aterm_io_binary.h"
13#include "mcrl2/core/load_aterm.h"
14#include "mcrl2/data/data_io.h"
15#include "mcrl2/pbes/algorithms.h"
16#include "mcrl2/pbes/detail/pbes_io.h"
17#include "mcrl2/pbes/io.h"
18#include "mcrl2/pbes/join.h"
19#include "mcrl2/pbes/parse.h"
20#include "mcrl2/pbes/normal_forms.h"
29 static std::vector<utilities::file_format> result;
32 result.emplace_back(
"pbes",
"PBES in internal format",
false);
33 result.back().add_extension(
"pbes");
34 result.emplace_back(
"text",
"PBES in textual (mCRL2) format",
true);
35 result.back().add_extension(
"txt");
36 result.emplace_back(
"bes",
"BES in internal format",
false);
37 result.back().add_extension(
"bes");
38 result.emplace_back(
"pgsolver",
"BES in PGSolver format",
true);
39 result.back().add_extension(
"gm");
40 result.back().add_extension(
"pg");
58 mCRL2log(log::verbose) <<
"Saving result in " << format.shortname() <<
" format..." << std::endl;
61 atermpp::binary_aterm_ostream(stream) << pbes;
65 save_bes_pgsolver(pbes, stream);
73 throw mcrl2::runtime_error(
"Trying to save PBES in non-PBES format (" + format.shortname() +
")");
89 mCRL2log(log::verbose) <<
"Loading PBES in " << format.shortname() <<
" format..." << std::endl;
92 atermpp::binary_aterm_istream(stream) >> pbes;
101 throw mcrl2::runtime_error(
"Trying to load PBES from non-PBES format (" + format.shortname() +
")");
116 bool welltypedness_check)
118 if (welltypedness_check)
124 format = guess_format(filename);
127 if (filename.empty() || filename ==
"-")
129 save_pbes(pbes, std::cout, format);
133 std::ofstream filestream(filename,(format.text_format()?std::ios_base::out: std::ios_base::binary));
134 if (!filestream.good())
136 throw mcrl2::runtime_error(
"Could not open file " + filename);
138 save_pbes(pbes, filestream, format);
150 const std::string& filename,
155 format = guess_format(filename);
157 if (filename.empty() || filename ==
"-")
159 load_pbes(pbes, std::cin, format);
163 std::ifstream filestream(filename,(format.text_format()?std::ios_base::in: std::ios_base::binary));
164 if (!filestream.good())
166 throw mcrl2::runtime_error(
"Could not open file " + filename);
168 load_pbes(pbes, filestream, format, core::detail::file_source(filename));
175 if (x.function() == core::detail::function_symbol_OpId())
177 return atermpp::aterm(core::detail::function_symbol_OpIdNoIndex(), x.begin(), --x.end());
185 if (x.function() == core::detail::function_symbol_OpIdNoIndex())
209 stream
>> expression;
218 return atermpp::aterm(atermpp::function_symbol(
"parameterised_boolean_equation_system", 0));
227 stream << pbes.data();
228 stream << pbes.global_variables();
229 stream << pbes.equations();
246 throw mcrl2::runtime_error(
"Stream does not contain a parameterised boolean equation system (PBES).");
250 std::set<data::variable> global_variables;
251 std::vector<pbes_equation> equations;
255 stream >> global_variables;
257 stream
>> initial_state;
259 pbes = pbes_system::pbes(data, global_variables, equations, initial_state);
267 catch (std::exception& ex)
269 mCRL2log(log::error) << ex.what() <<
"\n";
270 throw mcrl2::runtime_error(std::string(
"Error reading parameterised boolean equation system (PBES)."));
282 if (filename.empty() || filename ==
"-")
284 atermpp::binary_aterm_istream(std::cin) >> result;
288 std::ifstream from(filename, std::ifstream::in | std::ifstream::binary);
289 atermpp::binary_aterm_istream(from) >> result;
296 if (filename.empty() || filename ==
"-")
298 atermpp::binary_aterm_ostream(std::cout) << pbesspec;
302 std::ofstream to(filename, std::ofstream::out | std::ofstream::binary);
305 throw mcrl2::runtime_error(
"Could not write to filename " + filename);
307 atermpp::binary_aterm_ostream(to) << pbesspec;
317 atermpp::
aterm global_variables = atermpp::aterm(core::detail::function_symbol_GlobVarSpec(),
318 data::variable_list(p.global_variables().begin(),
319 p.global_variables().end()));
321 atermpp::aterm_list eqn_list;
322 const std::vector<pbes_equation>& eqn = p.equations();
323 for (
const auto & i : std::ranges::reverse_view(eqn))
325 atermpp::aterm a = pbes_equation_to_aterm(i);
326 eqn_list.push_front(a);
328 atermpp::
aterm equations = atermpp::aterm(core::detail::function_symbol_PBEqnSpec(), eqn_list);
329 atermpp::
aterm initial_state = atermpp::aterm(core::detail::function_symbol_PBInit(), p.initial_state());
332 result = atermpp::aterm(core::detail::function_symbol_PBES(),
333 data::detail::data_specification_to_aterm(p.data()),
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
aterm_stream_state(aterm_stream &stream)
A unordered_map class in which aterms can be stored.
function_symbol(const core::identifier_string &name, const sort_expression &sort)
Constructor.
const core::identifier_string & name() const
const sort_expression & sort() const
const pbes_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
pbes_equation(const fixpoint_symbol &symbol, const propositional_variable &variable, const pbes_expression &expr)
Constructor.
const fixpoint_symbol & symbol() const
Returns the fixpoint symbol of the equation.
const propositional_variable & variable() const
Returns the pbes variable of the equation.
parameterized boolean equation system
const propositional_variable_instantiation & initial_state() const
Returns the initial state.
bool is_well_typed() const
Checks if the PBES is well typed.
\brief A propositional variable instantiation
\brief A propositional variable declaration
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
aterm_istream & operator>>(aterm_istream &stream, aterm &term)
Read the given term from the stream, but for aterm_list we want to use a specific one that performs v...
aterm_istream & operator>>(aterm_istream &stream, aterm_transformer transformer)
Sets the given transformer to be applied to following reads.
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, data_specification &spec)
Reads a data specification from a stream.
bool is_bes(const pbes &x)
Returns true if a PBES is in BES form.
pbes load_pbes(const std::string &filename)
Loads a PBES from filename, or from stdin if filename equals "".
void save_pbes(const pbes &pbesspec, const std::string &filename)
Saves an PBES to filename, or to stdout if filename equals "".
The main namespace for the PBES library.
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, pbes &pbes)
Reads a pbes from a stream.
static atermpp::aterm remove_index_impl(const atermpp::aterm &x)
void load_pbes(pbes &pbes, std::istream &stream, utilities::file_format format, const std::string &)
Load a PBES from file.
void save_pbes(const pbes &pbes, const std::string &filename, utilities::file_format format, bool welltypedness_check)
save_pbes Saves a PBES to a file.
const utilities::file_format & pbes_format_internal_bes()
atermpp::aterm pbes_marker()
void load_pbes(pbes &pbes, const std::string &filename, utilities::file_format format)
Load pbes from file.
const utilities::file_format & pbes_format_pgsolver()
atermpp::aterm pbes_to_aterm(const pbes &p)
Conversion to atermappl.
const std::vector< utilities::file_format > & pbes_file_formats()
void save_pbes(const pbes &pbes, std::ostream &stream, utilities::file_format format)
Save a PBES in the format specified.
void complete_data_specification(pbes &)
Adds all sorts that appear in the PBES p to the data specification of p.
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, pbes_equation &equation)
const utilities::file_format & pbes_format_internal()
const utilities::file_format & pbes_format_text()
static atermpp::aterm add_index_impl(const atermpp::aterm &x)