mCRL2
Loading...
Searching...
No Matches
print.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//
11
12#ifndef MCRL2_LPS_PRINT_H
13#define MCRL2_LPS_PRINT_H
14
15#include "mcrl2/data/parse.h"
16#include "mcrl2/lps/traverser.h"
17#include "mcrl2/process/print.h"
18
19namespace mcrl2
20{
21
22namespace lps
23{
24
25namespace detail
26{
27
28template <typename Derived>
29struct printer: public lps::add_traverser_sort_expressions<process::detail::printer, Derived>
30{
32
33 using super::enter;
34 using super::leave;
35 using super::apply;
36 using super::derived;
37 using super::print_action_declarations;
38 using super::print_assignments;
39 using super::print_condition;
40 using super::print_expression;
41 using super::print_list;
42 using super::print_variables;
43
45
48 {}
49
51 {
53 }
54
55 template <typename Container>
56 void print_numbered_list(const Container& container,
57 const std::string& separator = ", ",
58 const std::string& number_separator = "",
59 std::size_t index = 0,
60 bool print_start_separator = false,
61 bool print_empty_container = false
62 )
63 {
64 if (container.empty() && !print_empty_container)
65 {
66 return;
67 }
68 for (auto i = container.begin(); i != container.end(); ++i)
69 {
70 derived().print("\n");
71 derived().print(number_separator);
72 derived().print("%");
73 derived().print(utilities::number2string(index++));
74
75 derived().print("\n");
76 if (i == container.begin() && !print_start_separator)
77 {
78 derived().print(number_separator);
79 }
80 else
81 {
82 derived().print(separator);
83 }
84 derived().apply(*i);
85 }
86 }
87
88 void apply(const lps::deadlock& x)
89 {
90 derived().enter(x);
91 derived().print("delta");
92 if (x.has_time())
93 {
94 derived().print(" @ ");
95 print_expression(x.time(), precedence(x.time()) < core::detail::max_precedence);
96 }
97 derived().leave(x);
98 }
99
101 {
102 derived().enter(x);
103 if (x.actions().empty())
104 {
105 derived().print("tau");
106 }
107 else
108 {
109 print_list(x.actions(), "", "", "|");
110 }
111 if (x.has_time())
112 {
113 derived().print(" @ ");
114 print_expression(x.time(), precedence(x.time()) < core::detail::max_precedence);
115 }
116 derived().leave(x);
117 }
118
120 {
121 derived().enter(x);
122 print_variables(x.summation_variables(), true, true, false, "sum ", ".\n ", ",");
123 print_condition(x.condition(), " ->\n ");
124 derived().apply(x.deadlock());
125 derived().leave(x);
126 }
127
129 {
130 derived().enter(x);
131 if (x.variables().empty()) // do not print the empty distribution
132 {
133 return;
134 }
135 derived().print("dist ");
136 print_variables(x.variables(), true, true, false, "", "");
137 derived().print("[");
138 derived().apply(x.distribution());
139 derived().print("]");
140 derived().leave(x);
141 }
142
144 { }
145
147 {
148 if (x.distribution().is_defined())
149 {
150 derived().apply(x.distribution());
151 derived().print(" .\n ");
152 }
153 }
154
155 template <typename ActionSummand>
156 void print_action_summand(const ActionSummand& x)
157 {
158 derived().enter(x);
159 print_variables(x.summation_variables(), true, true, false, "sum ", ".\n ", ",");
160 print_condition(x.condition(), " ->\n ");
161 derived().apply(x.multi_action());
162 derived().print(" .\n ");
164 derived().print("P(");
165 print_assignments(x.assignments(), true, "", "", ", ");
166 derived().print(")");
167 derived().leave(x);
168 }
169
171 {
173 }
174
176 {
178 }
179
181 {
182 derived().enter(x);
183 derived().print("init P");
184 print_variables(x.expressions(), false);
185 derived().print(";");
186 derived().leave(x);
187 }
188
190 {
191 derived().enter(x);
192 derived().print("init ");
193 if (x.distribution().is_defined())
194 {
195 derived().apply(x.distribution());
196 derived().print(" . ");
197 }
198 derived().print("P");
199 print_variables(x.expressions(), false);
200 derived().print(";");
201 derived().leave(x);
202 }
203
204 // this overload is enabled for linear_process and stochastic_linear_process
205 template <typename LinearProcess>
206 void print_linear_process(const LinearProcess& x)
207 {
208 derived().enter(x);
209 derived().print("proc P");
210 print_variables(x.process_parameters(), true, true, false, "(", ")", ", ");
211
213 {
214 derived().print(" =");
215
216 std::string separator = " + ";
217 std::string number_separator = " ";
218
219 // print action summands
220 print_numbered_list(x.action_summands(), separator, number_separator, 1, false);
221
222 // print deadlock summands
223 print_numbered_list(x.deadlock_summands(), separator, number_separator, x.action_summands().size() + 1, true);
224
225 // print delta if there are no summands
226 if (x.action_summands().empty() && (x.deadlock_summands().empty()))
227 {
230 print_numbered_list(v, separator, number_separator, 1, true);
231 }
232 }
233 else
234 {
235 derived().print(" =\n ");
236
237 // print action summands
238 std::string opener = "";
239 std::string closer = "";
240 std::string separator = "\n + ";
241 print_list(x.action_summands(), opener, closer, separator);
242
243 // print deadlock summands
244 if (!x.action_summands().empty())
245 {
246 opener = separator;
247 }
248 print_list(x.deadlock_summands(), opener, closer, separator);
249
250 // print delta if there are no summands
251 if (x.action_summands().empty() && (x.deadlock_summands().empty()))
252 {
255 print_list(v, opener, closer, separator);
256 }
257 }
258
259 derived().print(";\n");
260 derived().leave(x);
261 }
262
263 void apply(const linear_process& x)
264 {
266 }
267
269 {
271 }
272
273 template <typename Specification>
274 void print_specification(const Specification& x)
275 {
276 derived().enter(x);
277 derived().apply(x.data());
278 print_action_declarations(x.action_labels(), "act ",";\n\n", ";\n ");
279 print_variables(x.global_variables(), true, true, true, "glob ", ";\n\n", ";\n ");
280 derived().apply(x.process());
281 derived().print("\n");
282 derived().apply(x.initial_process());
283 derived().print("\n");
284 derived().leave(x);
285 }
286
287 void apply(const specification& x)
288 {
290 }
291
293 {
295 }
296
297 /* void apply(const lps::state &x)
298 {
299 derived().enter(x);
300 derived().print("state(");
301 bool first = true;
302 for (lps::state::const_iterator i = x.begin(); i != x.end(); i++)
303 {
304 if (!first)
305 {
306 derived().print(", ");
307 }
308 first = false;
309 print_expression(*i);
310 }
311 derived().print(")");
312 derived().leave(x);
313 } */
314};
315
316} // namespace detail
317
320{
321 template <typename T>
322 void operator()(const T& x, std::ostream& out)
323 {
324 core::detail::apply_printer<lps::detail::printer> printer(out);
325 printer.apply(x);
326 }
327};
328
330template <typename T>
331std::string pp(const T& x)
332{
333 std::ostringstream out;
334 stream_printer()(x, out);
335 return out.str();
336}
337
338} // namespace lps
339
340} // namespace mcrl2
341
342#endif // MCRL2_LPS_PRINT_H
bool empty() const
Returns true if the list's size is 0.
Definition aterm_list.h:268
LPS summand containing a multi-action.
LPS summand containing a deadlock.
const lps::deadlock & deadlock() const
Returns the deadlock of this summand.
Represents a deadlock.
Definition deadlock.h:26
bool has_time() const
Returns true if time is available.
Definition deadlock.h:42
const data::data_expression & time() const
Returns the time.
Definition deadlock.h:49
\brief A timed multi-action
bool has_time() const
Returns true if time is available.
const process::action_list & actions() const
const data::data_expression & time() const
data::data_expression_list expressions() const
Linear process specification.
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
\brief A stochastic distribution
const data::variable_list & variables() const
bool is_defined() const
Returns true if the distribution is defined, i.e. it contains a valid distribution....
const data::data_expression & distribution() const
const stochastic_distribution & distribution() const
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
data::variable_list & summation_variables()
Returns the sequence of summation variables.
Definition summand.h:46
Parser for data specifications.
add your file description here.
const function_symbol & true_()
Constructor for function symbol true.
Definition bool.h:77
data_expression parse_data_expression(std::istream &in, const VariableContainer &variables, const data_specification &dataspec=detail::default_specification(), bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parses and type checks a data expression.
Definition parse.h:276
int precedence(const data_expression &x)
Definition print.h:415
std::string pp(const action_summand &x)
Definition lps.cpp:26
std::vector< deadlock_summand > deadlock_summand_vector
\brief vector of deadlock_summands
void number2string(std::size_t number, std::string &buffer, std::size_t start_position)
Convert a number to a string in the buffer starting at position start_position.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.
bool & print_summand_numbers()
Definition print.h:50
void print_distribution(const lps::stochastic_action_summand &x)
Definition print.h:146
void print_numbered_list(const Container &container, const std::string &separator=", ", const std::string &number_separator="", std::size_t index=0, bool print_start_separator=false, bool print_empty_container=false)
Definition print.h:56
void apply(const lps::stochastic_action_summand &x)
Definition print.h:175
void print_linear_process(const LinearProcess &x)
Definition print.h:206
void apply(const lps::deadlock &x)
Definition print.h:88
void apply(const stochastic_linear_process &x)
Definition print.h:268
void apply(const lps::action_summand &x)
Definition print.h:170
void apply(const lps::stochastic_process_initializer &x)
Definition print.h:189
void apply(const lps::stochastic_distribution &x)
Definition print.h:128
void apply(const lps::process_initializer &x)
Definition print.h:180
void print_specification(const Specification &x)
Definition print.h:274
void print_distribution(const lps::action_summand &)
Definition print.h:143
void apply(const stochastic_specification &x)
Definition print.h:292
void apply(const specification &x)
Definition print.h:287
void apply(const lps::deadlock_summand &x)
Definition print.h:119
void print_action_summand(const ActionSummand &x)
Definition print.h:156
void apply(const linear_process &x)
Definition print.h:263
void apply(const lps::multi_action &x)
Definition print.h:100
lps::add_traverser_sort_expressions< process::detail::printer, Derived > super
Definition print.h:31
Prints the object x to a stream.
Definition print.h:320
void operator()(const T &x, std::ostream &out)
Definition print.h:322