]> sourceware.org Git - systemtap.git/blame - staptree.cxx
* tapset/system_calls.stp: All 281 syscalls *prototyped*. They
[systemtap.git] / staptree.cxx
CommitLineData
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
16using namespace std;
17
2f1a1aea 18
56099f08
FCE
19expression::expression ():
20 type (pe_unknown), tok (0)
21{
22}
23
24
25expression::~expression ()
26{
27}
28
29
30statement::statement ():
31 tok (0)
32{
33}
34
35
36statement::~statement ()
37{
38}
39
40
41symbol::symbol ():
42 referent (0)
43{
44}
45
46
47arrayindex::arrayindex ():
48 referent (0)
49{
50}
51
52
53functioncall::functioncall ():
54 referent (0)
55{
56}
57
58
59symboldecl::symboldecl ():
60 tok (0),
61 type (pe_unknown)
62{
63}
64
65
66symboldecl::~symboldecl ()
67{
68}
69
a229fcd7
GH
70probe_point::probe_point (std::vector<component*> const & comps,
71 const token * t):
72 components(comps), tok(t)
73{
74}
56099f08 75
9c0c0e46 76probe_point::probe_point ():
82919855
FCE
77 tok (0)
78{
79}
80
81
82probe::probe ():
83 body (0), tok (0)
9c0c0e46
FCE
84{
85}
86
87
88probe_point::component::component ():
89 arg (0)
90{
91}
92
93
a229fcd7
GH
94probe_point::component::component (std::string const & f, literal * a):
95 functor(f), arg(a)
96{
97}
98
99
2b066ec1
FCE
100vardecl::vardecl ():
101 arity (-1)
56099f08
FCE
102{
103}
104
105
2b066ec1
FCE
106void
107vardecl::set_arity (int a)
56099f08 108{
d98d459c
GH
109 if (a < 0)
110 return;
8846477c
FCE
111
112 if (arity != a && arity >= 0)
113 throw semantic_error ("inconsistent arity", tok);
114
115 if (arity != a)
116 {
117 arity = a;
118 index_types.resize (arity);
119 for (int i=0; i<arity; i++)
120 index_types[i] = pe_unknown;
121 }
56099f08
FCE
122}
123
313b2f74
GH
124bool
125vardecl::compatible_arity (int a)
126{
d98d459c 127 if (arity == -1 || a == -1)
313b2f74
GH
128 return true;
129 return arity == a;
130}
131
56099f08
FCE
132
133functiondecl::functiondecl ():
134 body (0)
135{
136}
137
138
3a20432b 139literal_number::literal_number (int64_t v)
56099f08
FCE
140{
141 value = v;
142 type = pe_long;
143}
144
2f1a1aea 145
56099f08
FCE
146literal_string::literal_string (const string& v)
147{
148 value = v;
149 type = pe_string;
150}
151
152
153ostream&
154operator << (ostream& o, const exp_type& e)
155{
156 switch (e)
157 {
158 case pe_unknown: o << "unknown"; break;
159 case pe_long: o << "long"; break;
160 case pe_string: o << "string"; break;
161 case pe_stats: o << "stats"; break;
162 default: o << "???"; break;
163 }
164 return o;
165}
166
167
168// ------------------------------------------------------------------------
169// parse tree printing
170
cc9ee605 171ostream& operator << (ostream& o, const expression& k)
56099f08
FCE
172{
173 k.print (o);
174 return o;
175}
176
177
cc9ee605 178void literal_string::print (ostream& o) const
56099f08 179{
cc9ee605
FCE
180 o << '"';
181 for (unsigned i=0; i<value.size(); i++)
182 if (value[i] == '"') // or other escapeworthy characters?
183 o << '\\' << '"';
184 else
185 o << value[i];
186 o << '"';
56099f08
FCE
187}
188
f3c26ea5 189
cc9ee605 190void literal_number::print (ostream& o) const
56099f08
FCE
191{
192 o << value;
193}
194
195
cc9ee605 196void binary_expression::print (ostream& o) const
56099f08
FCE
197{
198 o << '(' << *left << ")"
199 << op
200 << '(' << *right << ")";
201}
2f1a1aea
FCE
202
203
cc9ee605 204void unary_expression::print (ostream& o) const
2f1a1aea 205{
56099f08
FCE
206 o << op << '(' << *operand << ")";
207}
208
cc9ee605 209void array_in::print (ostream& o) const
69c68955
FCE
210{
211 o << "[";
212 for (unsigned i=0; i<operand->indexes.size(); i++)
213 {
214 if (i > 0) o << ", ";
215 operand->indexes[i]->print (o);
216 }
217 o << "] in " << operand->base;
218}
56099f08 219
cc9ee605 220void post_crement::print (ostream& o) const
56099f08
FCE
221{
222 o << '(' << *operand << ")" << op;
223}
224
225
cc9ee605 226void ternary_expression::print (ostream& o) const
56099f08 227{
ae56fddd
FCE
228 o << "(" << *cond << ")?("
229 << *truevalue << "):("
56099f08
FCE
230 << *falsevalue << ")";
231}
232
233
cc9ee605 234void symbol::print (ostream& o) const
56099f08
FCE
235{
236 o << name;
237}
238
239
cc9ee605 240void target_symbol::print (std::ostream& o) const
d7f3e0c5
GH
241{
242 o << base_name;
243 for (unsigned i = 0; i < components.size(); ++i)
244 {
245 switch (components[i].first)
246 {
247 case comp_literal_array_index:
248 o << '[' << components[i].second << ']';
249 break;
246b383e 250 case comp_struct_member:
d7f3e0c5
GH
251 o << "->" << components[i].second;
252 break;
d7f3e0c5
GH
253 }
254 }
255}
256
257
cc9ee605 258void vardecl::print (ostream& o) const
56099f08
FCE
259{
260 o << name;
bed7c0af 261 if (arity > 0 || index_types.size() > 0)
56099f08
FCE
262 o << "[...]";
263}
264
2f1a1aea 265
cc9ee605 266void vardecl::printsig (ostream& o) const
56099f08
FCE
267{
268 o << name << ":" << type;
269 if (index_types.size() > 0)
2f1a1aea 270 {
56099f08
FCE
271 o << " [";
272 for (unsigned i=0; i<index_types.size(); i++)
273 o << (i>0 ? ", " : "") << index_types[i];
274 o << "]";
275 }
276}
277
278
cc9ee605 279void functiondecl::print (ostream& o) const
56099f08
FCE
280{
281 o << "function " << name << " (";
282 for (unsigned i=0; i<formal_args.size(); i++)
283 o << (i>0 ? ", " : "") << *formal_args[i];
284 o << ")" << endl;
285 body->print(o);
286}
287
288
cc9ee605 289void functiondecl::printsig (ostream& o) const
56099f08
FCE
290{
291 o << name << ":" << type << " (";
292 for (unsigned i=0; i<formal_args.size(); i++)
293 o << (i>0 ? ", " : "")
294 << *formal_args[i]
295 << ":"
296 << formal_args[i]->type;
297 o << ")";
298}
299
300
cc9ee605 301void arrayindex::print (ostream& o) const
56099f08
FCE
302{
303 o << base << "[";
304 for (unsigned i=0; i<indexes.size(); i++)
305 o << (i>0 ? ", " : "") << *indexes[i];
306 o << "]";
307}
308
309
cc9ee605 310void functioncall::print (ostream& o) const
56099f08
FCE
311{
312 o << function << "(";
313 for (unsigned i=0; i<args.size(); i++)
314 o << (i>0 ? ", " : "") << *args[i];
315 o << ")";
316}
317
318
cc9ee605 319ostream& operator << (ostream& o, const statement& k)
56099f08
FCE
320{
321 k.print (o);
322 return o;
323}
324
325
cc9ee605 326void embeddedcode::print (ostream &o) const
54dfabe9
FCE
327{
328 o << "%{";
329 o << code;
330 o << "%}";
331}
332
cc9ee605 333void block::print (ostream& o) const
56099f08
FCE
334{
335 o << "{" << endl;
336 for (unsigned i=0; i<statements.size(); i++)
69c68955 337 o << *statements [i] << endl;
bb2e3076 338 o << "}";
56099f08
FCE
339}
340
341
cc9ee605 342void for_loop::print (ostream& o) const
56099f08 343{
f3c26ea5
FCE
344 o << "for (";
345 init->print (o);
346 o << "; ";
347 cond->print (o);
348 o << "; ";
349 incr->print (o);
bb2e3076 350 o << ") ";
f3c26ea5 351 block->print (o);
56099f08
FCE
352}
353
354
cc9ee605 355void foreach_loop::print (ostream& o) const
69c68955
FCE
356{
357 o << "foreach ([";
358 for (unsigned i=0; i<indexes.size(); i++)
359 {
360 if (i > 0) o << ", ";
361 indexes[i]->print (o);
362 }
bb2e3076 363 o << "] in " << base << ") ";
69c68955
FCE
364 block->print (o);
365}
366
367
cc9ee605 368void null_statement::print (ostream& o) const
56099f08
FCE
369{
370 o << ";";
371}
372
373
cc9ee605 374void expr_statement::print (ostream& o) const
56099f08
FCE
375{
376 o << *value;
377}
378
379
cc9ee605 380void return_statement::print (ostream& o) const
56099f08
FCE
381{
382 o << "return " << *value;
383}
384
385
cc9ee605 386void delete_statement::print (ostream& o) const
56099f08
FCE
387{
388 o << "delete " << *value;
389}
390
cc9ee605 391void next_statement::print (ostream& o) const
f3c26ea5
FCE
392{
393 o << "next";
394}
395
cc9ee605 396void break_statement::print (ostream& o) const
f3c26ea5
FCE
397{
398 o << "break";
399}
400
cc9ee605 401void continue_statement::print (ostream& o) const
f3c26ea5
FCE
402{
403 o << "continue";
404}
56099f08 405
cc9ee605 406void if_statement::print (ostream& o) const
56099f08 407{
bb2e3076 408 o << "if (" << *condition << ") "
56099f08
FCE
409 << *thenblock << endl;
410 if (elseblock)
411 o << "else " << *elseblock << endl;
412}
413
414
cc9ee605 415void stapfile::print (ostream& o) const
56099f08
FCE
416{
417 o << "# file " << name << endl;
418
54dfabe9
FCE
419 for (unsigned i=0; i<embeds.size(); i++)
420 embeds[i]->print (o);
421
bed7c0af
FCE
422 for (unsigned i=0; i<globals.size(); i++)
423 {
424 o << "global ";
425 globals[i]->print (o);
426 o << endl;
427 }
428
20c6c071
GH
429 for (unsigned i=0; i<aliases.size(); i++)
430 {
431 aliases[i]->print (o);
432 o << endl;
433 }
434
bed7c0af 435 for (unsigned i=0; i<probes.size(); i++)
56099f08
FCE
436 {
437 probes[i]->print (o);
438 o << endl;
439 }
440
441 for (unsigned j = 0; j < functions.size(); j++)
442 {
443 functions[j]->print (o);
444 o << endl;
445 }
446}
447
448
cc9ee605 449void probe::print (ostream& o) const
56099f08
FCE
450{
451 o << "probe ";
40a1cb62
FCE
452 printsig (o);
453 o << *body;
454}
455
456
cc9ee605 457void probe::printsig (ostream& o) const
40a1cb62 458{
9c0c0e46 459 for (unsigned i=0; i<locations.size(); i++)
56099f08 460 {
2930abc7 461 if (i > 0) o << "," << endl;
9c0c0e46 462 locations[i]->print (o);
56099f08 463 }
56099f08
FCE
464}
465
466
cc9ee605 467void probe_point::print (ostream& o) const
56099f08 468{
9c0c0e46
FCE
469 for (unsigned i=0; i<components.size(); i++)
470 {
471 if (i>0) o << ".";
472 probe_point::component* c = components[i];
473 o << c->functor;
474 if (c->arg)
475 o << "(" << *c->arg << ")";
476 }
56099f08
FCE
477}
478
cc9ee605 479
20c6c071
GH
480probe_alias::probe_alias(std::vector<probe_point*> const & aliases):
481 probe (), alias_names (aliases)
482{
483}
484
cc9ee605 485void probe_alias::printsig (ostream& o) const
20c6c071
GH
486{
487 for (unsigned i=0; i<alias_names.size(); i++)
488 {
489 o << (i>0 ? " = " : "");
490 alias_names[i]->print (o);
491 }
5227f1ea 492 o << " = ";
20c6c071
GH
493 for (unsigned i=0; i<locations.size(); i++)
494 {
495 o << (i>0 ? ", " : "");
496 locations[i]->print (o);
497 }
498}
499
56099f08 500
cc9ee605 501ostream& operator << (ostream& o, const probe_point& k)
82919855
FCE
502{
503 k.print (o);
504 return o;
505}
506
507
cc9ee605 508ostream& operator << (ostream& o, const symboldecl& k)
56099f08
FCE
509{
510 k.print (o);
511 return o;
512}
513
514
82919855
FCE
515
516// ------------------------------------------------------------------------
517// visitors
518
519
520void
521block::visit (visitor* u)
522{
523 u->visit_block (this);
524}
525
54dfabe9
FCE
526
527void
528embeddedcode::visit (visitor* u)
529{
530 u->visit_embeddedcode (this);
531}
532
533
82919855
FCE
534void
535for_loop::visit (visitor* u)
536{
537 u->visit_for_loop (this);
538}
539
69c68955
FCE
540void
541foreach_loop::visit (visitor* u)
542{
543 u->visit_foreach_loop (this);
544}
545
82919855
FCE
546void
547null_statement::visit (visitor* u)
548{
549 u->visit_null_statement (this);
550}
551
552void
553expr_statement::visit (visitor* u)
554{
555 u->visit_expr_statement (this);
556}
557
558void
559return_statement::visit (visitor* u)
560{
561 u->visit_return_statement (this);
562}
563
564void
565delete_statement::visit (visitor* u)
566{
d7f3e0c5 567 u->push_active_lvalue (this->value);
82919855 568 u->visit_delete_statement (this);
d7f3e0c5 569 u->pop_active_lvalue ();
82919855
FCE
570}
571
572void
573if_statement::visit (visitor* u)
574{
575 u->visit_if_statement (this);
576}
577
f3c26ea5
FCE
578void
579next_statement::visit (visitor* u)
580{
581 u->visit_next_statement (this);
582}
583
584void
585break_statement::visit (visitor* u)
586{
587 u->visit_break_statement (this);
588}
589
590void
591continue_statement::visit (visitor* u)
592{
593 u->visit_continue_statement (this);
594}
595
82919855
FCE
596void
597literal_string::visit(visitor* u)
598{
599 u->visit_literal_string (this);
600}
601
602void
603literal_number::visit(visitor* u)
604{
605 u->visit_literal_number (this);
606}
607
608void
609binary_expression::visit (visitor* u)
610{
611 u->visit_binary_expression (this);
612}
613
614void
615unary_expression::visit (visitor* u)
616{
617 u->visit_unary_expression (this);
618}
619
620void
621pre_crement::visit (visitor* u)
622{
d7f3e0c5 623 u->push_active_lvalue (this->operand);
82919855 624 u->visit_pre_crement (this);
d7f3e0c5 625 u->pop_active_lvalue ();
82919855
FCE
626}
627
628void
629post_crement::visit (visitor* u)
630{
d7f3e0c5 631 u->push_active_lvalue (this->operand);
82919855 632 u->visit_post_crement (this);
d7f3e0c5 633 u->pop_active_lvalue ();
82919855
FCE
634}
635
636void
637logical_or_expr::visit (visitor* u)
638{
639 u->visit_logical_or_expr (this);
640}
641
642void
643logical_and_expr::visit (visitor* u)
644{
645 u->visit_logical_and_expr (this);
646}
647
648void
649array_in::visit (visitor* u)
650{
651 u->visit_array_in (this);
652}
653
654void
655comparison::visit (visitor* u)
656{
657 u->visit_comparison (this);
658}
659
660void
661concatenation::visit (visitor* u)
662{
663 u->visit_concatenation (this);
664}
665
82919855
FCE
666void
667ternary_expression::visit (visitor* u)
668{
669 u->visit_ternary_expression (this);
670}
671
672void
673assignment::visit (visitor* u)
674{
d7f3e0c5 675 u->push_active_lvalue (this->left);
82919855 676 u->visit_assignment (this);
d7f3e0c5 677 u->pop_active_lvalue ();
82919855
FCE
678}
679
680void
681symbol::visit (visitor* u)
682{
683 u->visit_symbol (this);
684}
685
d7f3e0c5
GH
686void
687target_symbol::visit (visitor* u)
688{
689 u->visit_target_symbol(this);
690}
691
82919855
FCE
692void
693arrayindex::visit (visitor* u)
694{
695 u->visit_arrayindex (this);
696}
697
698void
699functioncall::visit (visitor* u)
700{
701 u->visit_functioncall (this);
702}
703
d7f3e0c5
GH
704// ------------------------------------------------------------------------
705
706bool
707visitor::is_active_lvalue(expression *e)
708{
709 for (unsigned i = 0; i < active_lvalues.size(); ++i)
710 {
711 if (active_lvalues[i] == e)
712 return true;
713 }
714 return false;
715}
716
717void
718visitor::push_active_lvalue(expression *e)
719{
720 active_lvalues.push_back(e);
721}
722
723void
724visitor::pop_active_lvalue()
725{
726 assert(!active_lvalues.empty());
727 active_lvalues.pop_back();
728}
729
730
82919855
FCE
731
732// ------------------------------------------------------------------------
733
734void
54dfabe9 735traversing_visitor::visit_block (block* s)
82919855
FCE
736{
737 for (unsigned i=0; i<s->statements.size(); i++)
738 s->statements[i]->visit (this);
739}
740
741void
54dfabe9
FCE
742traversing_visitor::visit_embeddedcode (embeddedcode* s)
743{
744}
745
746void
747traversing_visitor::visit_null_statement (null_statement* s)
82919855
FCE
748{
749}
750
751void
54dfabe9 752traversing_visitor::visit_expr_statement (expr_statement* s)
82919855
FCE
753{
754 s->value->visit (this);
755}
756
757void
758traversing_visitor::visit_if_statement (if_statement* s)
759{
760 s->condition->visit (this);
761 s->thenblock->visit (this);
2b066ec1
FCE
762 if (s->elseblock)
763 s->elseblock->visit (this);
82919855
FCE
764}
765
766void
767traversing_visitor::visit_for_loop (for_loop* s)
768{
769 s->init->visit (this);
770 s->cond->visit (this);
771 s->incr->visit (this);
772 s->block->visit (this);
773}
774
69c68955
FCE
775void
776traversing_visitor::visit_foreach_loop (foreach_loop* s)
777{
778 for (unsigned i=0; i<s->indexes.size(); i++)
779 s->indexes[i]->visit (this);
780 s->block->visit (this);
781}
782
82919855
FCE
783void
784traversing_visitor::visit_return_statement (return_statement* s)
785{
786 s->value->visit (this);
787}
788
789void
790traversing_visitor::visit_delete_statement (delete_statement* s)
791{
792 s->value->visit (this);
793}
794
f3c26ea5
FCE
795void
796traversing_visitor::visit_next_statement (next_statement* s)
797{
798}
799
800void
801traversing_visitor::visit_break_statement (break_statement* s)
802{
803}
804
805void
806traversing_visitor::visit_continue_statement (continue_statement* s)
807{
808}
809
82919855
FCE
810void
811traversing_visitor::visit_literal_string (literal_string* e)
812{
813}
814
815void
816traversing_visitor::visit_literal_number (literal_number* e)
817{
818}
819
820void
821traversing_visitor::visit_binary_expression (binary_expression* e)
822{
823 e->left->visit (this);
824 e->right->visit (this);
825}
826
827void
828traversing_visitor::visit_unary_expression (unary_expression* e)
829{
830 e->operand->visit (this);
831}
832
833void
834traversing_visitor::visit_pre_crement (pre_crement* e)
835{
836 e->operand->visit (this);
837}
838
839void
840traversing_visitor::visit_post_crement (post_crement* e)
841{
842 e->operand->visit (this);
843}
844
845
846void
847traversing_visitor::visit_logical_or_expr (logical_or_expr* e)
848{
849 e->left->visit (this);
850 e->right->visit (this);
851}
852
853void
854traversing_visitor::visit_logical_and_expr (logical_and_expr* e)
855{
856 e->left->visit (this);
857 e->right->visit (this);
858}
859
860void
861traversing_visitor::visit_array_in (array_in* e)
862{
ce10591c 863 e->operand->visit (this);
82919855
FCE
864}
865
866void
867traversing_visitor::visit_comparison (comparison* e)
868{
869 e->left->visit (this);
870 e->right->visit (this);
871}
872
873void
874traversing_visitor::visit_concatenation (concatenation* e)
875{
876 e->left->visit (this);
877 e->right->visit (this);
878}
879
82919855
FCE
880void
881traversing_visitor::visit_ternary_expression (ternary_expression* e)
882{
883 e->cond->visit (this);
884 e->truevalue->visit (this);
885 e->falsevalue->visit (this);
886}
887
888void
889traversing_visitor::visit_assignment (assignment* e)
890{
891 e->left->visit (this);
892 e->right->visit (this);
893}
894
895void
896traversing_visitor::visit_symbol (symbol* e)
897{
898}
899
d7f3e0c5
GH
900void
901traversing_visitor::visit_target_symbol (target_symbol* e)
902{
903}
904
82919855
FCE
905void
906traversing_visitor::visit_arrayindex (arrayindex* e)
907{
908 for (unsigned i=0; i<e->indexes.size(); i++)
909 e->indexes[i]->visit (this);
910}
911
912void
913traversing_visitor::visit_functioncall (functioncall* e)
914{
915 for (unsigned i=0; i<e->args.size(); i++)
916 e->args[i]->visit (this);
917}
918
919
920// ------------------------------------------------------------------------
921
922
923throwing_visitor::throwing_visitor (const std::string& m): msg (m) {}
924throwing_visitor::throwing_visitor (): msg ("invalid element") {}
925
926
927void
928throwing_visitor::throwone (const token* t)
929{
930 throw semantic_error (msg, t);
931}
932
933void
54dfabe9
FCE
934throwing_visitor::visit_block (block* s)
935{
936 throwone (s->tok);
937}
938
939void
940throwing_visitor::visit_embeddedcode (embeddedcode* s)
82919855
FCE
941{
942 throwone (s->tok);
943}
944
945void
54dfabe9 946throwing_visitor::visit_null_statement (null_statement* s)
82919855
FCE
947{
948 throwone (s->tok);
949}
950
951void
54dfabe9 952throwing_visitor::visit_expr_statement (expr_statement* s)
82919855
FCE
953{
954 throwone (s->tok);
955}
956
957void
958throwing_visitor::visit_if_statement (if_statement* s)
959{
960 throwone (s->tok);
961}
962
963void
964throwing_visitor::visit_for_loop (for_loop* s)
965{
966 throwone (s->tok);
967}
968
69c68955
FCE
969void
970throwing_visitor::visit_foreach_loop (foreach_loop* s)
971{
972 throwone (s->tok);
973}
974
82919855
FCE
975void
976throwing_visitor::visit_return_statement (return_statement* s)
977{
978 throwone (s->tok);
979}
980
981void
982throwing_visitor::visit_delete_statement (delete_statement* s)
983{
984 throwone (s->tok);
985}
986
f3c26ea5
FCE
987void
988throwing_visitor::visit_next_statement (next_statement* s)
989{
990 throwone (s->tok);
991}
992
993void
994throwing_visitor::visit_break_statement (break_statement* s)
995{
996 throwone (s->tok);
997}
998
999void
1000throwing_visitor::visit_continue_statement (continue_statement* s)
1001{
1002 throwone (s->tok);
1003}
1004
82919855
FCE
1005void
1006throwing_visitor::visit_literal_string (literal_string* e)
1007{
1008 throwone (e->tok);
1009}
1010
1011void
1012throwing_visitor::visit_literal_number (literal_number* e)
1013{
1014 throwone (e->tok);
1015}
1016
1017void
1018throwing_visitor::visit_binary_expression (binary_expression* e)
1019{
1020 throwone (e->tok);
1021}
1022
1023void
1024throwing_visitor::visit_unary_expression (unary_expression* e)
1025{
1026 throwone (e->tok);
1027}
1028
1029void
1030throwing_visitor::visit_pre_crement (pre_crement* e)
1031{
1032 throwone (e->tok);
1033}
1034
1035void
1036throwing_visitor::visit_post_crement (post_crement* e)
1037{
1038 throwone (e->tok);
0054a7ea
FCE
1039}
1040
1041
82919855
FCE
1042void
1043throwing_visitor::visit_logical_or_expr (logical_or_expr* e)
1044{
1045 throwone (e->tok);
1046}
1047
1048void
1049throwing_visitor::visit_logical_and_expr (logical_and_expr* e)
1050{
1051 throwone (e->tok);
1052}
1053
1054void
1055throwing_visitor::visit_array_in (array_in* e)
1056{
1057 throwone (e->tok);
1058}
1059
1060void
1061throwing_visitor::visit_comparison (comparison* e)
1062{
1063 throwone (e->tok);
1064}
1065
1066void
1067throwing_visitor::visit_concatenation (concatenation* e)
1068{
1069 throwone (e->tok);
1070}
1071
82919855
FCE
1072void
1073throwing_visitor::visit_ternary_expression (ternary_expression* e)
1074{
1075 throwone (e->tok);
1076}
1077
1078void
1079throwing_visitor::visit_assignment (assignment* e)
1080{
1081 throwone (e->tok);
1082}
1083
1084void
1085throwing_visitor::visit_symbol (symbol* e)
1086{
1087 throwone (e->tok);
1088}
1089
d7f3e0c5
GH
1090void
1091throwing_visitor::visit_target_symbol (target_symbol* e)
1092{
1093 throwone (e->tok);
1094}
1095
82919855
FCE
1096void
1097throwing_visitor::visit_arrayindex (arrayindex* e)
1098{
1099 throwone (e->tok);
1100}
1101
1102void
1103throwing_visitor::visit_functioncall (functioncall* e)
1104{
1105 throwone (e->tok);
1106}
85365d1b
GH
1107
1108
1109// ------------------------------------------------------------------------
1110
85365d1b
GH
1111
1112void
54dfabe9 1113deep_copy_visitor::visit_block (block* s)
85365d1b 1114{
54dfabe9 1115 block* n = new block;
67c0a579 1116 n->tok = s->tok;
85365d1b
GH
1117 for (unsigned i = 0; i < s->statements.size(); ++i)
1118 {
54dfabe9 1119 statement* ns;
85365d1b
GH
1120 require <statement*> (this, &ns, s->statements[i]);
1121 n->statements.push_back(ns);
1122 }
1123 provide <block*> (this, n);
1124}
1125
1126void
54dfabe9
FCE
1127deep_copy_visitor::visit_embeddedcode (embeddedcode* s)
1128{
1129 embeddedcode* n = new embeddedcode;
1130 n->tok = s->tok;
1131 n->code = s->code;
1132 provide <embeddedcode*> (this, n);
1133}
1134
1135void
1136deep_copy_visitor::visit_null_statement (null_statement* s)
85365d1b 1137{
54dfabe9 1138 null_statement* n = new null_statement;
67c0a579
GH
1139 n->tok = s->tok;
1140 provide <null_statement*> (this, n);
85365d1b
GH
1141}
1142
1143void
54dfabe9 1144deep_copy_visitor::visit_expr_statement (expr_statement* s)
85365d1b 1145{
54dfabe9 1146 expr_statement* n = new expr_statement;
67c0a579 1147 n->tok = s->tok;
85365d1b
GH
1148 require <expression*> (this, &(n->value), s->value);
1149 provide <expr_statement*> (this, n);
1150}
1151
1152void
1153deep_copy_visitor::visit_if_statement (if_statement* s)
1154{
54dfabe9 1155 if_statement* n = new if_statement;
67c0a579 1156 n->tok = s->tok;
85365d1b
GH
1157 require <expression*> (this, &(n->condition), s->condition);
1158 require <statement*> (this, &(n->thenblock), s->thenblock);
c37f6b36 1159 require <statement*> (this, &(n->elseblock), s->elseblock);
85365d1b
GH
1160 provide <if_statement*> (this, n);
1161}
1162
1163void
1164deep_copy_visitor::visit_for_loop (for_loop* s)
1165{
54dfabe9 1166 for_loop* n = new for_loop;
67c0a579 1167 n->tok = s->tok;
85365d1b
GH
1168 require <expr_statement*> (this, &(n->init), s->init);
1169 require <expression*> (this, &(n->cond), s->cond);
1170 require <expr_statement*> (this, &(n->incr), s->incr);
1171 require <statement*> (this, &(n->block), s->block);
1172 provide <for_loop*> (this, n);
1173}
1174
1175void
1176deep_copy_visitor::visit_foreach_loop (foreach_loop* s)
1177{
54dfabe9 1178 foreach_loop* n = new foreach_loop;
67c0a579 1179 n->tok = s->tok;
85365d1b
GH
1180 for (unsigned i = 0; i < s->indexes.size(); ++i)
1181 {
54dfabe9 1182 symbol* sym;
85365d1b
GH
1183 require <symbol*> (this, &sym, s->indexes[i]);
1184 n->indexes.push_back(sym);
1185 }
1186 n->base = s->base;
1187 n->base_referent = NULL;
1188 require <statement*> (this, &(n->block), s->block);
1189 provide <foreach_loop*> (this, n);
1190}
1191
1192void
1193deep_copy_visitor::visit_return_statement (return_statement* s)
1194{
54dfabe9 1195 return_statement* n = new return_statement;
67c0a579 1196 n->tok = s->tok;
85365d1b
GH
1197 require <expression*> (this, &(n->value), s->value);
1198 provide <return_statement*> (this, n);
1199}
1200
1201void
1202deep_copy_visitor::visit_delete_statement (delete_statement* s)
1203{
54dfabe9 1204 delete_statement* n = new delete_statement;
67c0a579 1205 n->tok = s->tok;
85365d1b
GH
1206 require <expression*> (this, &(n->value), s->value);
1207 provide <delete_statement*> (this, n);
1208}
1209
1210void
1211deep_copy_visitor::visit_next_statement (next_statement* s)
1212{
54dfabe9 1213 next_statement* n = new next_statement;
67c0a579
GH
1214 n->tok = s->tok;
1215 provide <next_statement*> (this, n);
85365d1b
GH
1216}
1217
1218void
1219deep_copy_visitor::visit_break_statement (break_statement* s)
1220{
54dfabe9 1221 break_statement* n = new break_statement;
67c0a579
GH
1222 n->tok = s->tok;
1223 provide <break_statement*> (this, n);
85365d1b
GH
1224}
1225
1226void
1227deep_copy_visitor::visit_continue_statement (continue_statement* s)
1228{
54dfabe9 1229 continue_statement* n = new continue_statement;
67c0a579
GH
1230 n->tok = s->tok;
1231 provide <continue_statement*> (this, n);
85365d1b
GH
1232}
1233
1234void
1235deep_copy_visitor::visit_literal_string (literal_string* e)
1236{
54dfabe9 1237 literal_string* n = new literal_string(e->value);
67c0a579
GH
1238 n->tok = e->tok;
1239 provide <literal_string*> (this, n);
85365d1b
GH
1240}
1241
1242void
1243deep_copy_visitor::visit_literal_number (literal_number* e)
1244{
54dfabe9 1245 literal_number* n = new literal_number(e->value);
67c0a579
GH
1246 n->tok = e->tok;
1247 provide <literal_number*> (this, n);
85365d1b
GH
1248}
1249
1250void
1251deep_copy_visitor::visit_binary_expression (binary_expression* e)
1252{
54dfabe9 1253 binary_expression* n = new binary_expression;
85365d1b 1254 n->op = e->op;
67c0a579 1255 n->tok = e->tok;
85365d1b
GH
1256 require <expression*> (this, &(n->left), e->left);
1257 require <expression*> (this, &(n->right), e->right);
1258 provide <binary_expression*> (this, n);
1259}
1260
1261void
1262deep_copy_visitor::visit_unary_expression (unary_expression* e)
1263{
54dfabe9 1264 unary_expression* n = new unary_expression;
85365d1b 1265 n->op = e->op;
67c0a579 1266 n->tok = e->tok;
85365d1b
GH
1267 require <expression*> (this, &(n->operand), e->operand);
1268 provide <unary_expression*> (this, n);
1269}
1270
1271void
1272deep_copy_visitor::visit_pre_crement (pre_crement* e)
1273{
54dfabe9 1274 pre_crement* n = new pre_crement;
85365d1b 1275 n->op = e->op;
67c0a579 1276 n->tok = e->tok;
85365d1b
GH
1277 require <expression*> (this, &(n->operand), e->operand);
1278 provide <pre_crement*> (this, n);
1279}
1280
1281void
1282deep_copy_visitor::visit_post_crement (post_crement* e)
1283{
54dfabe9 1284 post_crement* n = new post_crement;
85365d1b 1285 n->op = e->op;
67c0a579 1286 n->tok = e->tok;
85365d1b
GH
1287 require <expression*> (this, &(n->operand), e->operand);
1288 provide <post_crement*> (this, n);
1289}
1290
1291
1292void
1293deep_copy_visitor::visit_logical_or_expr (logical_or_expr* e)
1294{
54dfabe9 1295 logical_or_expr* n = new logical_or_expr;
85365d1b 1296 n->op = e->op;
67c0a579 1297 n->tok = e->tok;
85365d1b
GH
1298 require <expression*> (this, &(n->left), e->left);
1299 require <expression*> (this, &(n->right), e->right);
1300 provide <logical_or_expr*> (this, n);
1301}
1302
1303void
1304deep_copy_visitor::visit_logical_and_expr (logical_and_expr* e)
1305{
54dfabe9 1306 logical_and_expr* n = new logical_and_expr;
85365d1b 1307 n->op = e->op;
67c0a579 1308 n->tok = e->tok;
85365d1b
GH
1309 require <expression*> (this, &(n->left), e->left);
1310 require <expression*> (this, &(n->right), e->right);
1311 provide <logical_and_expr*> (this, n);
1312}
1313
1314void
1315deep_copy_visitor::visit_array_in (array_in* e)
1316{
54dfabe9 1317 array_in* n = new array_in;
67c0a579 1318 n->tok = e->tok;
85365d1b
GH
1319 require <arrayindex*> (this, &(n->operand), e->operand);
1320 provide <array_in*> (this, n);
1321}
1322
1323void
1324deep_copy_visitor::visit_comparison (comparison* e)
1325{
54dfabe9 1326 comparison* n = new comparison;
85365d1b 1327 n->op = e->op;
67c0a579 1328 n->tok = e->tok;
85365d1b
GH
1329 require <expression*> (this, &(n->left), e->left);
1330 require <expression*> (this, &(n->right), e->right);
1331 provide <comparison*> (this, n);
1332}
1333
1334void
1335deep_copy_visitor::visit_concatenation (concatenation* e)
1336{
54dfabe9 1337 concatenation* n = new concatenation;
85365d1b 1338 n->op = e->op;
67c0a579 1339 n->tok = e->tok;
85365d1b
GH
1340 require <expression*> (this, &(n->left), e->left);
1341 require <expression*> (this, &(n->right), e->right);
1342 provide <concatenation*> (this, n);
1343}
1344
1345void
1346deep_copy_visitor::visit_ternary_expression (ternary_expression* e)
1347{
54dfabe9 1348 ternary_expression* n = new ternary_expression;
67c0a579 1349 n->tok = e->tok;
85365d1b
GH
1350 require <expression*> (this, &(n->cond), e->cond);
1351 require <expression*> (this, &(n->truevalue), e->truevalue);
1352 require <expression*> (this, &(n->falsevalue), e->falsevalue);
1353 provide <ternary_expression*> (this, n);
1354}
1355
1356void
1357deep_copy_visitor::visit_assignment (assignment* e)
1358{
54dfabe9 1359 assignment* n = new assignment;
85365d1b 1360 n->op = e->op;
67c0a579 1361 n->tok = e->tok;
85365d1b
GH
1362 require <expression*> (this, &(n->left), e->left);
1363 require <expression*> (this, &(n->right), e->right);
1364 provide <assignment*> (this, n);
1365}
1366
1367void
1368deep_copy_visitor::visit_symbol (symbol* e)
1369{
54dfabe9 1370 symbol* n = new symbol;
67c0a579 1371 n->tok = e->tok;
85365d1b
GH
1372 n->name = e->name;
1373 n->referent = NULL;
1374 provide <symbol*> (this, n);
d7f3e0c5
GH
1375}
1376
1377void
1378deep_copy_visitor::visit_target_symbol (target_symbol* e)
1379{
1380 target_symbol* n = new target_symbol;
1381 n->tok = e->tok;
1382 n->base_name = e->base_name;
1383 n->components = e->components;
1384 provide <target_symbol*> (this, n);
85365d1b
GH
1385}
1386
1387void
1388deep_copy_visitor::visit_arrayindex (arrayindex* e)
1389{
54dfabe9 1390 arrayindex* n = new arrayindex;
67c0a579 1391 n->tok = e->tok;
85365d1b
GH
1392 n->base = e->base;
1393 n->referent = NULL;
1394 for (unsigned i = 0; i < e->indexes.size(); ++i)
1395 {
54dfabe9 1396 expression* ne;
85365d1b
GH
1397 require <expression*> (this, &ne, e->indexes[i]);
1398 n->indexes.push_back(ne);
1399 }
1400 provide <arrayindex*> (this, n);
1401}
1402
1403void
1404deep_copy_visitor::visit_functioncall (functioncall* e)
1405{
54dfabe9 1406 functioncall* n = new functioncall;
67c0a579 1407 n->tok = e->tok;
85365d1b
GH
1408 n->function = e->function;
1409 n->referent = NULL;
1410 for (unsigned i = 0; i < e->args.size(); ++i)
1411 {
54dfabe9 1412 expression* na;
85365d1b
GH
1413 require <expression*> (this, &na, e->args[i]);
1414 n->args.push_back(na);
1415 }
1416 provide <functioncall*> (this, n);
1417}
1418
54dfabe9
FCE
1419block*
1420deep_copy_visitor::deep_copy (block* b)
85365d1b 1421{
54dfabe9 1422 block* n;
85365d1b
GH
1423 deep_copy_visitor v;
1424 require <block*> (&v, &n, b);
1425 return n;
1426}
1427
54dfabe9
FCE
1428statement*
1429deep_copy_visitor::deep_copy (statement* s)
85365d1b 1430{
54dfabe9 1431 statement* n;
85365d1b
GH
1432 deep_copy_visitor v;
1433 require <statement*> (&v, &n, s);
1434 return n;
1435}
This page took 0.165073 seconds and 5 git commands to generate.