]>
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 | ||
a229fcd7 GH |
70 | probe_point::probe_point (std::vector<component*> const & comps, |
71 | const token * t): | |
72 | components(comps), tok(t) | |
73 | { | |
74 | } | |
56099f08 | 75 | |
9c0c0e46 | 76 | probe_point::probe_point (): |
82919855 FCE |
77 | tok (0) |
78 | { | |
79 | } | |
80 | ||
81 | ||
82 | probe::probe (): | |
83 | body (0), tok (0) | |
9c0c0e46 FCE |
84 | { |
85 | } | |
86 | ||
87 | ||
88 | probe_point::component::component (): | |
89 | arg (0) | |
90 | { | |
91 | } | |
92 | ||
93 | ||
a229fcd7 GH |
94 | probe_point::component::component (std::string const & f, literal * a): |
95 | functor(f), arg(a) | |
96 | { | |
97 | } | |
98 | ||
99 | ||
2b066ec1 FCE |
100 | vardecl::vardecl (): |
101 | arity (-1) | |
56099f08 FCE |
102 | { |
103 | } | |
104 | ||
105 | ||
2b066ec1 FCE |
106 | void |
107 | vardecl::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 |
124 | bool |
125 | vardecl::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 | |
133 | functiondecl::functiondecl (): | |
134 | body (0) | |
135 | { | |
136 | } | |
137 | ||
138 | ||
3a20432b | 139 | literal_number::literal_number (int64_t v) |
56099f08 FCE |
140 | { |
141 | value = v; | |
142 | type = pe_long; | |
143 | } | |
144 | ||
2f1a1aea | 145 | |
56099f08 FCE |
146 | literal_string::literal_string (const string& v) |
147 | { | |
148 | value = v; | |
149 | type = pe_string; | |
150 | } | |
151 | ||
152 | ||
153 | ostream& | |
154 | operator << (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 | 171 | ostream& operator << (ostream& o, const expression& k) |
56099f08 FCE |
172 | { |
173 | k.print (o); | |
174 | return o; | |
175 | } | |
176 | ||
177 | ||
cc9ee605 | 178 | void 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 | 190 | void literal_number::print (ostream& o) const |
56099f08 FCE |
191 | { |
192 | o << value; | |
193 | } | |
194 | ||
195 | ||
cc9ee605 | 196 | void binary_expression::print (ostream& o) const |
56099f08 FCE |
197 | { |
198 | o << '(' << *left << ")" | |
199 | << op | |
200 | << '(' << *right << ")"; | |
201 | } | |
2f1a1aea FCE |
202 | |
203 | ||
cc9ee605 | 204 | void unary_expression::print (ostream& o) const |
2f1a1aea | 205 | { |
56099f08 FCE |
206 | o << op << '(' << *operand << ")"; |
207 | } | |
208 | ||
cc9ee605 | 209 | void 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 | 220 | void post_crement::print (ostream& o) const |
56099f08 FCE |
221 | { |
222 | o << '(' << *operand << ")" << op; | |
223 | } | |
224 | ||
225 | ||
cc9ee605 | 226 | void ternary_expression::print (ostream& o) const |
56099f08 | 227 | { |
ae56fddd FCE |
228 | o << "(" << *cond << ")?(" |
229 | << *truevalue << "):(" | |
56099f08 FCE |
230 | << *falsevalue << ")"; |
231 | } | |
232 | ||
233 | ||
cc9ee605 | 234 | void symbol::print (ostream& o) const |
56099f08 FCE |
235 | { |
236 | o << name; | |
237 | } | |
238 | ||
239 | ||
cc9ee605 | 240 | void 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 | 258 | void 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 | 266 | void 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 | 279 | void 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 | 289 | void 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 | 301 | void 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 | 310 | void 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 | 319 | ostream& operator << (ostream& o, const statement& k) |
56099f08 FCE |
320 | { |
321 | k.print (o); | |
322 | return o; | |
323 | } | |
324 | ||
325 | ||
cc9ee605 | 326 | void embeddedcode::print (ostream &o) const |
54dfabe9 FCE |
327 | { |
328 | o << "%{"; | |
329 | o << code; | |
330 | o << "%}"; | |
331 | } | |
332 | ||
cc9ee605 | 333 | void 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 | 342 | void 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 | 355 | void 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 | 368 | void null_statement::print (ostream& o) const |
56099f08 FCE |
369 | { |
370 | o << ";"; | |
371 | } | |
372 | ||
373 | ||
cc9ee605 | 374 | void expr_statement::print (ostream& o) const |
56099f08 FCE |
375 | { |
376 | o << *value; | |
377 | } | |
378 | ||
379 | ||
cc9ee605 | 380 | void return_statement::print (ostream& o) const |
56099f08 FCE |
381 | { |
382 | o << "return " << *value; | |
383 | } | |
384 | ||
385 | ||
cc9ee605 | 386 | void delete_statement::print (ostream& o) const |
56099f08 FCE |
387 | { |
388 | o << "delete " << *value; | |
389 | } | |
390 | ||
cc9ee605 | 391 | void next_statement::print (ostream& o) const |
f3c26ea5 FCE |
392 | { |
393 | o << "next"; | |
394 | } | |
395 | ||
cc9ee605 | 396 | void break_statement::print (ostream& o) const |
f3c26ea5 FCE |
397 | { |
398 | o << "break"; | |
399 | } | |
400 | ||
cc9ee605 | 401 | void continue_statement::print (ostream& o) const |
f3c26ea5 FCE |
402 | { |
403 | o << "continue"; | |
404 | } | |
56099f08 | 405 | |
cc9ee605 | 406 | void 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 | 415 | void 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 | 449 | void probe::print (ostream& o) const |
56099f08 FCE |
450 | { |
451 | o << "probe "; | |
40a1cb62 FCE |
452 | printsig (o); |
453 | o << *body; | |
454 | } | |
455 | ||
456 | ||
cc9ee605 | 457 | void 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 | 467 | void 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 |
480 | probe_alias::probe_alias(std::vector<probe_point*> const & aliases): |
481 | probe (), alias_names (aliases) | |
482 | { | |
483 | } | |
484 | ||
cc9ee605 | 485 | void 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 | 501 | ostream& operator << (ostream& o, const probe_point& k) |
82919855 FCE |
502 | { |
503 | k.print (o); | |
504 | return o; | |
505 | } | |
506 | ||
507 | ||
cc9ee605 | 508 | ostream& 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 | ||
520 | void | |
521 | block::visit (visitor* u) | |
522 | { | |
523 | u->visit_block (this); | |
524 | } | |
525 | ||
54dfabe9 FCE |
526 | |
527 | void | |
528 | embeddedcode::visit (visitor* u) | |
529 | { | |
530 | u->visit_embeddedcode (this); | |
531 | } | |
532 | ||
533 | ||
82919855 FCE |
534 | void |
535 | for_loop::visit (visitor* u) | |
536 | { | |
537 | u->visit_for_loop (this); | |
538 | } | |
539 | ||
69c68955 FCE |
540 | void |
541 | foreach_loop::visit (visitor* u) | |
542 | { | |
543 | u->visit_foreach_loop (this); | |
544 | } | |
545 | ||
82919855 FCE |
546 | void |
547 | null_statement::visit (visitor* u) | |
548 | { | |
549 | u->visit_null_statement (this); | |
550 | } | |
551 | ||
552 | void | |
553 | expr_statement::visit (visitor* u) | |
554 | { | |
555 | u->visit_expr_statement (this); | |
556 | } | |
557 | ||
558 | void | |
559 | return_statement::visit (visitor* u) | |
560 | { | |
561 | u->visit_return_statement (this); | |
562 | } | |
563 | ||
564 | void | |
565 | delete_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 | ||
572 | void | |
573 | if_statement::visit (visitor* u) | |
574 | { | |
575 | u->visit_if_statement (this); | |
576 | } | |
577 | ||
f3c26ea5 FCE |
578 | void |
579 | next_statement::visit (visitor* u) | |
580 | { | |
581 | u->visit_next_statement (this); | |
582 | } | |
583 | ||
584 | void | |
585 | break_statement::visit (visitor* u) | |
586 | { | |
587 | u->visit_break_statement (this); | |
588 | } | |
589 | ||
590 | void | |
591 | continue_statement::visit (visitor* u) | |
592 | { | |
593 | u->visit_continue_statement (this); | |
594 | } | |
595 | ||
82919855 FCE |
596 | void |
597 | literal_string::visit(visitor* u) | |
598 | { | |
599 | u->visit_literal_string (this); | |
600 | } | |
601 | ||
602 | void | |
603 | literal_number::visit(visitor* u) | |
604 | { | |
605 | u->visit_literal_number (this); | |
606 | } | |
607 | ||
608 | void | |
609 | binary_expression::visit (visitor* u) | |
610 | { | |
611 | u->visit_binary_expression (this); | |
612 | } | |
613 | ||
614 | void | |
615 | unary_expression::visit (visitor* u) | |
616 | { | |
617 | u->visit_unary_expression (this); | |
618 | } | |
619 | ||
620 | void | |
621 | pre_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 | ||
628 | void | |
629 | post_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 | ||
636 | void | |
637 | logical_or_expr::visit (visitor* u) | |
638 | { | |
639 | u->visit_logical_or_expr (this); | |
640 | } | |
641 | ||
642 | void | |
643 | logical_and_expr::visit (visitor* u) | |
644 | { | |
645 | u->visit_logical_and_expr (this); | |
646 | } | |
647 | ||
648 | void | |
649 | array_in::visit (visitor* u) | |
650 | { | |
651 | u->visit_array_in (this); | |
652 | } | |
653 | ||
654 | void | |
655 | comparison::visit (visitor* u) | |
656 | { | |
657 | u->visit_comparison (this); | |
658 | } | |
659 | ||
660 | void | |
661 | concatenation::visit (visitor* u) | |
662 | { | |
663 | u->visit_concatenation (this); | |
664 | } | |
665 | ||
82919855 FCE |
666 | void |
667 | ternary_expression::visit (visitor* u) | |
668 | { | |
669 | u->visit_ternary_expression (this); | |
670 | } | |
671 | ||
672 | void | |
673 | assignment::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 | ||
680 | void | |
681 | symbol::visit (visitor* u) | |
682 | { | |
683 | u->visit_symbol (this); | |
684 | } | |
685 | ||
d7f3e0c5 GH |
686 | void |
687 | target_symbol::visit (visitor* u) | |
688 | { | |
689 | u->visit_target_symbol(this); | |
690 | } | |
691 | ||
82919855 FCE |
692 | void |
693 | arrayindex::visit (visitor* u) | |
694 | { | |
695 | u->visit_arrayindex (this); | |
696 | } | |
697 | ||
698 | void | |
699 | functioncall::visit (visitor* u) | |
700 | { | |
701 | u->visit_functioncall (this); | |
702 | } | |
703 | ||
d7f3e0c5 GH |
704 | // ------------------------------------------------------------------------ |
705 | ||
706 | bool | |
707 | visitor::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 | ||
717 | void | |
718 | visitor::push_active_lvalue(expression *e) | |
719 | { | |
720 | active_lvalues.push_back(e); | |
721 | } | |
722 | ||
723 | void | |
724 | visitor::pop_active_lvalue() | |
725 | { | |
726 | assert(!active_lvalues.empty()); | |
727 | active_lvalues.pop_back(); | |
728 | } | |
729 | ||
730 | ||
82919855 FCE |
731 | |
732 | // ------------------------------------------------------------------------ | |
733 | ||
734 | void | |
54dfabe9 | 735 | traversing_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 | ||
741 | void | |
54dfabe9 FCE |
742 | traversing_visitor::visit_embeddedcode (embeddedcode* s) |
743 | { | |
744 | } | |
745 | ||
746 | void | |
747 | traversing_visitor::visit_null_statement (null_statement* s) | |
82919855 FCE |
748 | { |
749 | } | |
750 | ||
751 | void | |
54dfabe9 | 752 | traversing_visitor::visit_expr_statement (expr_statement* s) |
82919855 FCE |
753 | { |
754 | s->value->visit (this); | |
755 | } | |
756 | ||
757 | void | |
758 | traversing_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 | ||
766 | void | |
767 | traversing_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 |
775 | void |
776 | traversing_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 |
783 | void |
784 | traversing_visitor::visit_return_statement (return_statement* s) | |
785 | { | |
786 | s->value->visit (this); | |
787 | } | |
788 | ||
789 | void | |
790 | traversing_visitor::visit_delete_statement (delete_statement* s) | |
791 | { | |
792 | s->value->visit (this); | |
793 | } | |
794 | ||
f3c26ea5 FCE |
795 | void |
796 | traversing_visitor::visit_next_statement (next_statement* s) | |
797 | { | |
798 | } | |
799 | ||
800 | void | |
801 | traversing_visitor::visit_break_statement (break_statement* s) | |
802 | { | |
803 | } | |
804 | ||
805 | void | |
806 | traversing_visitor::visit_continue_statement (continue_statement* s) | |
807 | { | |
808 | } | |
809 | ||
82919855 FCE |
810 | void |
811 | traversing_visitor::visit_literal_string (literal_string* e) | |
812 | { | |
813 | } | |
814 | ||
815 | void | |
816 | traversing_visitor::visit_literal_number (literal_number* e) | |
817 | { | |
818 | } | |
819 | ||
820 | void | |
821 | traversing_visitor::visit_binary_expression (binary_expression* e) | |
822 | { | |
823 | e->left->visit (this); | |
824 | e->right->visit (this); | |
825 | } | |
826 | ||
827 | void | |
828 | traversing_visitor::visit_unary_expression (unary_expression* e) | |
829 | { | |
830 | e->operand->visit (this); | |
831 | } | |
832 | ||
833 | void | |
834 | traversing_visitor::visit_pre_crement (pre_crement* e) | |
835 | { | |
836 | e->operand->visit (this); | |
837 | } | |
838 | ||
839 | void | |
840 | traversing_visitor::visit_post_crement (post_crement* e) | |
841 | { | |
842 | e->operand->visit (this); | |
843 | } | |
844 | ||
845 | ||
846 | void | |
847 | traversing_visitor::visit_logical_or_expr (logical_or_expr* e) | |
848 | { | |
849 | e->left->visit (this); | |
850 | e->right->visit (this); | |
851 | } | |
852 | ||
853 | void | |
854 | traversing_visitor::visit_logical_and_expr (logical_and_expr* e) | |
855 | { | |
856 | e->left->visit (this); | |
857 | e->right->visit (this); | |
858 | } | |
859 | ||
860 | void | |
861 | traversing_visitor::visit_array_in (array_in* e) | |
862 | { | |
ce10591c | 863 | e->operand->visit (this); |
82919855 FCE |
864 | } |
865 | ||
866 | void | |
867 | traversing_visitor::visit_comparison (comparison* e) | |
868 | { | |
869 | e->left->visit (this); | |
870 | e->right->visit (this); | |
871 | } | |
872 | ||
873 | void | |
874 | traversing_visitor::visit_concatenation (concatenation* e) | |
875 | { | |
876 | e->left->visit (this); | |
877 | e->right->visit (this); | |
878 | } | |
879 | ||
82919855 FCE |
880 | void |
881 | traversing_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 | ||
888 | void | |
889 | traversing_visitor::visit_assignment (assignment* e) | |
890 | { | |
891 | e->left->visit (this); | |
892 | e->right->visit (this); | |
893 | } | |
894 | ||
895 | void | |
896 | traversing_visitor::visit_symbol (symbol* e) | |
897 | { | |
898 | } | |
899 | ||
d7f3e0c5 GH |
900 | void |
901 | traversing_visitor::visit_target_symbol (target_symbol* e) | |
902 | { | |
903 | } | |
904 | ||
82919855 FCE |
905 | void |
906 | traversing_visitor::visit_arrayindex (arrayindex* e) | |
907 | { | |
908 | for (unsigned i=0; i<e->indexes.size(); i++) | |
909 | e->indexes[i]->visit (this); | |
910 | } | |
911 | ||
912 | void | |
913 | traversing_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 | ||
923 | throwing_visitor::throwing_visitor (const std::string& m): msg (m) {} | |
924 | throwing_visitor::throwing_visitor (): msg ("invalid element") {} | |
925 | ||
926 | ||
927 | void | |
928 | throwing_visitor::throwone (const token* t) | |
929 | { | |
930 | throw semantic_error (msg, t); | |
931 | } | |
932 | ||
933 | void | |
54dfabe9 FCE |
934 | throwing_visitor::visit_block (block* s) |
935 | { | |
936 | throwone (s->tok); | |
937 | } | |
938 | ||
939 | void | |
940 | throwing_visitor::visit_embeddedcode (embeddedcode* s) | |
82919855 FCE |
941 | { |
942 | throwone (s->tok); | |
943 | } | |
944 | ||
945 | void | |
54dfabe9 | 946 | throwing_visitor::visit_null_statement (null_statement* s) |
82919855 FCE |
947 | { |
948 | throwone (s->tok); | |
949 | } | |
950 | ||
951 | void | |
54dfabe9 | 952 | throwing_visitor::visit_expr_statement (expr_statement* s) |
82919855 FCE |
953 | { |
954 | throwone (s->tok); | |
955 | } | |
956 | ||
957 | void | |
958 | throwing_visitor::visit_if_statement (if_statement* s) | |
959 | { | |
960 | throwone (s->tok); | |
961 | } | |
962 | ||
963 | void | |
964 | throwing_visitor::visit_for_loop (for_loop* s) | |
965 | { | |
966 | throwone (s->tok); | |
967 | } | |
968 | ||
69c68955 FCE |
969 | void |
970 | throwing_visitor::visit_foreach_loop (foreach_loop* s) | |
971 | { | |
972 | throwone (s->tok); | |
973 | } | |
974 | ||
82919855 FCE |
975 | void |
976 | throwing_visitor::visit_return_statement (return_statement* s) | |
977 | { | |
978 | throwone (s->tok); | |
979 | } | |
980 | ||
981 | void | |
982 | throwing_visitor::visit_delete_statement (delete_statement* s) | |
983 | { | |
984 | throwone (s->tok); | |
985 | } | |
986 | ||
f3c26ea5 FCE |
987 | void |
988 | throwing_visitor::visit_next_statement (next_statement* s) | |
989 | { | |
990 | throwone (s->tok); | |
991 | } | |
992 | ||
993 | void | |
994 | throwing_visitor::visit_break_statement (break_statement* s) | |
995 | { | |
996 | throwone (s->tok); | |
997 | } | |
998 | ||
999 | void | |
1000 | throwing_visitor::visit_continue_statement (continue_statement* s) | |
1001 | { | |
1002 | throwone (s->tok); | |
1003 | } | |
1004 | ||
82919855 FCE |
1005 | void |
1006 | throwing_visitor::visit_literal_string (literal_string* e) | |
1007 | { | |
1008 | throwone (e->tok); | |
1009 | } | |
1010 | ||
1011 | void | |
1012 | throwing_visitor::visit_literal_number (literal_number* e) | |
1013 | { | |
1014 | throwone (e->tok); | |
1015 | } | |
1016 | ||
1017 | void | |
1018 | throwing_visitor::visit_binary_expression (binary_expression* e) | |
1019 | { | |
1020 | throwone (e->tok); | |
1021 | } | |
1022 | ||
1023 | void | |
1024 | throwing_visitor::visit_unary_expression (unary_expression* e) | |
1025 | { | |
1026 | throwone (e->tok); | |
1027 | } | |
1028 | ||
1029 | void | |
1030 | throwing_visitor::visit_pre_crement (pre_crement* e) | |
1031 | { | |
1032 | throwone (e->tok); | |
1033 | } | |
1034 | ||
1035 | void | |
1036 | throwing_visitor::visit_post_crement (post_crement* e) | |
1037 | { | |
1038 | throwone (e->tok); | |
0054a7ea FCE |
1039 | } |
1040 | ||
1041 | ||
82919855 FCE |
1042 | void |
1043 | throwing_visitor::visit_logical_or_expr (logical_or_expr* e) | |
1044 | { | |
1045 | throwone (e->tok); | |
1046 | } | |
1047 | ||
1048 | void | |
1049 | throwing_visitor::visit_logical_and_expr (logical_and_expr* e) | |
1050 | { | |
1051 | throwone (e->tok); | |
1052 | } | |
1053 | ||
1054 | void | |
1055 | throwing_visitor::visit_array_in (array_in* e) | |
1056 | { | |
1057 | throwone (e->tok); | |
1058 | } | |
1059 | ||
1060 | void | |
1061 | throwing_visitor::visit_comparison (comparison* e) | |
1062 | { | |
1063 | throwone (e->tok); | |
1064 | } | |
1065 | ||
1066 | void | |
1067 | throwing_visitor::visit_concatenation (concatenation* e) | |
1068 | { | |
1069 | throwone (e->tok); | |
1070 | } | |
1071 | ||
82919855 FCE |
1072 | void |
1073 | throwing_visitor::visit_ternary_expression (ternary_expression* e) | |
1074 | { | |
1075 | throwone (e->tok); | |
1076 | } | |
1077 | ||
1078 | void | |
1079 | throwing_visitor::visit_assignment (assignment* e) | |
1080 | { | |
1081 | throwone (e->tok); | |
1082 | } | |
1083 | ||
1084 | void | |
1085 | throwing_visitor::visit_symbol (symbol* e) | |
1086 | { | |
1087 | throwone (e->tok); | |
1088 | } | |
1089 | ||
d7f3e0c5 GH |
1090 | void |
1091 | throwing_visitor::visit_target_symbol (target_symbol* e) | |
1092 | { | |
1093 | throwone (e->tok); | |
1094 | } | |
1095 | ||
82919855 FCE |
1096 | void |
1097 | throwing_visitor::visit_arrayindex (arrayindex* e) | |
1098 | { | |
1099 | throwone (e->tok); | |
1100 | } | |
1101 | ||
1102 | void | |
1103 | throwing_visitor::visit_functioncall (functioncall* e) | |
1104 | { | |
1105 | throwone (e->tok); | |
1106 | } | |
85365d1b GH |
1107 | |
1108 | ||
1109 | // ------------------------------------------------------------------------ | |
1110 | ||
85365d1b GH |
1111 | |
1112 | void | |
54dfabe9 | 1113 | deep_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 | ||
1126 | void | |
54dfabe9 FCE |
1127 | deep_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 | ||
1135 | void | |
1136 | deep_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 | ||
1143 | void | |
54dfabe9 | 1144 | deep_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 | ||
1152 | void | |
1153 | deep_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 | ||
1163 | void | |
1164 | deep_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 | ||
1175 | void | |
1176 | deep_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 | ||
1192 | void | |
1193 | deep_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 | ||
1201 | void | |
1202 | deep_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 | ||
1210 | void | |
1211 | deep_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 | ||
1218 | void | |
1219 | deep_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 | ||
1226 | void | |
1227 | deep_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 | ||
1234 | void | |
1235 | deep_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 | ||
1242 | void | |
1243 | deep_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 | ||
1250 | void | |
1251 | deep_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 | ||
1261 | void | |
1262 | deep_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 | ||
1271 | void | |
1272 | deep_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 | ||
1281 | void | |
1282 | deep_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 | ||
1292 | void | |
1293 | deep_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 | ||
1303 | void | |
1304 | deep_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 | ||
1314 | void | |
1315 | deep_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 | ||
1323 | void | |
1324 | deep_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 | ||
1334 | void | |
1335 | deep_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 | ||
1345 | void | |
1346 | deep_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 | ||
1356 | void | |
1357 | deep_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 | ||
1367 | void | |
1368 | deep_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 | ||
1377 | void | |
1378 | deep_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 | ||
1387 | void | |
1388 | deep_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 | ||
1403 | void | |
1404 | deep_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 |
1419 | block* |
1420 | deep_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 |
1428 | statement* |
1429 | deep_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 | } |