]>
Commit | Line | Data |
---|---|---|
56099f08 | 1 | // parse tree functions |
69c68955 FCE |
2 | // Copyright (C) 2005 Red Hat Inc. |
3 | // | |
4 | // This file is part of systemtap, and is free software. You can | |
5 | // redistribute it and/or modify it under the terms of the GNU General | |
6 | // Public License (GPL); either version 2, or (at your option) any | |
7 | // later version. | |
2f1a1aea | 8 | |
2b066ec1 | 9 | #include "config.h" |
2f1a1aea FCE |
10 | #include "staptree.h" |
11 | #include "parse.h" | |
12 | #include <iostream> | |
56099f08 FCE |
13 | #include <typeinfo> |
14 | #include <cassert> | |
2f1a1aea | 15 | |
2b066ec1 FCE |
16 | using namespace std; |
17 | ||
2f1a1aea | 18 | |
56099f08 FCE |
19 | expression::expression (): |
20 | type (pe_unknown), tok (0) | |
21 | { | |
22 | } | |
23 | ||
24 | ||
25 | expression::~expression () | |
26 | { | |
27 | } | |
28 | ||
29 | ||
30 | statement::statement (): | |
31 | tok (0) | |
32 | { | |
33 | } | |
34 | ||
35 | ||
36 | statement::~statement () | |
37 | { | |
38 | } | |
39 | ||
40 | ||
41 | symbol::symbol (): | |
42 | referent (0) | |
43 | { | |
44 | } | |
45 | ||
46 | ||
47 | arrayindex::arrayindex (): | |
48 | referent (0) | |
49 | { | |
50 | } | |
51 | ||
52 | ||
53 | functioncall::functioncall (): | |
54 | referent (0) | |
55 | { | |
56 | } | |
57 | ||
58 | ||
59 | symboldecl::symboldecl (): | |
60 | tok (0), | |
61 | type (pe_unknown) | |
62 | { | |
63 | } | |
64 | ||
65 | ||
66 | symboldecl::~symboldecl () | |
67 | { | |
68 | } | |
69 | ||
70 | ||
9c0c0e46 | 71 | probe_point::probe_point (): |
82919855 FCE |
72 | tok (0) |
73 | { | |
74 | } | |
75 | ||
76 | ||
77 | probe::probe (): | |
78 | body (0), tok (0) | |
9c0c0e46 FCE |
79 | { |
80 | } | |
81 | ||
82 | ||
83 | probe_point::component::component (): | |
84 | arg (0) | |
85 | { | |
86 | } | |
87 | ||
88 | ||
2b066ec1 FCE |
89 | vardecl::vardecl (): |
90 | arity (-1) | |
56099f08 FCE |
91 | { |
92 | } | |
93 | ||
94 | ||
2b066ec1 FCE |
95 | void |
96 | vardecl::set_arity (int a) | |
56099f08 | 97 | { |
2b066ec1 | 98 | assert (a >= 0); |
8846477c FCE |
99 | |
100 | if (arity != a && arity >= 0) | |
101 | throw semantic_error ("inconsistent arity", tok); | |
102 | ||
103 | if (arity != a) | |
104 | { | |
105 | arity = a; | |
106 | index_types.resize (arity); | |
107 | for (int i=0; i<arity; i++) | |
108 | index_types[i] = pe_unknown; | |
109 | } | |
56099f08 FCE |
110 | } |
111 | ||
112 | ||
113 | functiondecl::functiondecl (): | |
114 | body (0) | |
115 | { | |
116 | } | |
117 | ||
118 | ||
119 | literal_number::literal_number (long v) | |
120 | { | |
121 | value = v; | |
122 | type = pe_long; | |
123 | } | |
124 | ||
2f1a1aea | 125 | |
56099f08 FCE |
126 | literal_string::literal_string (const string& v) |
127 | { | |
128 | value = v; | |
129 | type = pe_string; | |
130 | } | |
131 | ||
132 | ||
133 | ostream& | |
134 | operator << (ostream& o, const exp_type& e) | |
135 | { | |
136 | switch (e) | |
137 | { | |
138 | case pe_unknown: o << "unknown"; break; | |
139 | case pe_long: o << "long"; break; | |
140 | case pe_string: o << "string"; break; | |
141 | case pe_stats: o << "stats"; break; | |
142 | default: o << "???"; break; | |
143 | } | |
144 | return o; | |
145 | } | |
146 | ||
147 | ||
148 | // ------------------------------------------------------------------------ | |
149 | // parse tree printing | |
150 | ||
151 | ostream& operator << (ostream& o, expression& k) | |
152 | { | |
153 | k.print (o); | |
154 | return o; | |
155 | } | |
156 | ||
157 | ||
158 | void literal_string::print (ostream& o) | |
159 | { | |
2b066ec1 | 160 | // XXX: quote special chars |
56099f08 FCE |
161 | o << '"' << value << '"'; |
162 | } | |
163 | ||
f3c26ea5 | 164 | |
56099f08 FCE |
165 | void literal_number::print (ostream& o) |
166 | { | |
167 | o << value; | |
168 | } | |
169 | ||
170 | ||
171 | void binary_expression::print (ostream& o) | |
172 | { | |
173 | o << '(' << *left << ")" | |
174 | << op | |
175 | << '(' << *right << ")"; | |
176 | } | |
2f1a1aea FCE |
177 | |
178 | ||
56099f08 | 179 | void unary_expression::print (ostream& o) |
2f1a1aea | 180 | { |
56099f08 FCE |
181 | o << op << '(' << *operand << ")"; |
182 | } | |
183 | ||
69c68955 FCE |
184 | void array_in::print (ostream& o) |
185 | { | |
186 | o << "["; | |
187 | for (unsigned i=0; i<operand->indexes.size(); i++) | |
188 | { | |
189 | if (i > 0) o << ", "; | |
190 | operand->indexes[i]->print (o); | |
191 | } | |
192 | o << "] in " << operand->base; | |
193 | } | |
56099f08 FCE |
194 | |
195 | void post_crement::print (ostream& o) | |
196 | { | |
197 | o << '(' << *operand << ")" << op; | |
198 | } | |
199 | ||
200 | ||
201 | void ternary_expression::print (ostream& o) | |
202 | { | |
203 | o << "(" << *cond << ") ? (" | |
204 | << *truevalue << ") : (" | |
205 | << *falsevalue << ")"; | |
206 | } | |
207 | ||
208 | ||
209 | void symbol::print (ostream& o) | |
210 | { | |
211 | o << name; | |
212 | } | |
213 | ||
214 | ||
215 | void vardecl::print (ostream& o) | |
216 | { | |
217 | o << name; | |
bed7c0af | 218 | if (arity > 0 || index_types.size() > 0) |
56099f08 FCE |
219 | o << "[...]"; |
220 | } | |
221 | ||
2f1a1aea | 222 | |
56099f08 FCE |
223 | void vardecl::printsig (ostream& o) |
224 | { | |
225 | o << name << ":" << type; | |
226 | if (index_types.size() > 0) | |
2f1a1aea | 227 | { |
56099f08 FCE |
228 | o << " ["; |
229 | for (unsigned i=0; i<index_types.size(); i++) | |
230 | o << (i>0 ? ", " : "") << index_types[i]; | |
231 | o << "]"; | |
232 | } | |
233 | } | |
234 | ||
235 | ||
236 | void functiondecl::print (ostream& o) | |
237 | { | |
238 | o << "function " << name << " ("; | |
239 | for (unsigned i=0; i<formal_args.size(); i++) | |
240 | o << (i>0 ? ", " : "") << *formal_args[i]; | |
241 | o << ")" << endl; | |
242 | body->print(o); | |
243 | } | |
244 | ||
245 | ||
246 | void functiondecl::printsig (ostream& o) | |
247 | { | |
248 | o << name << ":" << type << " ("; | |
249 | for (unsigned i=0; i<formal_args.size(); i++) | |
250 | o << (i>0 ? ", " : "") | |
251 | << *formal_args[i] | |
252 | << ":" | |
253 | << formal_args[i]->type; | |
254 | o << ")"; | |
255 | } | |
256 | ||
257 | ||
258 | void arrayindex::print (ostream& o) | |
259 | { | |
260 | o << base << "["; | |
261 | for (unsigned i=0; i<indexes.size(); i++) | |
262 | o << (i>0 ? ", " : "") << *indexes[i]; | |
263 | o << "]"; | |
264 | } | |
265 | ||
266 | ||
267 | void functioncall::print (ostream& o) | |
268 | { | |
269 | o << function << "("; | |
270 | for (unsigned i=0; i<args.size(); i++) | |
271 | o << (i>0 ? ", " : "") << *args[i]; | |
272 | o << ")"; | |
273 | } | |
274 | ||
275 | ||
276 | ostream& operator << (ostream& o, statement& k) | |
277 | { | |
278 | k.print (o); | |
279 | return o; | |
280 | } | |
281 | ||
282 | ||
283 | void block::print (ostream& o) | |
284 | { | |
285 | o << "{" << endl; | |
286 | for (unsigned i=0; i<statements.size(); i++) | |
69c68955 | 287 | o << *statements [i] << endl; |
bb2e3076 | 288 | o << "}"; |
56099f08 FCE |
289 | } |
290 | ||
291 | ||
292 | void for_loop::print (ostream& o) | |
293 | { | |
f3c26ea5 FCE |
294 | o << "for ("; |
295 | init->print (o); | |
296 | o << "; "; | |
297 | cond->print (o); | |
298 | o << "; "; | |
299 | incr->print (o); | |
bb2e3076 | 300 | o << ") "; |
f3c26ea5 | 301 | block->print (o); |
56099f08 FCE |
302 | } |
303 | ||
304 | ||
69c68955 FCE |
305 | void foreach_loop::print (ostream& o) |
306 | { | |
307 | o << "foreach (["; | |
308 | for (unsigned i=0; i<indexes.size(); i++) | |
309 | { | |
310 | if (i > 0) o << ", "; | |
311 | indexes[i]->print (o); | |
312 | } | |
bb2e3076 | 313 | o << "] in " << base << ") "; |
69c68955 FCE |
314 | block->print (o); |
315 | } | |
316 | ||
317 | ||
56099f08 FCE |
318 | void null_statement::print (ostream& o) |
319 | { | |
320 | o << ";"; | |
321 | } | |
322 | ||
323 | ||
324 | void expr_statement::print (ostream& o) | |
325 | { | |
326 | o << *value; | |
327 | } | |
328 | ||
329 | ||
330 | void return_statement::print (ostream& o) | |
331 | { | |
332 | o << "return " << *value; | |
333 | } | |
334 | ||
335 | ||
336 | void delete_statement::print (ostream& o) | |
337 | { | |
338 | o << "delete " << *value; | |
339 | } | |
340 | ||
f3c26ea5 FCE |
341 | void next_statement::print (ostream& o) |
342 | { | |
343 | o << "next"; | |
344 | } | |
345 | ||
346 | void break_statement::print (ostream& o) | |
347 | { | |
348 | o << "break"; | |
349 | } | |
350 | ||
351 | void continue_statement::print (ostream& o) | |
352 | { | |
353 | o << "continue"; | |
354 | } | |
56099f08 FCE |
355 | |
356 | void if_statement::print (ostream& o) | |
357 | { | |
bb2e3076 | 358 | o << "if (" << *condition << ") " |
56099f08 FCE |
359 | << *thenblock << endl; |
360 | if (elseblock) | |
361 | o << "else " << *elseblock << endl; | |
362 | } | |
363 | ||
364 | ||
365 | void stapfile::print (ostream& o) | |
366 | { | |
367 | o << "# file " << name << endl; | |
368 | ||
bed7c0af FCE |
369 | for (unsigned i=0; i<globals.size(); i++) |
370 | { | |
371 | o << "global "; | |
372 | globals[i]->print (o); | |
373 | o << endl; | |
374 | } | |
375 | ||
20c6c071 GH |
376 | for (unsigned i=0; i<aliases.size(); i++) |
377 | { | |
378 | aliases[i]->print (o); | |
379 | o << endl; | |
380 | } | |
381 | ||
bed7c0af | 382 | for (unsigned i=0; i<probes.size(); i++) |
56099f08 FCE |
383 | { |
384 | probes[i]->print (o); | |
385 | o << endl; | |
386 | } | |
387 | ||
388 | for (unsigned j = 0; j < functions.size(); j++) | |
389 | { | |
390 | functions[j]->print (o); | |
391 | o << endl; | |
392 | } | |
393 | } | |
394 | ||
395 | ||
396 | void probe::print (ostream& o) | |
397 | { | |
398 | o << "probe "; | |
40a1cb62 FCE |
399 | printsig (o); |
400 | o << *body; | |
401 | } | |
402 | ||
403 | ||
404 | void probe::printsig (ostream& o) | |
405 | { | |
9c0c0e46 | 406 | for (unsigned i=0; i<locations.size(); i++) |
56099f08 | 407 | { |
9c0c0e46 FCE |
408 | o << (i>0 ? ", " : ""); |
409 | locations[i]->print (o); | |
56099f08 | 410 | } |
56099f08 FCE |
411 | } |
412 | ||
413 | ||
9c0c0e46 | 414 | void probe_point::print (ostream& o) |
56099f08 | 415 | { |
9c0c0e46 FCE |
416 | for (unsigned i=0; i<components.size(); i++) |
417 | { | |
418 | if (i>0) o << "."; | |
419 | probe_point::component* c = components[i]; | |
420 | o << c->functor; | |
421 | if (c->arg) | |
422 | o << "(" << *c->arg << ")"; | |
423 | } | |
56099f08 FCE |
424 | } |
425 | ||
20c6c071 GH |
426 | probe_alias::probe_alias(std::vector<probe_point*> const & aliases): |
427 | probe (), alias_names (aliases) | |
428 | { | |
429 | } | |
430 | ||
431 | void probe_alias::printsig (ostream& o) | |
432 | { | |
433 | for (unsigned i=0; i<alias_names.size(); i++) | |
434 | { | |
435 | o << (i>0 ? " = " : ""); | |
436 | alias_names[i]->print (o); | |
437 | } | |
5227f1ea | 438 | o << " = "; |
20c6c071 GH |
439 | for (unsigned i=0; i<locations.size(); i++) |
440 | { | |
441 | o << (i>0 ? ", " : ""); | |
442 | locations[i]->print (o); | |
443 | } | |
444 | } | |
445 | ||
56099f08 | 446 | |
82919855 FCE |
447 | ostream& operator << (ostream& o, probe_point& k) |
448 | { | |
449 | k.print (o); | |
450 | return o; | |
451 | } | |
452 | ||
453 | ||
56099f08 FCE |
454 | ostream& operator << (ostream& o, symboldecl& k) |
455 | { | |
456 | k.print (o); | |
457 | return o; | |
458 | } | |
459 | ||
460 | ||
82919855 FCE |
461 | |
462 | // ------------------------------------------------------------------------ | |
463 | // visitors | |
464 | ||
465 | ||
466 | void | |
467 | block::visit (visitor* u) | |
468 | { | |
469 | u->visit_block (this); | |
470 | } | |
471 | ||
472 | void | |
473 | for_loop::visit (visitor* u) | |
474 | { | |
475 | u->visit_for_loop (this); | |
476 | } | |
477 | ||
69c68955 FCE |
478 | void |
479 | foreach_loop::visit (visitor* u) | |
480 | { | |
481 | u->visit_foreach_loop (this); | |
482 | } | |
483 | ||
82919855 FCE |
484 | void |
485 | null_statement::visit (visitor* u) | |
486 | { | |
487 | u->visit_null_statement (this); | |
488 | } | |
489 | ||
490 | void | |
491 | expr_statement::visit (visitor* u) | |
492 | { | |
493 | u->visit_expr_statement (this); | |
494 | } | |
495 | ||
496 | void | |
497 | return_statement::visit (visitor* u) | |
498 | { | |
499 | u->visit_return_statement (this); | |
500 | } | |
501 | ||
502 | void | |
503 | delete_statement::visit (visitor* u) | |
504 | { | |
505 | u->visit_delete_statement (this); | |
506 | } | |
507 | ||
508 | void | |
509 | if_statement::visit (visitor* u) | |
510 | { | |
511 | u->visit_if_statement (this); | |
512 | } | |
513 | ||
f3c26ea5 FCE |
514 | void |
515 | next_statement::visit (visitor* u) | |
516 | { | |
517 | u->visit_next_statement (this); | |
518 | } | |
519 | ||
520 | void | |
521 | break_statement::visit (visitor* u) | |
522 | { | |
523 | u->visit_break_statement (this); | |
524 | } | |
525 | ||
526 | void | |
527 | continue_statement::visit (visitor* u) | |
528 | { | |
529 | u->visit_continue_statement (this); | |
530 | } | |
531 | ||
82919855 FCE |
532 | void |
533 | literal_string::visit(visitor* u) | |
534 | { | |
535 | u->visit_literal_string (this); | |
536 | } | |
537 | ||
538 | void | |
539 | literal_number::visit(visitor* u) | |
540 | { | |
541 | u->visit_literal_number (this); | |
542 | } | |
543 | ||
544 | void | |
545 | binary_expression::visit (visitor* u) | |
546 | { | |
547 | u->visit_binary_expression (this); | |
548 | } | |
549 | ||
550 | void | |
551 | unary_expression::visit (visitor* u) | |
552 | { | |
553 | u->visit_unary_expression (this); | |
554 | } | |
555 | ||
556 | void | |
557 | pre_crement::visit (visitor* u) | |
558 | { | |
559 | u->visit_pre_crement (this); | |
560 | } | |
561 | ||
562 | void | |
563 | post_crement::visit (visitor* u) | |
564 | { | |
565 | u->visit_post_crement (this); | |
566 | } | |
567 | ||
568 | void | |
569 | logical_or_expr::visit (visitor* u) | |
570 | { | |
571 | u->visit_logical_or_expr (this); | |
572 | } | |
573 | ||
574 | void | |
575 | logical_and_expr::visit (visitor* u) | |
576 | { | |
577 | u->visit_logical_and_expr (this); | |
578 | } | |
579 | ||
580 | void | |
581 | array_in::visit (visitor* u) | |
582 | { | |
583 | u->visit_array_in (this); | |
584 | } | |
585 | ||
586 | void | |
587 | comparison::visit (visitor* u) | |
588 | { | |
589 | u->visit_comparison (this); | |
590 | } | |
591 | ||
592 | void | |
593 | concatenation::visit (visitor* u) | |
594 | { | |
595 | u->visit_concatenation (this); | |
596 | } | |
597 | ||
82919855 FCE |
598 | void |
599 | ternary_expression::visit (visitor* u) | |
600 | { | |
601 | u->visit_ternary_expression (this); | |
602 | } | |
603 | ||
604 | void | |
605 | assignment::visit (visitor* u) | |
606 | { | |
607 | u->visit_assignment (this); | |
608 | } | |
609 | ||
610 | void | |
611 | symbol::visit (visitor* u) | |
612 | { | |
613 | u->visit_symbol (this); | |
614 | } | |
615 | ||
616 | void | |
617 | arrayindex::visit (visitor* u) | |
618 | { | |
619 | u->visit_arrayindex (this); | |
620 | } | |
621 | ||
622 | void | |
623 | functioncall::visit (visitor* u) | |
624 | { | |
625 | u->visit_functioncall (this); | |
626 | } | |
627 | ||
628 | ||
629 | // ------------------------------------------------------------------------ | |
630 | ||
631 | void | |
632 | traversing_visitor::visit_block (block *s) | |
633 | { | |
634 | for (unsigned i=0; i<s->statements.size(); i++) | |
635 | s->statements[i]->visit (this); | |
636 | } | |
637 | ||
638 | void | |
639 | traversing_visitor::visit_null_statement (null_statement *s) | |
640 | { | |
641 | } | |
642 | ||
643 | void | |
644 | traversing_visitor::visit_expr_statement (expr_statement *s) | |
645 | { | |
646 | s->value->visit (this); | |
647 | } | |
648 | ||
649 | void | |
650 | traversing_visitor::visit_if_statement (if_statement* s) | |
651 | { | |
652 | s->condition->visit (this); | |
653 | s->thenblock->visit (this); | |
2b066ec1 FCE |
654 | if (s->elseblock) |
655 | s->elseblock->visit (this); | |
82919855 FCE |
656 | } |
657 | ||
658 | void | |
659 | traversing_visitor::visit_for_loop (for_loop* s) | |
660 | { | |
661 | s->init->visit (this); | |
662 | s->cond->visit (this); | |
663 | s->incr->visit (this); | |
664 | s->block->visit (this); | |
665 | } | |
666 | ||
69c68955 FCE |
667 | void |
668 | traversing_visitor::visit_foreach_loop (foreach_loop* s) | |
669 | { | |
670 | for (unsigned i=0; i<s->indexes.size(); i++) | |
671 | s->indexes[i]->visit (this); | |
672 | s->block->visit (this); | |
673 | } | |
674 | ||
82919855 FCE |
675 | void |
676 | traversing_visitor::visit_return_statement (return_statement* s) | |
677 | { | |
678 | s->value->visit (this); | |
679 | } | |
680 | ||
681 | void | |
682 | traversing_visitor::visit_delete_statement (delete_statement* s) | |
683 | { | |
684 | s->value->visit (this); | |
685 | } | |
686 | ||
f3c26ea5 FCE |
687 | void |
688 | traversing_visitor::visit_next_statement (next_statement* s) | |
689 | { | |
690 | } | |
691 | ||
692 | void | |
693 | traversing_visitor::visit_break_statement (break_statement* s) | |
694 | { | |
695 | } | |
696 | ||
697 | void | |
698 | traversing_visitor::visit_continue_statement (continue_statement* s) | |
699 | { | |
700 | } | |
701 | ||
82919855 FCE |
702 | void |
703 | traversing_visitor::visit_literal_string (literal_string* e) | |
704 | { | |
705 | } | |
706 | ||
707 | void | |
708 | traversing_visitor::visit_literal_number (literal_number* e) | |
709 | { | |
710 | } | |
711 | ||
712 | void | |
713 | traversing_visitor::visit_binary_expression (binary_expression* e) | |
714 | { | |
715 | e->left->visit (this); | |
716 | e->right->visit (this); | |
717 | } | |
718 | ||
719 | void | |
720 | traversing_visitor::visit_unary_expression (unary_expression* e) | |
721 | { | |
722 | e->operand->visit (this); | |
723 | } | |
724 | ||
725 | void | |
726 | traversing_visitor::visit_pre_crement (pre_crement* e) | |
727 | { | |
728 | e->operand->visit (this); | |
729 | } | |
730 | ||
731 | void | |
732 | traversing_visitor::visit_post_crement (post_crement* e) | |
733 | { | |
734 | e->operand->visit (this); | |
735 | } | |
736 | ||
737 | ||
738 | void | |
739 | traversing_visitor::visit_logical_or_expr (logical_or_expr* e) | |
740 | { | |
741 | e->left->visit (this); | |
742 | e->right->visit (this); | |
743 | } | |
744 | ||
745 | void | |
746 | traversing_visitor::visit_logical_and_expr (logical_and_expr* e) | |
747 | { | |
748 | e->left->visit (this); | |
749 | e->right->visit (this); | |
750 | } | |
751 | ||
752 | void | |
753 | traversing_visitor::visit_array_in (array_in* e) | |
754 | { | |
ce10591c | 755 | e->operand->visit (this); |
82919855 FCE |
756 | } |
757 | ||
758 | void | |
759 | traversing_visitor::visit_comparison (comparison* e) | |
760 | { | |
761 | e->left->visit (this); | |
762 | e->right->visit (this); | |
763 | } | |
764 | ||
765 | void | |
766 | traversing_visitor::visit_concatenation (concatenation* e) | |
767 | { | |
768 | e->left->visit (this); | |
769 | e->right->visit (this); | |
770 | } | |
771 | ||
82919855 FCE |
772 | void |
773 | traversing_visitor::visit_ternary_expression (ternary_expression* e) | |
774 | { | |
775 | e->cond->visit (this); | |
776 | e->truevalue->visit (this); | |
777 | e->falsevalue->visit (this); | |
778 | } | |
779 | ||
780 | void | |
781 | traversing_visitor::visit_assignment (assignment* e) | |
782 | { | |
783 | e->left->visit (this); | |
784 | e->right->visit (this); | |
785 | } | |
786 | ||
787 | void | |
788 | traversing_visitor::visit_symbol (symbol* e) | |
789 | { | |
790 | } | |
791 | ||
792 | void | |
793 | traversing_visitor::visit_arrayindex (arrayindex* e) | |
794 | { | |
795 | for (unsigned i=0; i<e->indexes.size(); i++) | |
796 | e->indexes[i]->visit (this); | |
797 | } | |
798 | ||
799 | void | |
800 | traversing_visitor::visit_functioncall (functioncall* e) | |
801 | { | |
802 | for (unsigned i=0; i<e->args.size(); i++) | |
803 | e->args[i]->visit (this); | |
804 | } | |
805 | ||
806 | ||
807 | // ------------------------------------------------------------------------ | |
808 | ||
809 | ||
810 | throwing_visitor::throwing_visitor (const std::string& m): msg (m) {} | |
811 | throwing_visitor::throwing_visitor (): msg ("invalid element") {} | |
812 | ||
813 | ||
814 | void | |
815 | throwing_visitor::throwone (const token* t) | |
816 | { | |
817 | throw semantic_error (msg, t); | |
818 | } | |
819 | ||
820 | void | |
821 | throwing_visitor::visit_block (block *s) | |
822 | { | |
823 | throwone (s->tok); | |
824 | } | |
825 | ||
826 | void | |
827 | throwing_visitor::visit_null_statement (null_statement *s) | |
828 | { | |
829 | throwone (s->tok); | |
830 | } | |
831 | ||
832 | void | |
833 | throwing_visitor::visit_expr_statement (expr_statement *s) | |
834 | { | |
835 | throwone (s->tok); | |
836 | } | |
837 | ||
838 | void | |
839 | throwing_visitor::visit_if_statement (if_statement* s) | |
840 | { | |
841 | throwone (s->tok); | |
842 | } | |
843 | ||
844 | void | |
845 | throwing_visitor::visit_for_loop (for_loop* s) | |
846 | { | |
847 | throwone (s->tok); | |
848 | } | |
849 | ||
69c68955 FCE |
850 | void |
851 | throwing_visitor::visit_foreach_loop (foreach_loop* s) | |
852 | { | |
853 | throwone (s->tok); | |
854 | } | |
855 | ||
82919855 FCE |
856 | void |
857 | throwing_visitor::visit_return_statement (return_statement* s) | |
858 | { | |
859 | throwone (s->tok); | |
860 | } | |
861 | ||
862 | void | |
863 | throwing_visitor::visit_delete_statement (delete_statement* s) | |
864 | { | |
865 | throwone (s->tok); | |
866 | } | |
867 | ||
f3c26ea5 FCE |
868 | void |
869 | throwing_visitor::visit_next_statement (next_statement* s) | |
870 | { | |
871 | throwone (s->tok); | |
872 | } | |
873 | ||
874 | void | |
875 | throwing_visitor::visit_break_statement (break_statement* s) | |
876 | { | |
877 | throwone (s->tok); | |
878 | } | |
879 | ||
880 | void | |
881 | throwing_visitor::visit_continue_statement (continue_statement* s) | |
882 | { | |
883 | throwone (s->tok); | |
884 | } | |
885 | ||
82919855 FCE |
886 | void |
887 | throwing_visitor::visit_literal_string (literal_string* e) | |
888 | { | |
889 | throwone (e->tok); | |
890 | } | |
891 | ||
892 | void | |
893 | throwing_visitor::visit_literal_number (literal_number* e) | |
894 | { | |
895 | throwone (e->tok); | |
896 | } | |
897 | ||
898 | void | |
899 | throwing_visitor::visit_binary_expression (binary_expression* e) | |
900 | { | |
901 | throwone (e->tok); | |
902 | } | |
903 | ||
904 | void | |
905 | throwing_visitor::visit_unary_expression (unary_expression* e) | |
906 | { | |
907 | throwone (e->tok); | |
908 | } | |
909 | ||
910 | void | |
911 | throwing_visitor::visit_pre_crement (pre_crement* e) | |
912 | { | |
913 | throwone (e->tok); | |
914 | } | |
915 | ||
916 | void | |
917 | throwing_visitor::visit_post_crement (post_crement* e) | |
918 | { | |
919 | throwone (e->tok); | |
0054a7ea FCE |
920 | } |
921 | ||
922 | ||
82919855 FCE |
923 | void |
924 | throwing_visitor::visit_logical_or_expr (logical_or_expr* e) | |
925 | { | |
926 | throwone (e->tok); | |
927 | } | |
928 | ||
929 | void | |
930 | throwing_visitor::visit_logical_and_expr (logical_and_expr* e) | |
931 | { | |
932 | throwone (e->tok); | |
933 | } | |
934 | ||
935 | void | |
936 | throwing_visitor::visit_array_in (array_in* e) | |
937 | { | |
938 | throwone (e->tok); | |
939 | } | |
940 | ||
941 | void | |
942 | throwing_visitor::visit_comparison (comparison* e) | |
943 | { | |
944 | throwone (e->tok); | |
945 | } | |
946 | ||
947 | void | |
948 | throwing_visitor::visit_concatenation (concatenation* e) | |
949 | { | |
950 | throwone (e->tok); | |
951 | } | |
952 | ||
82919855 FCE |
953 | void |
954 | throwing_visitor::visit_ternary_expression (ternary_expression* e) | |
955 | { | |
956 | throwone (e->tok); | |
957 | } | |
958 | ||
959 | void | |
960 | throwing_visitor::visit_assignment (assignment* e) | |
961 | { | |
962 | throwone (e->tok); | |
963 | } | |
964 | ||
965 | void | |
966 | throwing_visitor::visit_symbol (symbol* e) | |
967 | { | |
968 | throwone (e->tok); | |
969 | } | |
970 | ||
971 | void | |
972 | throwing_visitor::visit_arrayindex (arrayindex* e) | |
973 | { | |
974 | throwone (e->tok); | |
975 | } | |
976 | ||
977 | void | |
978 | throwing_visitor::visit_functioncall (functioncall* e) | |
979 | { | |
980 | throwone (e->tok); | |
981 | } |