mCRL2
Loading...
Searching...
No Matches
match_tree.h
Go to the documentation of this file.
1// Author(s): Muck van Weerdenburg/Jan Friso Groote
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//
10
11#ifndef MCRL2_DATA_MATCH_TREE_H
12#define MCRL2_DATA_MATCH_TREE_H
13
17
18namespace mcrl2
19{
20namespace data
21{
22namespace detail
23{
24
27{
28 public:
31 {}
32
35 atermpp::aterm(v)
36 {
37 assert(is_variable(v) || v.type_is_int());
38 }
39};
40
42
44{
45 public:
49 {}
50
53 atermpp::aterm(t)
54 {
55 assert(!is_defined() || isS() || isA() || isM() || isF() || isMachineNumber() ||
56 isN() || isD() || isR () || isC() || isX() || isRe() ||
57 isCRe() || isMe());
58 }
59
60 protected:
62 {
63 static atermpp::function_symbol afunUndefined("@@Match_tree_dummy",0); // Undefined match term. Used as default match term
64 return afunUndefined;
65 }
66
68 {
69 static atermpp::function_symbol afunS("@@S",2); // Store term ( target_variable, result_tree )
70 return afunS;
71 }
72
74 {
75 static atermpp::function_symbol afunA("@@A",1); // Rewrite argument ( number of an argument as an aterm_int )
76 return afunA;
77 }
78
79
81 {
82 static atermpp::function_symbol afunM("@@M",3); // Match term ( match_variable, true_tree , false_tree )
83 return afunM;
84 }
85
87 {
88 static atermpp::function_symbol afunF("@@F",3); // Match function ( match_function, true_tree, false_tree )
89 return afunF;
90 }
91
93 {
94 static atermpp::function_symbol afunNumber("@@MachineNumber",3); // Match function ( match_function, true_tree, false_tree )
95 return afunNumber;
96 }
97
99 {
100 static atermpp::function_symbol afunN("@@N",1); // Go to next parameter ( result_tree )
101 return afunN;
102 }
103
105 {
106 static atermpp::function_symbol afunD("@@D",1); // Go down a level ( result_tree )
107 return afunD;
108 }
109
111 {
112 static atermpp::function_symbol afunR("@@R",1); // End of tree ( matching_rule )
113 return afunR;
114 }
115
117 {
118 static atermpp::function_symbol afunC("@@C",3); // Check condition ( condition, true_tree, false_tree )
119 return afunC;
120 }
121
123 {
124 static atermpp::function_symbol afunX("@@X",0); // End of tree
125 return afunX;
126 }
127
129 {
130 static atermpp::function_symbol afunRe("@@Re",2); // End of tree ( matching_rule , vars_of_rule)
131 return afunRe;
132 }
133
135 {
136 static atermpp::function_symbol afunCRe("@@CRe",4); // End of tree ( condition, matching_rule, vars_of_condition, vars_of_rule )
137 return afunCRe;
138 }
139
141 {
142 static atermpp::function_symbol afunMe("@@Me",2); // Match term ( match_variable, variable_index )
143 return afunMe;
144 }
145
146 public:
147 bool is_defined() const
148 {
149 return this->function()!=afunUndefined();
150 }
151
152 bool isS() const
153 {
154 return this->function()==afunS();
155 }
156
157 bool isA() const
158 {
159 return this->function()==afunA();
160 }
161
162 bool isM() const
163 {
164 return this->function()==afunM();
165 }
166
167 bool isF() const
168 {
169 return this->function()==afunF();
170 }
171
172 bool isMachineNumber() const
173 {
174 return this->function()==afunMachineNumber();
175 }
176
177 bool isN() const
178 {
179 return this->function()==afunN();
180 }
181
182 bool isD() const
183 {
184 return this->function()==afunD();
185 }
186
187 bool isR() const
188 {
189 return this->function()==afunR();
190 }
191
192 bool isC() const
193 {
194 return this->function()==afunC();
195 }
196
197 bool isX() const
198 {
199 return this->function()==afunX();
200 }
201
202 bool isRe() const
203 {
204 return this->function()==afunRe();
205 }
206
207 bool isCRe() const
208 {
209 return this->function()==afunCRe();
210 }
211
212 bool isMe() const
213 {
214 return this->function()==afunMe();
215 }
216};
217
218// Store term ( target_variable, result_tree )
220{
221 public:
223 {}
224
226 : match_tree(t)
227 {
228 assert(isS());
229 }
230
232 : match_tree(atermpp::aterm(afunS(),target_variable,result_tree))
233 {}
234
236 {
237 return atermpp::down_cast<const variable>((*this)[0]);
238 }
239
240 const match_tree& subtree() const
241 {
242 return atermpp::down_cast<const match_tree>((*this)[1]);
243 }
244};
245
246// Rewrite argument ( a number of an arguments as a aterm_int )
247
249{
250 public:
252 {}
253
255 : match_tree(t)
256 {
257 assert(isA());
258 }
259
260 match_tree_A(const std::size_t n)
261 : match_tree(atermpp::aterm(afunA(),atermpp::aterm_int(n)))
262 {}
263
264 std::size_t variable_index() const
265 {
266 return atermpp::down_cast<const atermpp::aterm_int>((*this)[0]).value();
267 }
268};
269
270
271// Match term ( match_variable, true_tree , false_tree )
273{
274 public:
276 {}
277
279 : match_tree(t)
280 {
281 assert(isM());
282 }
283
286 {}
287
289 {
290 return atermpp::down_cast<const variable>((*this)[0]);
291 }
292
293 const match_tree& true_tree() const
294 {
295 return atermpp::down_cast<const match_tree>((*this)[1]);
296 }
297
298 const match_tree& false_tree() const
299 {
300 return atermpp::down_cast<const match_tree>((*this)[2]);
301 }
302};
303
304// Match function ( match_function, true_tree, false_tree )
306{
307 public:
309 {}
310
312 : match_tree(t)
313 {
314 assert(isF());
315 }
316
319 {}
320
322 {
323 return atermpp::down_cast<const data::function_symbol>((*this)[0]);
324 }
325
326 const match_tree& true_tree() const
327 {
328 return atermpp::down_cast<const match_tree>((*this)[1]);
329 }
330
331 const match_tree& false_tree() const
332 {
333 return atermpp::down_cast<const match_tree>((*this)[2]);
334 }
335};
336
337// Match function ( match_function, true_tree, false_tree )
339{
340 public:
342 {}
343
345 match_tree(t)
346 {
347 assert(isMachineNumber());
348 }
349
352 {}
353
355 {
356 return atermpp::down_cast<const data::machine_number>((*this)[0]);
357 }
358
359 const match_tree& true_tree() const
360 {
361 return atermpp::down_cast<const match_tree>((*this)[1]);
362 }
363
364 const match_tree& false_tree() const
365 {
366 return atermpp::down_cast<const match_tree>((*this)[2]);
367 }
368};
369
370
371// Go to next parameter ( result_tree )
373{
374 public:
376 {}
377
379 : match_tree(t)
380 {
381 assert(isN());
382 }
383
387 match_tree_N(const match_tree& result_tree, std::size_t)
388 : match_tree(atermpp::aterm(afunN(),result_tree))
389 {}
390
391 const match_tree& subtree() const
392 {
393 return atermpp::down_cast<const match_tree>((*this)[0]);
394 }
395};
396
397// Go down a level ( result_tree )
399{
400 public:
402 {}
403
405 : match_tree(t)
406 {
407 assert(isD());
408 }
409
413 match_tree_D(const match_tree& result_tree, std::size_t)
414 : match_tree(atermpp::aterm(afunD(),result_tree))
415 {}
416
417 const match_tree& subtree() const
418 {
419 return atermpp::down_cast<const match_tree>((*this)[0]);
420 }
421};
422
423// End of tree ( matching_rule )
425{
426
427 public:
429 {}
430
432 : match_tree(t)
433 {
434 assert(isR());
435 }
436
439 {}
440
441 const data_expression& result() const
442 {
443 return atermpp::down_cast<const data_expression>((*this)[0]);
444 }
445};
446
447// Check condition ( condition, true_tree, false_tree )
449{
450 public:
452 {}
453
455 : match_tree(t)
456 {
457 assert(isC());
458 }
459
462 {}
463
465 {
466 return atermpp::down_cast<const data_expression>((*this)[0]);
467 }
468
469 const match_tree& true_tree() const
470 {
471 return atermpp::down_cast<const match_tree>((*this)[1]);
472 }
473
474 const match_tree& false_tree() const
475 {
476 return atermpp::down_cast<const match_tree>((*this)[2]);
477 }
478};
479
480// End of tree
482{
483 public:
485 : match_tree(t)
486 {
487 assert(isX());
488 }
489
492 {}
493};
494
495// End of tree ( matching_rule , vars_of_rule)
496// The var_of_rule is a list with variables and aterm_ints.
498{
499 public:
501 {}
502
504 : match_tree(t)
505 {
506 assert(isRe());
507 }
508
511 {}
512
513 const data_expression& result() const
514 {
515 return atermpp::down_cast<const data_expression>((*this)[0]);
516 }
517
519 {
520 return atermpp::down_cast<const variable_or_number_list>((*this)[1]);
521 }
522};
523
524// End of tree ( condition, matching_rule, vars_of_condition, vars_of_rule )
525// The last two parameters consist of a list with variables and numbers.
527{
528 public:
530 {}
531
533 : match_tree(t)
534 {
535 assert(isCRe());
536 }
537
539 : match_tree(atermpp::aterm(afunCRe(),condition,result,vars_condition,vars_rule))
540 {}
541
543 {
544 return atermpp::down_cast<const data_expression>((*this)[0]);
545 }
546
547 const data_expression& result() const
548 {
549 return atermpp::down_cast<const data_expression>((*this)[1]);
550 }
551
553 {
554 return atermpp::down_cast<const variable_or_number_list>((*this)[2]);
555 }
556
558 {
559 return atermpp::down_cast<const variable_or_number_list>((*this)[3]);
560 }
561};
562
563// Match term ( match_variable, variable_index )
565{
566 public:
568 {}
569
571 : match_tree(t)
572 {
573 assert(isMe());
574 }
575
578 {}
579
581 {
582 return atermpp::down_cast<const variable>((*this)[0]);
583 }
584
585 std::size_t variable_index() const
586 {
587 return (atermpp::down_cast<const atermpp::aterm_int>((*this)[1])).value();
588 }
589};
590
591typedef atermpp::term_list < match_tree > match_tree_list;
592typedef std::vector < match_tree > match_tree_vector;
593typedef atermpp::term_list < match_tree_list > match_tree_list_list;
594typedef atermpp::term_list < match_tree_list_list > match_tree_list_list_list;
595
596// Structure for build_tree parameters
598{
599public:
600 match_tree_list_list Flist; // List of sequences of which the first action is an F
601 match_tree_list_list Slist; // List of sequences of which the first action is an S
602 match_tree_list_list Mlist; // List of sequences of which the first action is an M
603 match_tree_list_list_list stack; // Stack to maintain the sequences that do not have to
604 // do anything in the current term
605 match_tree_list_list upstack; // List of sequences that have done an F at the current
606 // level
607
608 // Initialise.
610 : Flist(),
611 Slist(),
612 Mlist(),
614 upstack()
615
616 {
617 }
618};
619
620
621inline
622std::ostream& operator<<(std::ostream& s, const match_tree& t)
623{
624 using atermpp::down_cast;
625 if (t.isS())
626 {
627 const match_tree_S& tS = down_cast<match_tree_S>(t);
628 s << "@@S(" << tS.target_variable() << ", " << tS.subtree() << ")";
629 }
630 else
631 if (t.isA())
632 {
633 const match_tree_A& tA = down_cast<match_tree_A>(t);
634 s << "@@A(" << tA.variable_index() << ")";
635 }
636 else
637 if (t.isM())
638 {
639 const match_tree_M& tM = down_cast<match_tree_M>(t);
640 s << "@@M(" << tM.match_variable() << ", " << tM.true_tree() << ", " << tM.false_tree() << ")";
641 }
642 else
643 if (t.isF())
644 {
645 const match_tree_F& tF = down_cast<match_tree_F>(t);
646 s << "@@F(" << tF.function() << ", " << tF.true_tree() << ", " << tF.false_tree() << ")";
647 }
648 else
649 if (t.isMachineNumber())
650 {
651 const match_tree_MachineNumber& tM = down_cast<match_tree_MachineNumber>(t);
652 s << "@@MachineNumber(" << tM.function() << ", " << tM.true_tree() << ", " << tM.false_tree() << ")";
653 }
654 else
655 if (t.isN())
656 {
657 const match_tree_N& tN = down_cast<match_tree_N>(t);
658 s << "@@N(" << tN.subtree() << ")";
659 }
660 else
661 if (t.isD())
662 {
663 const match_tree_D& tD = down_cast<match_tree_D>(t);
664 s << "@@D(" << tD.subtree() << ")";
665 }
666 else
667 if (t.isR())
668 {
669 const match_tree_R& tR = down_cast<match_tree_R>(t);
670 s << "@@R(" << tR.result() << ")";
671 }
672 else
673 if (t.isC())
674 {
675 const match_tree_C& tC = down_cast<match_tree_C>(t);
676 s << "@@C(" << tC.condition() << ", " << tC.true_tree() << ", " << tC.false_tree() << ")";
677 }
678 else
679 if (t.isX())
680 {
681 s << "@@X";
682 }
683 else
684 if (t.isRe())
685 {
686 const match_tree_Re& tRe = down_cast<match_tree_Re>(t);
687 s << "@@Re(" << tRe.result() << ", " << tRe.variables() << ")";
688 }
689 else
690 if (t.isCRe())
691 {
692 const match_tree_CRe& tCRe = down_cast<match_tree_CRe>(t);
693 s << "@@CRe(" << tCRe.condition() << ", " << tCRe.result() << ", "
694 << tCRe.variables_condition() << ", " << tCRe.variables_result() << ")";
695 }
696 else
697 if (t.isMe())
698 {
699 const match_tree_Me& tMe = down_cast<match_tree_Me>(t);
700 s << "@@Me(" << tMe.match_variable() << ", " << tMe.variable_index() << ")";
701 }
702 return s;
703}
704
705} // namespace detail
706
707} // namespace data
708
709} // namespace mcrl2
710
711#endif // MCRL2_DATA_MATCH_TREE_H
aterm()
Default constructor.
Definition aterm.h:48
const function_symbol & function() const
Returns the function symbol belonging to an aterm.
Definition aterm.h:144
A list of aterm objects.
Definition aterm_list.h:24
bool type_is_int() const noexcept
Dynamic check whether the term is an aterm_int.
Definition aterm_core.h:63
match_tree_list_list Slist
Definition match_tree.h:601
match_tree_list_list upstack
Definition match_tree.h:605
match_tree_list_list Flist
Definition match_tree.h:600
match_tree_list_list Mlist
Definition match_tree.h:602
match_tree_list_list_list stack
Definition match_tree.h:603
std::size_t variable_index() const
Definition match_tree.h:264
match_tree_A(const std::size_t n)
Definition match_tree.h:260
match_tree_A(const atermpp::aterm &t)
Definition match_tree.h:254
match_tree_CRe(const data_expression &condition, const data_expression &result, const variable_or_number_list &vars_condition, const variable_or_number_list &vars_rule)
Definition match_tree.h:538
match_tree_CRe(const atermpp::aterm &t)
Definition match_tree.h:532
const variable_or_number_list & variables_condition() const
Definition match_tree.h:552
const data_expression & condition() const
Definition match_tree.h:542
const data_expression & result() const
Definition match_tree.h:547
const variable_or_number_list & variables_result() const
Definition match_tree.h:557
const data_expression & condition() const
Definition match_tree.h:464
match_tree_C(const atermpp::aterm &t)
Definition match_tree.h:454
const match_tree & false_tree() const
Definition match_tree.h:474
match_tree_C(const data_expression &condition, const match_tree &true_tree, const match_tree &false_tree)
Definition match_tree.h:460
const match_tree & true_tree() const
Definition match_tree.h:469
match_tree_D(const atermpp::aterm &t)
Definition match_tree.h:404
const match_tree & subtree() const
Definition match_tree.h:417
match_tree_D(const match_tree &result_tree, std::size_t)
Definition match_tree.h:413
match_tree_F(const data::function_symbol &function, const match_tree &true_tree, const match_tree &false_tree)
Definition match_tree.h:317
const data::function_symbol & function() const
Definition match_tree.h:321
const match_tree & false_tree() const
Definition match_tree.h:331
const match_tree & true_tree() const
Definition match_tree.h:326
match_tree_F(const atermpp::aterm &t)
Definition match_tree.h:311
const match_tree & false_tree() const
Definition match_tree.h:298
const match_tree & true_tree() const
Definition match_tree.h:293
const variable & match_variable() const
Definition match_tree.h:288
match_tree_M(const atermpp::aterm &t)
Definition match_tree.h:278
match_tree_M(const variable &match_variable, const match_tree &true_tree, const match_tree &false_tree)
Definition match_tree.h:284
match_tree_MachineNumber(const atermpp::aterm &t)
Definition match_tree.h:344
match_tree_MachineNumber(const data::machine_number &mn, const match_tree &true_tree, const match_tree &false_tree)
Definition match_tree.h:350
const data::machine_number & number() const
Definition match_tree.h:354
const variable & match_variable() const
Definition match_tree.h:580
match_tree_Me(const variable &match_variable, const std::size_t variable_index)
Definition match_tree.h:576
std::size_t variable_index() const
Definition match_tree.h:585
match_tree_Me(const atermpp::aterm &t)
Definition match_tree.h:570
match_tree_N(const atermpp::aterm &t)
Definition match_tree.h:378
const match_tree & subtree() const
Definition match_tree.h:391
match_tree_N(const match_tree &result_tree, std::size_t)
Definition match_tree.h:387
match_tree_R(const atermpp::aterm &t)
Definition match_tree.h:431
const data_expression & result() const
Definition match_tree.h:441
match_tree_R(const data_expression &e)
Definition match_tree.h:437
match_tree_Re(const data_expression &result, const variable_or_number_list &vars)
Definition match_tree.h:509
match_tree_Re(const atermpp::aterm &t)
Definition match_tree.h:503
const variable_or_number_list & variables() const
Definition match_tree.h:518
const data_expression & result() const
Definition match_tree.h:513
match_tree_S(const atermpp::aterm &t)
Definition match_tree.h:225
const variable & target_variable() const
Definition match_tree.h:235
match_tree_S(const variable &target_variable, const match_tree &result_tree)
Definition match_tree.h:231
const match_tree & subtree() const
Definition match_tree.h:240
match_tree_X(const atermpp::aterm &t)
Definition match_tree.h:484
atermpp::function_symbol afunUndefined() const
Definition match_tree.h:61
atermpp::function_symbol afunD() const
Definition match_tree.h:104
atermpp::function_symbol afunN() const
Definition match_tree.h:98
match_tree(const atermpp::aterm &t)
Constructor based on an aterm.
Definition match_tree.h:52
match_tree()
Default constructor.
Definition match_tree.h:47
atermpp::function_symbol afunRe() const
Definition match_tree.h:128
atermpp::function_symbol afunF() const
Definition match_tree.h:86
atermpp::function_symbol afunCRe() const
Definition match_tree.h:134
atermpp::function_symbol afunM() const
Definition match_tree.h:80
atermpp::function_symbol afunX() const
Definition match_tree.h:122
atermpp::function_symbol afunMachineNumber() const
Definition match_tree.h:92
atermpp::function_symbol afunMe() const
Definition match_tree.h:140
atermpp::function_symbol afunC() const
Definition match_tree.h:116
atermpp::function_symbol afunS() const
Definition match_tree.h:67
atermpp::function_symbol afunA() const
Definition match_tree.h:73
atermpp::function_symbol afunR() const
Definition match_tree.h:110
This is a list where variables and aterm ints can be stored.
Definition match_tree.h:27
variable_or_number(const atermpp::aterm &v)
Constructor.
Definition match_tree.h:34
variable_or_number()
Default constructor.
Definition match_tree.h:30
\brief A function symbol
\brief A machine number
\brief A data variable
Definition variable.h:28
The class function symbol.
The class machine_number, which is a subclass of data_expression.
The main namespace for the aterm++ library.
Definition algorithm.h:21
const Derived & down_cast(const Base &t, typename std::enable_if< is_convertible< Base, Derived >::value &&!std::is_base_of< Derived, Base >::value >::type *=nullptr)
A cheap cast from one aterm based type to another When casting one aterm based type into another,...
Definition aterm.h:337
atermpp::term_list< match_tree > match_tree_list
Definition match_tree.h:591
atermpp::term_list< match_tree_list > match_tree_list_list
Definition match_tree.h:593
atermpp::term_list< variable_or_number > variable_or_number_list
Definition match_tree.h:41
std::ostream & operator<<(std::ostream &os, smt_solver_type s)
standard conversion from solvert type to stream
Definition solver_type.h:71
std::vector< match_tree > match_tree_vector
Definition match_tree.h:592
atermpp::term_list< match_tree_list_list > match_tree_list_list_list
Definition match_tree.h:594
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72