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/>.
17
#include "PetriEngine/PQL/CTLVisitor.h"
21
namespace PetriEngine::PQL {
22
void IsCTLVisitor::_accept(const NotCondition *element) {
23
(*element)[0]->visit(*this);
24
if (_cur_type != CTLSyntaxType::BOOLEAN)
28
void IsCTLVisitor::_accept(const LogicalCondition *element) {
29
for (size_t i = 0; i < element->operands(); i++){
30
(*element)[i]->visit(*this);
31
if (_cur_type != CTLSyntaxType::BOOLEAN){
38
void IsCTLVisitor::_accept(const AndCondition *element) {
39
_accept((const LogicalCondition *) element);
42
void IsCTLVisitor::_accept(const OrCondition *element) {
43
_accept((const LogicalCondition *) element);
46
void IsCTLVisitor::_accept(const CompareCondition *element) {
47
//We are an atom. No need to check children as they are the same as CTL*
48
_cur_type = CTLSyntaxType::BOOLEAN;
51
void IsCTLVisitor::_accept(const LessThanCondition *element) {
52
_accept((const CompareCondition *) element);
55
void IsCTLVisitor::_accept(const LessThanOrEqualCondition *element) {
56
_accept((const CompareCondition *) element);
59
void IsCTLVisitor::_accept(const EqualCondition *element) {
60
_accept((const CompareCondition *) element);
63
void IsCTLVisitor::_accept(const NotEqualCondition *element) {
64
_accept((const CompareCondition *) element);
67
void IsCTLVisitor::_accept(const DeadlockCondition *element) {
68
_cur_type = CTLSyntaxType::BOOLEAN;
71
void IsCTLVisitor::_accept(const CompareConjunction *element) {
72
_cur_type = CTLSyntaxType::BOOLEAN;
75
void IsCTLVisitor::_accept(const UnfoldedUpperBoundsCondition *element) {
76
_cur_type = CTLSyntaxType::BOOLEAN;
79
void IsCTLVisitor::_accept(const EFCondition *condition) {
80
(*condition)[0]->visit(*this);
81
if (_cur_type != CTLSyntaxType::BOOLEAN)
85
void IsCTLVisitor::_accept(const EGCondition *condition) {
86
(*condition)[0]->visit(*this);
87
if (_cur_type != CTLSyntaxType::BOOLEAN)
91
void IsCTLVisitor::_accept(const AGCondition *condition) {
92
(*condition)[0]->visit(*this);
93
if (_cur_type != CTLSyntaxType::BOOLEAN)
97
void IsCTLVisitor::_accept(const AFCondition *condition) {
98
(*condition)[0]->visit(*this);
99
if (_cur_type != CTLSyntaxType::BOOLEAN)
103
void IsCTLVisitor::_accept(const EXCondition *condition) {
104
(*condition)[0]->visit(*this);
105
if (_cur_type != CTLSyntaxType::BOOLEAN)
109
void IsCTLVisitor::_accept(const AXCondition *condition) {
110
(*condition)[0]->visit(*this);
111
if (_cur_type != CTLSyntaxType::BOOLEAN)
115
void IsCTLVisitor::_accept(const EUCondition *condition) {
116
(*condition)[0]->visit(*this);
117
if (_cur_type != CTLSyntaxType::BOOLEAN)
121
void IsCTLVisitor::_accept(const AUCondition *condition) {
122
(*condition)[0]->visit(*this);
123
if (_cur_type != CTLSyntaxType::BOOLEAN)
127
void IsCTLVisitor::_accept(const ACondition *condition) {
128
(*condition)[0]->visit(*this);
129
if (_cur_type != CTLSyntaxType::PATH)
131
_cur_type = CTLSyntaxType::BOOLEAN;
134
void IsCTLVisitor::_accept(const ECondition *condition) {
135
(*condition)[0]->visit(*this);
136
if (_cur_type != CTLSyntaxType::PATH)
138
_cur_type = CTLSyntaxType::BOOLEAN;
141
void IsCTLVisitor::_accept(const GCondition *condition) {
142
(*condition)[0]->visit(*this);
143
if (_cur_type != CTLSyntaxType::BOOLEAN)
145
_cur_type = CTLSyntaxType::PATH;
148
void IsCTLVisitor::_accept(const FCondition *condition) {
149
(*condition)[0]->visit(*this);
150
if (_cur_type != CTLSyntaxType::BOOLEAN)
152
_cur_type = CTLSyntaxType::PATH;
155
void IsCTLVisitor::_accept(const XCondition *condition) {
156
(*condition)[0]->visit(*this);
157
if (_cur_type != CTLSyntaxType::BOOLEAN)
159
_cur_type = CTLSyntaxType::PATH;
162
void IsCTLVisitor::_accept(const UntilCondition *condition) {
163
(*condition)[0]->visit(*this);
164
if (_cur_type != CTLSyntaxType::BOOLEAN)
166
(*condition)[1]->visit(*this);
167
if (_cur_type != CTLSyntaxType::BOOLEAN)
169
_cur_type = CTLSyntaxType::PATH;
172
void IsCTLVisitor::_accept(const UnfoldedFireableCondition *element) {
173
_cur_type = CTLSyntaxType::BOOLEAN;
176
void IsCTLVisitor::_accept(const FireableCondition *element) {
177
_cur_type = CTLSyntaxType::BOOLEAN;
180
void IsCTLVisitor::_accept(const UpperBoundsCondition *element) {
181
_cur_type = CTLSyntaxType::BOOLEAN;
184
void IsCTLVisitor::_accept(const LivenessCondition *element) {
185
_cur_type = CTLSyntaxType::BOOLEAN;
188
void IsCTLVisitor::_accept(const KSafeCondition *element) {
189
_cur_type = CTLSyntaxType::BOOLEAN;
192
void IsCTLVisitor::_accept(const QuasiLivenessCondition *element) {
193
_cur_type = CTLSyntaxType::BOOLEAN;
196
void IsCTLVisitor::_accept(const StableMarkingCondition *element) {
197
_cur_type = CTLSyntaxType::BOOLEAN;
200
void IsCTLVisitor::_accept(const BooleanCondition *element) {
201
_cur_type = CTLSyntaxType::BOOLEAN;
204
void IsCTLVisitor::_accept(const UnfoldedIdentifierExpr *element) {
205
_cur_type = CTLSyntaxType::BOOLEAN;
208
void IsCTLVisitor::_accept(const LiteralExpr *element) {
209
_cur_type = CTLSyntaxType::BOOLEAN;
212
void IsCTLVisitor::_accept(const PlusExpr *element) {
213
_cur_type = CTLSyntaxType::BOOLEAN;
216
void IsCTLVisitor::_accept(const MultiplyExpr *element) {
217
_cur_type = CTLSyntaxType::BOOLEAN;
220
void IsCTLVisitor::_accept(const MinusExpr *element) {
221
_cur_type = CTLSyntaxType::BOOLEAN;
224
void IsCTLVisitor::_accept(const SubtractExpr *element) {
225
_cur_type = CTLSyntaxType::BOOLEAN;
228
void IsCTLVisitor::_accept(const IdentifierExpr *element) {
229
_cur_type = CTLSyntaxType::BOOLEAN;
233
void AsCTL::_accept(const NotCondition *element) {
234
(*element)[0]->visit(*this);
235
_ctl_query = std::make_shared<NotCondition>(_ctl_query);
239
void AsCTL::_acceptNary(const T *element) {
240
std::vector<Condition_ptr> children;
241
for (auto operand : *element){
242
operand->visit(*this);
243
children.push_back(_ctl_query);
245
_ctl_query = std::make_shared<T>(children);
248
void AsCTL::_accept(const AndCondition *element) {
249
AsCTL::_acceptNary(element);
252
void AsCTL::_accept(const OrCondition *element) {
253
AsCTL::_acceptNary(element);
257
std::shared_ptr<T> AsCTL::copy_compare_condition(const T *element) {
258
// we copy of sharedptr for now, but this is not safe!
259
// copy_narry_expr needs fixing.
260
return std::make_shared<T>((*element)[0], (*element)[1]);
263
void AsCTL::_accept(const LessThanCondition *element) {
264
_ctl_query = copy_compare_condition(element);
267
void AsCTL::_accept(const LessThanOrEqualCondition *element) {
268
_ctl_query = copy_compare_condition(element);
271
void AsCTL::_accept(const EqualCondition *element) {
272
_ctl_query = copy_compare_condition(element);
275
void AsCTL::_accept(const NotEqualCondition *element) {
276
_ctl_query = copy_compare_condition(element);
279
void AsCTL::_accept(const DeadlockCondition *element) {
280
_ctl_query = std::make_shared<DeadlockCondition>();
283
void AsCTL::_accept(const CompareConjunction *element) {
284
_ctl_query = std::make_shared<CompareConjunction>(*element);
287
void AsCTL::_accept(const UnfoldedUpperBoundsCondition *element) {
288
_ctl_query = std::make_shared<UnfoldedUpperBoundsCondition>(*element);
291
void AsCTL::_accept(const EFCondition *condition) {
292
(*condition)[0]->visit(*this);
293
_ctl_query = std::make_shared<EFCondition>(_ctl_query);
296
void AsCTL::_accept(const EGCondition *condition) {
297
(*condition)[0]->visit(*this);
298
_ctl_query = std::make_shared<EGCondition>(_ctl_query);
301
void AsCTL::_accept(const AGCondition *condition) {
302
(*condition)[0]->visit(*this);
303
_ctl_query = std::make_shared<AGCondition>(_ctl_query);
306
void AsCTL::_accept(const AFCondition *condition) {
307
(*condition)[0]->visit(*this);
308
_ctl_query = std::make_shared<AFCondition>(_ctl_query);
311
void AsCTL::_accept(const EXCondition *condition) {
312
(*condition)[0]->visit(*this);
313
_ctl_query = std::make_shared<EXCondition>(_ctl_query);
316
void AsCTL::_accept(const AXCondition *condition) {
317
(*condition)[0]->visit(*this);
318
_ctl_query = std::make_shared<AXCondition>(_ctl_query);
321
void AsCTL::_accept(const EUCondition *condition) {
322
(*condition)[0]->visit(*this);
323
auto first = _ctl_query;
324
(*condition)[1]->visit(*this);
325
_ctl_query = std::make_shared<EUCondition>(first, _ctl_query);
328
void AsCTL::_accept(const AUCondition *condition) {
329
(*condition)[0]->visit(*this);
330
auto first = _ctl_query;
331
(*condition)[1]->visit(*this);
332
_ctl_query = std::make_shared<AUCondition>(first, _ctl_query);
335
void AsCTL::_accept(const ACondition *condition) {
336
auto child = dynamic_cast<QuantifierCondition*>((*condition)[0].get());
337
switch (child->getPath()) {
339
(*child)[0]->visit(*this);
340
_ctl_query = std::make_shared<AGCondition>(_ctl_query);
343
(*child)[0]->visit(*this);
344
_ctl_query = std::make_shared<AXCondition>(_ctl_query);
347
(*child)[0]->visit(*this);
348
_ctl_query = std::make_shared<AFCondition>(_ctl_query);
351
(*child)[0]->visit(*this);
352
auto first = _ctl_query;
353
(*child)[1]->visit(*this);
354
_ctl_query = std::make_shared<AUCondition>(first, _ctl_query);
359
_ctl_query = nullptr;
364
void AsCTL::_accept(const ECondition *condition) {
365
auto child = dynamic_cast<QuantifierCondition*>((*condition)[0].get());
366
switch (child->getPath()) {
368
(*child)[0]->visit(*this);
369
_ctl_query = std::make_shared<EGCondition>(_ctl_query);
372
(*child)[0]->visit(*this);
373
_ctl_query = std::make_shared<EXCondition>(_ctl_query);
376
(*child)[0]->visit(*this);
377
_ctl_query = std::make_shared<EFCondition>(_ctl_query);
380
(*child)[0]->visit(*this);
381
auto first = _ctl_query;
382
(*child)[1]->visit(*this);
383
_ctl_query = std::make_shared<EUCondition>(first, _ctl_query);
388
_ctl_query = nullptr;
393
void AsCTL::_accept(const GCondition *condition) {
394
std::cerr << "Direct call to path quantifier in AsCTL GCondition" << std::endl;
396
_ctl_query = nullptr;
399
void AsCTL::_accept(const FCondition *condition) {
400
std::cerr << "Direct call to path quantifier in AsCTL FCondition" << std::endl;
402
_ctl_query = nullptr;
405
void AsCTL::_accept(const XCondition *condition) {
406
std::cerr << "Direct call to path quantifier in AsCTL XCondition" << std::endl;
408
_ctl_query = nullptr;
411
void AsCTL::_accept(const UntilCondition *condition) {
412
std::cerr << "Direct call to path quantifier in AsCTL UntilCondition" << std::endl;
414
_ctl_query = nullptr;
417
void AsCTL::_accept(const UnfoldedFireableCondition *element) {
418
_ctl_query = std::make_shared<UnfoldedFireableCondition>(*element);
422
Condition_ptr copy_condition(const T* el)
424
return std::make_shared<T>(*el);
427
void AsCTL::_accept(const FireableCondition *element) {
428
_ctl_query = copy_condition(element);
431
void AsCTL::_accept(const UpperBoundsCondition *element) {
432
_ctl_query = copy_condition(element);
435
void AsCTL::_accept(const LivenessCondition *element) {
436
_ctl_query = copy_condition(element);
439
void AsCTL::_accept(const KSafeCondition *element) {
440
_ctl_query = copy_condition(element);
443
void AsCTL::_accept(const QuasiLivenessCondition *element) {
444
_ctl_query = copy_condition(element);
447
void AsCTL::_accept(const StableMarkingCondition *element) {
448
_ctl_query = copy_condition(element);
451
void AsCTL::_accept(const BooleanCondition *element) {
452
_ctl_query = element->value ? BooleanCondition::TRUE_CONSTANT : BooleanCondition::FALSE_CONSTANT;
456
Expr_ptr AsCTL::copy_narry_expr(const T* el)
463
void AsCTL::_accept(const PlusExpr *element) {
464
_expression = copy_narry_expr(element);
467
void AsCTL::_accept(const MultiplyExpr *element) {
468
_expression = copy_narry_expr(element);
471
void AsCTL::_accept(const SubtractExpr *element) {
472
_expression = copy_narry_expr(element);
475
void AsCTL::_accept(const MinusExpr *element) {
476
(*element)[0]->visit(*this);
477
_expression = std::make_shared<MinusExpr>(_expression);
480
void AsCTL::_accept(const LiteralExpr *element) {
481
_expression = std::make_shared<LiteralExpr>(element->value());
484
void AsCTL::_accept(const IdentifierExpr *element) {
485
_expression = std::make_shared<IdentifierExpr>(*element);
488
void AsCTL::_accept(const UnfoldedIdentifierExpr *element) {
489
_expression = std::make_shared<UnfoldedIdentifierExpr>(*element);
b'\\ No newline at end of file'