1
/* Copyright (C) 2020 Nikolaj J. Ulrik <nikolaj@njulrik.dk>,
2
* Simon M. Virenfeldt <simon@simwir.dk>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "PetriEngine/PQL/QueryPrinter.h"
20
namespace PetriEngine {
22
void QueryPrinter::_accept(const NotCondition *element) {
24
element->operator[](0)->visit(*this);
29
void QueryPrinter::_accept(const LogicalCondition *element, const std::string &op) {
31
(*element)[0]->visit(*this);
32
for (size_t i = 1; i < element->operands(); ++i) {
33
os << " " << op << " ";
34
(*element)[i]->visit(*this);
39
void QueryPrinter::_accept(const CompareCondition *element, const std::string &op) {
41
element->getExpr1()->visit(*this);
42
os << " " << op << " ";
43
element->getExpr2()->visit(*this);
47
void QueryPrinter::_accept(const AndCondition *element) {
48
_accept(element, "and");
51
void QueryPrinter::_accept(const OrCondition *element) {
52
_accept(element, "or");
55
void QueryPrinter::_accept(const LessThanCondition *element) {
56
_accept(element, "<");
59
void QueryPrinter::_accept(const LessThanOrEqualCondition *element) {
60
_accept(element, "<=");
63
void QueryPrinter::_accept(const EqualCondition *element) {
64
_accept(element, "==");
67
void QueryPrinter::_accept(const NotEqualCondition *element) {
68
_accept(element, "!=");
71
void QueryPrinter::_accept(const DeadlockCondition *element) {
75
void QueryPrinter::_accept(const CompareConjunction *element) {
77
if (element->isNegated()) os << "not";
79
for (const auto &cons : *element) {
80
if (!first) os << " and ";
82
os << "(" << cons._lower << " <= " << cons._name << ")";
83
if (cons._lower != 0 && cons._upper != std::numeric_limits<uint32_t>::max())
85
if (cons._upper != std::numeric_limits<uint32_t>::max())
86
os << "(" << cons._upper << " >= " << cons._name << ")";
92
void QueryPrinter::_accept(const UnfoldedUpperBoundsCondition *element) {
94
auto places = element->places();
95
for (size_t i = 0; i < places.size(); ++i) {
96
if (i != 0) os << ", ";
97
os << places[i]._name;
102
void QueryPrinter::_accept(const EFCondition *condition) {
104
(*condition)[0]->visit(*this);
107
void QueryPrinter::_accept(const EGCondition *condition) {
109
(*condition)[0]->visit(*this);
112
void QueryPrinter::_accept(const AGCondition *condition) {
114
(*condition)[0]->visit(*this);
117
void QueryPrinter::_accept(const AFCondition *condition) {
119
(*condition)[0]->visit(*this);
122
void QueryPrinter::_accept(const EXCondition *condition) {
124
(*condition)[0]->visit(*this);
127
void QueryPrinter::_accept(const AXCondition *condition) {
129
(*condition)[0]->visit(*this);
132
void QueryPrinter::_accept(const EUCondition *condition) {
134
_accept((UntilCondition*) condition);
137
void QueryPrinter::_accept(const AUCondition *condition) {
139
_accept((UntilCondition*) condition);
142
void QueryPrinter::_accept(const ACondition *condition) {
144
(*condition)[0]->visit(*this);
147
void QueryPrinter::_accept(const ECondition *condition) {
149
(*condition)[0]->visit(*this);
152
void QueryPrinter::_accept(const GCondition *condition) {
154
(*condition)[0]->visit(*this);
157
void QueryPrinter::_accept(const FCondition *condition) {
159
(*condition)[0]->visit(*this);
162
void QueryPrinter::_accept(const XCondition *condition) {
164
(*condition)[0]->visit(*this);
167
void QueryPrinter::_accept(const UntilCondition *condition) {
169
condition->getCond1()->visit(*this);
171
condition->getCond2()->visit(*this);
175
void QueryPrinter::_accept(const UnfoldedFireableCondition *element) {
176
os << "is-fireable(" << element->getName() << ")";
179
void QueryPrinter::_accept(const FireableCondition *element) {
180
os << "is-fireable(" << element->getName() << ")";
184
void QueryPrinter::_accept(const UpperBoundsCondition *element) {
186
auto places = element->getPlaces();
187
for(size_t i = 0; i < places.size(); ++i)
189
if(i != 0) os << ", ";
195
void QueryPrinter::_accept(const LivenessCondition *element) {
196
const Condition_ptr& cond = element->getCompiled();
205
void QueryPrinter::_accept(const KSafeCondition *element) {
206
if (element->getCompiled()) {
207
element->getCompiled()->visit(*this);
211
element->getBound()->visit(*this);
216
void QueryPrinter::_accept(const QuasiLivenessCondition *element) {
217
const Condition_ptr& cond = element->getCompiled();
226
void QueryPrinter::_accept(const StableMarkingCondition *element) {
227
const Condition_ptr& cond = element->getCompiled();
232
os << "stable-marking";
236
void QueryPrinter::_accept(const BooleanCondition *element) {
237
os << (element->value ? "true" : "false");
240
void QueryPrinter::_accept(const UnfoldedIdentifierExpr *element) {
241
os << element->name();
244
void QueryPrinter::_accept(const LiteralExpr *element) {
245
os << element->value();
248
void QueryPrinter::_accept(const CommutativeExpr *element, const std::string &op) {
249
os << "(" << element->constant();
250
for (const auto &id: element->places()) {
251
os << " " << op << " " << id.second;
253
for (const auto &expr : element->expressions()) {
254
os << " " << op << " ";
260
void QueryPrinter::_accept(const NaryExpr *element, const std::string &op) {
262
(*element)[0]->visit(*this);
263
for(size_t i = 1; i < element->operands(); ++i)
265
os << " " << op << " ";
266
(*element)[i]->visit(*this);
271
void QueryPrinter::_accept(const PlusExpr *element) {
272
_accept((const CommutativeExpr *)element, "+");
275
void QueryPrinter::_accept(const MultiplyExpr *element) {
276
_accept((const CommutativeExpr*)element, "*");
279
void QueryPrinter::_accept(const MinusExpr *element) {
281
(*element)[0]->visit(*this);
284
void QueryPrinter::_accept(const SubtractExpr *element) {
285
_accept((const NaryExpr *)element, "-");
288
void QueryPrinter::_accept(const IdentifierExpr *element) {
289
os << element->name();
b'\\ No newline at end of file'