]> sourceware.org Git - systemtap.git/blame - staptree.h
PR18431: Function overloading
[systemtap.git] / staptree.h
CommitLineData
2f1a1aea 1// -*- C++ -*-
a3e980f9 2// Copyright (C) 2005-2015 Red Hat Inc.
9ba8c134 3// Copyright (C) 2006 Intel Corporation.
69c68955
FCE
4//
5// This file is part of systemtap, and is free software. You can
6// redistribute it and/or modify it under the terms of the GNU General
7// Public License (GPL); either version 2, or (at your option) any
8// later version.
2f1a1aea 9
82919855
FCE
10#ifndef STAPTREE_H
11#define STAPTREE_H
12
57b73400 13#include <map>
85365d1b 14#include <stack>
cbfbbf69 15#include <set>
2f1a1aea
FCE
16#include <string>
17#include <vector>
2f1a1aea 18#include <iostream>
82919855 19#include <stdexcept>
6a7bfd81 20#include <cassert>
d15d767c 21#include <typeinfo>
3a20432b
FCE
22extern "C" {
23#include <stdint.h>
24}
2f1a1aea 25
d15d767c 26#include "util.h"
47d349b1 27#include "stringtable.h"
d15d767c 28
40a393cd
JS
29#if defined(HAVE_TR1_MEMORY)
30#include <tr1/memory>
31using std::tr1::shared_ptr;
32#elif defined(HAVE_BOOST_SHARED_PTR_HPP)
33#include <boost/shared_ptr.hpp>
34using boost::shared_ptr;
35#else
36#error "No shared_ptr implementation found; get boost or modern g++"
37#endif
47d349b1 38
40a393cd 39
82919855 40struct token; // parse.h
313db8e6
DB
41struct systemtap_session; // session.h
42
82919855
FCE
43struct semantic_error: public std::runtime_error
44{
45 const token* tok1;
82919855 46 const token* tok2;
c081af73 47 std::string errsrc;
6a7bfd81 48
48f6d208
MW
49 // Extra details to explain the error or provide alternatives to the user.
50 // Each one printed after the main error message and tokens aligned on
51 // separate lines. Just push_back anything you want that better explains
52 // the error to the user (not meant for extra verbose developer messages).
53 std::vector<std::string> details;
54
c081af73
JL
55 ~semantic_error () throw ()
56 {
57 if (chain)
58 delete chain;
59 }
02c997c0 60
dc09353a 61 semantic_error (const std::string& src, const std::string& msg, const token* t1=0):
c081af73 62 runtime_error (msg), tok1 (t1), tok2 (0), errsrc (src), chain (0) {}
e26c2f83 63
dc09353a 64 semantic_error (const std::string& src, const std::string& msg, const token* t1,
c081af73
JL
65 const token* t2, const semantic_error* chn=0):
66 runtime_error (msg), tok1 (t1), tok2 (t2), errsrc (src), chain (0)
67 {
68 if (chn)
69 set_chain(*chn);
70 }
71
72 /* override copy-ctor to deep-copy chain */
73 semantic_error (const semantic_error& other):
74 runtime_error(other), tok1(other.tok1), tok2(other.tok2),
48f6d208 75 errsrc(other.errsrc), details(other.details), chain (0)
c081af73
JL
76 {
77 if (other.chain)
78 set_chain(*other.chain);
79 }
9e1a2390
JL
80
81 std::string errsrc_chain(void) const
82 {
83 return errsrc + (chain ? "|" + chain->errsrc_chain() : "");
84 }
c081af73 85
96c7f494 86 semantic_error& set_chain(const semantic_error& new_chain)
c081af73
JL
87 {
88 if (chain)
89 delete chain;
90 chain = new semantic_error(new_chain);
96c7f494 91 return *this;
c081af73
JL
92 }
93
94 const semantic_error* get_chain(void) const
95 {
96 return chain;
97 }
98
99private:
100 const semantic_error* chain;
82919855
FCE
101};
102
57b73400 103// ------------------------------------------------------------------------
82919855 104
177a8ead 105/* struct statistic_decl moved to session.h */
57b73400
GH
106
107// ------------------------------------------------------------------------
82919855 108
56099f08
FCE
109enum exp_type
110 {
111 pe_unknown,
3a20432b
FCE
112 pe_long, // int64_t
113 pe_string, // std::string
6a7bfd81 114 pe_stats
56099f08 115 };
2f1a1aea 116
2b066ec1 117std::ostream& operator << (std::ostream& o, const exp_type& e);
2f1a1aea 118
66facfa3
JS
119struct functioncall;
120struct autocast_op;
40a393cd
JS
121struct exp_type_details
122{
123 virtual ~exp_type_details () {};
124
125 // A process-wide unique identifier; probably a pointer.
126 virtual uintptr_t id () const = 0;
127 bool operator==(const exp_type_details& other) const
128 { return id () == other.id (); }
eb79eb0a
JS
129 bool operator!=(const exp_type_details& other) const
130 { return !(*this == other); }
66facfa3
JS
131
132 // Expand this autocast_op into a function call
eb79eb0a 133 virtual bool expandable() const = 0;
66facfa3 134 virtual functioncall *expand(autocast_op* e, bool lvalue) = 0;
40a393cd
JS
135};
136typedef shared_ptr<exp_type_details> exp_type_ptr;
137
138
56099f08 139struct token;
82919855 140struct visitor;
6fda2dff 141struct update_visitor;
82919855 142
d15d767c
JS
143struct visitable
144{
145 virtual ~visitable ();
146};
147
e92d43e9 148struct symbol;
d15d767c 149struct expression : public visitable
2f1a1aea 150{
56099f08 151 exp_type type;
40a393cd 152 exp_type_ptr type_details;
56099f08 153 const token* tok;
56099f08 154 expression ();
2f1a1aea 155 virtual ~expression ();
cc9ee605 156 virtual void print (std::ostream& o) const = 0;
82919855 157 virtual void visit (visitor* u) = 0;
e92d43e9 158 virtual bool is_symbol(symbol *& sym_out);
2f1a1aea
FCE
159};
160
cc9ee605 161std::ostream& operator << (std::ostream& o, const expression& k);
2f1a1aea 162
2f1a1aea
FCE
163
164struct literal: public expression
165{
166};
167
56099f08 168
2f1a1aea
FCE
169struct literal_string: public literal
170{
47d349b1
FCE
171 interned_string value;
172 literal_string (interned_string v);
cc9ee605 173 void print (std::ostream& o) const;
82919855 174 void visit (visitor* u);
2f1a1aea
FCE
175};
176
56099f08 177
2f1a1aea
FCE
178struct literal_number: public literal
179{
3a20432b 180 int64_t value;
9ea68eb9
JS
181 bool print_hex;
182 literal_number (int64_t v, bool hex=false);
cc9ee605 183 void print (std::ostream& o) const;
82919855 184 void visit (visitor* u);
2f1a1aea
FCE
185};
186
187
7d902887
FCE
188struct embedded_expr: public expression
189{
47d349b1 190 interned_string code;
7d902887
FCE
191 void print (std::ostream& o) const;
192 void visit (visitor* u);
193};
194
195
2f1a1aea
FCE
196struct binary_expression: public expression
197{
198 expression* left;
47d349b1 199 interned_string op;
2f1a1aea 200 expression* right;
cc9ee605 201 void print (std::ostream& o) const;
82919855 202 void visit (visitor* u);
2f1a1aea
FCE
203};
204
56099f08 205
2f1a1aea
FCE
206struct unary_expression: public expression
207{
47d349b1 208 interned_string op;
2f1a1aea 209 expression* operand;
cc9ee605 210 void print (std::ostream& o) const;
82919855 211 void visit (visitor* u);
2f1a1aea
FCE
212};
213
56099f08 214
2f1a1aea
FCE
215struct pre_crement: public unary_expression
216{
82919855 217 void visit (visitor* u);
2f1a1aea
FCE
218};
219
56099f08 220
2f1a1aea
FCE
221struct post_crement: public unary_expression
222{
cc9ee605 223 void print (std::ostream& o) const;
82919855 224 void visit (visitor* u);
2f1a1aea
FCE
225};
226
56099f08 227
2f1a1aea
FCE
228struct logical_or_expr: public binary_expression
229{
82919855 230 void visit (visitor* u);
2f1a1aea
FCE
231};
232
56099f08 233
2f1a1aea
FCE
234struct logical_and_expr: public binary_expression
235{
82919855 236 void visit (visitor* u);
2f1a1aea
FCE
237};
238
56099f08 239
69c68955
FCE
240struct arrayindex;
241struct array_in: public expression
2f1a1aea 242{
69c68955 243 arrayindex* operand;
cc9ee605 244 void print (std::ostream& o) const;
82919855 245 void visit (visitor* u);
2f1a1aea
FCE
246};
247
946e4bbd 248struct regex_query: public expression
93daaca8 249{
946e4bbd 250 expression* left;
47d349b1 251 interned_string op;
946e4bbd 252 literal_string* right;
93daaca8 253 void visit (visitor* u);
b4bb55ed 254 void print (std::ostream& o) const;
93daaca8 255};
56099f08 256
2f1a1aea
FCE
257struct comparison: public binary_expression
258{
82919855 259 void visit (visitor* u);
2f1a1aea
FCE
260};
261
56099f08 262
2f1a1aea
FCE
263struct concatenation: public binary_expression
264{
82919855 265 void visit (visitor* u);
2f1a1aea
FCE
266};
267
56099f08 268
2f1a1aea
FCE
269struct ternary_expression: public expression
270{
271 expression* cond;
272 expression* truevalue;
273 expression* falsevalue;
cc9ee605 274 void print (std::ostream& o) const;
82919855 275 void visit (visitor* u);
56099f08
FCE
276};
277
278
279struct assignment: public binary_expression
280{
82919855 281 void visit (visitor* u);
2f1a1aea
FCE
282};
283
d02548c0 284struct hist_op;
d15d767c 285struct indexable : public expression
d02548c0
GH
286{
287 // This is a helper class which, type-wise, acts as a disjoint union
288 // of symbols and histograms. You can ask it whether it's a
289 // histogram or a symbol, and downcast accordingly.
d02548c0
GH
290 virtual bool is_symbol(symbol *& sym_out);
291 virtual bool is_hist_op(hist_op *& hist_out);
d02548c0
GH
292 virtual ~indexable() {}
293};
294
295// Perform a downcast to one out-value and NULL the other, throwing an
296// exception if neither downcast succeeds. This is (sadly) about the
297// best we can accomplish in C++.
298void
299classify_indexable(indexable* ix,
300 symbol *& array_out,
301 hist_op *& hist_out);
302
b9aa5bb4 303struct vardecl;
d15d767c 304struct symbol: public indexable
2f1a1aea 305{
47d349b1 306 interned_string name;
56099f08
FCE
307 vardecl *referent;
308 symbol ();
cc9ee605 309 void print (std::ostream& o) const;
82919855 310 void visit (visitor* u);
d02548c0 311 // overrides of type 'indexable'
d02548c0 312 bool is_symbol(symbol *& sym_out);
2f1a1aea
FCE
313};
314
56099f08 315
bd70b999 316struct target_symbol: public expression
d7f3e0c5
GH
317{
318 enum component_type
319 {
320 comp_struct_member,
6fda2dff
JS
321 comp_literal_array_index,
322 comp_expression_array_index,
5f36109e 323 comp_pretty_print, // must be final
d7f3e0c5 324 };
c67847a0
JS
325
326 struct component
327 {
328 const token* tok;
329 component_type type;
5f36109e 330 std::string member; // comp_struct_member, comp_pretty_print
c67847a0 331 int64_t num_index; // comp_literal_array_index
6fda2dff 332 expression* expr_index; // comp_expression_array_index
c67847a0 333
5f36109e
JS
334 component(const token* t, const std::string& m, bool pprint=false):
335 tok(t),
336 type(pprint ? comp_pretty_print : comp_struct_member),
74fe61bc 337 member(m), num_index(0), expr_index(0)
5f36109e 338 {}
c67847a0 339 component(const token* t, int64_t n):
74fe61bc
LB
340 tok(t), type(comp_literal_array_index), num_index(n),
341 expr_index(0) {}
6fda2dff 342 component(const token* t, expression* e):
74fe61bc
LB
343 tok(t), type(comp_expression_array_index), num_index(0),
344 expr_index(e) {}
c67847a0
JS
345 void print (std::ostream& o) const;
346 };
347
47d349b1 348 interned_string name;
03c75a4a 349 bool addressof;
c67847a0 350 std::vector<component> components;
c69a87e0 351 semantic_error* saved_conversion_error; // hand-made linked list
03c75a4a 352 target_symbol(): addressof(false), saved_conversion_error (0) {}
bd1fcbad 353 virtual std::string sym_name ();
1af1e62d 354 void chain (const semantic_error& er);
cc9ee605 355 void print (std::ostream& o) const;
6a7bfd81 356 void visit (visitor* u);
6fda2dff
JS
357 void visit_components (visitor* u);
358 void visit_components (update_visitor* u);
5f36109e 359 void assert_no_components(const std::string& tapset, bool pretty_ok=false);
c4965ad9
JS
360 size_t pretty_print_depth () const;
361 bool check_pretty_print (bool lvalue=false) const;
d7f3e0c5
GH
362};
363
c67847a0
JS
364std::ostream& operator << (std::ostream& o, const target_symbol::component& c);
365
d7f3e0c5 366
9b5af295
JS
367struct cast_op: public target_symbol
368{
369 expression *operand;
47d349b1 370 interned_string type_name, module;
9b5af295
JS
371 void print (std::ostream& o) const;
372 void visit (visitor* u);
373};
374
251707c8
JS
375// An autocast is like an implicit @cast on any expression, like
376// (expr)->foo->var[baz], and the type is gleaned from the expr.
377struct autocast_op: public target_symbol
378{
379 expression *operand;
380 void print (std::ostream& o) const;
381 void visit (visitor* u);
382};
383
bd1fcbad
YZ
384struct atvar_op: public target_symbol
385{
47d349b1 386 interned_string target_name, cu_name, module;
bd1fcbad
YZ
387 virtual std::string sym_name ();
388 void print (std::ostream& o) const;
389 void visit (visitor* u);
390};
9b5af295 391
30263a73
FCE
392struct defined_op: public expression
393{
0fb0cac9 394 expression *operand;
30263a73
FCE
395 void print (std::ostream& o) const;
396 void visit (visitor* u);
397};
398
399
8cc799a5
JS
400struct entry_op: public expression
401{
402 expression *operand;
403 void print (std::ostream& o) const;
404 void visit (visitor* u);
405};
406
407
3689db05
SC
408struct perf_op: public expression
409{
ace7c23f 410 literal_string *operand;
3689db05
SC
411 void print (std::ostream& o) const;
412 void visit (visitor* u);
413};
414
415
56099f08 416struct arrayindex: public expression
2f1a1aea 417{
2b066ec1 418 std::vector<expression*> indexes;
d02548c0 419 indexable *base;
56099f08 420 arrayindex ();
cc9ee605 421 void print (std::ostream& o) const;
82919855 422 void visit (visitor* u);
2f1a1aea
FCE
423};
424
56099f08 425
b9aa5bb4 426struct functiondecl;
56099f08 427struct functioncall: public expression
2f1a1aea 428{
47d349b1 429 interned_string function;
2b066ec1 430 std::vector<expression*> args;
7b5b30a8 431 std::vector<functiondecl*> referents;
56099f08 432 functioncall ();
cc9ee605 433 void print (std::ostream& o) const;
82919855 434 void visit (visitor* u);
2f1a1aea
FCE
435};
436
437
d02548c0
GH
438struct print_format: public expression
439{
d02548c0 440 bool print_to_stream;
3cb17058
JS
441 bool print_with_format;
442 bool print_with_delim;
443 bool print_with_newline;
32784362 444 bool print_char;
d02548c0 445
929eb962
JS
446 // XXX match runtime/vsprintf.c's print_flag
447 // ... for use with number() & number_size()
d02548c0
GH
448 enum format_flag
449 {
450 fmt_flag_zeropad = 1,
929eb962
JS
451 fmt_flag_sign = 2,
452 fmt_flag_plus = 4,
453 fmt_flag_space = 8,
454 fmt_flag_left = 16,
455 fmt_flag_special = 32,
456 fmt_flag_large = 64,
d02548c0
GH
457 };
458
6a7bfd81 459 enum conversion_type
d02548c0
GH
460 {
461 conv_unspecified,
929eb962
JS
462 conv_pointer,
463 conv_number,
d02548c0 464 conv_string,
fecccf83 465 conv_char,
34201621 466 conv_memory,
30c94a80 467 conv_memory_hex,
dc0b623a 468 conv_literal,
b5852334 469 conv_binary
d02548c0
GH
470 };
471
34201621
DB
472 enum width_type
473 {
474 width_unspecified,
475 width_static,
476 width_dynamic
477 };
478
479 enum precision_type
480 {
481 prec_unspecified,
482 prec_static,
483 prec_dynamic
484 };
485
d02548c0
GH
486 struct format_component
487 {
929eb962 488 unsigned base;
d02548c0
GH
489 unsigned width;
490 unsigned precision;
d70e3afe
JS
491 unsigned flags : 8;
492 width_type widthtype : 8;
493 precision_type prectype : 8;
494 conversion_type type : 8;
47d349b1 495 interned_string literal_string;
07c17d67
GH
496 bool is_empty() const
497 {
6a7bfd81 498 return flags == 0
34201621
DB
499 && widthtype == width_unspecified
500 && prectype == prec_unspecified
07c17d67
GH
501 && type == conv_unspecified
502 && literal_string.empty();
503 }
d02548c0
GH
504 void clear()
505 {
c92d3b42 506 base = 0;
d02548c0 507 flags = 0;
c92d3b42 508 width = 0;
34201621 509 widthtype = width_unspecified;
82c6d474 510 precision = 0;
34201621 511 prectype = prec_unspecified;
d02548c0
GH
512 type = conv_unspecified;
513 literal_string.clear();
514 }
351373b0 515 format_component() { clear(); }
929eb962
JS
516 inline void set_flag(format_flag f) { flags |= f; }
517 inline bool test_flag(format_flag f) const { return flags & f; }
d02548c0
GH
518 };
519
a9c62ac9 520 std::string raw_components;
d02548c0 521 std::vector<format_component> components;
d70e3afe 522 interned_string delimiter;
d02548c0 523 std::vector<expression*> args;
a4636912 524 hist_op *hist;
d02548c0
GH
525
526 static std::string components_to_string(std::vector<format_component> const & components);
2ec92b34 527 static std::vector<format_component> string_to_components(std::string const & str);
1c922ad7 528 static print_format* create(const token *t, const char *n = NULL);
d02548c0
GH
529
530 void print (std::ostream& o) const;
531 void visit (visitor* u);
d5e178c1
JS
532
533private:
45a63356 534 interned_string print_format_type;
28ef3a4c 535 print_format(bool stream, bool format, bool delim, bool newline, bool _char, interned_string type):
d5e178c1
JS
536 print_to_stream(stream), print_with_format(format),
537 print_with_delim(delim), print_with_newline(newline),
1c922ad7 538 print_char(_char), hist(NULL), print_format_type(type)
d5e178c1 539 {}
d02548c0
GH
540};
541
542
543enum stat_component_type
544 {
545 sc_average,
546 sc_count,
547 sc_sum,
548 sc_min,
549 sc_max,
fd5689dc 550 sc_none,
d02548c0
GH
551 };
552
553struct stat_op: public expression
6a7bfd81 554{
d02548c0
GH
555 stat_component_type ctype;
556 expression* stat;
557 void print (std::ostream& o) const;
558 void visit (visitor* u);
559};
560
561enum histogram_type
562 {
563 hist_linear,
564 hist_log
565 };
566
567struct hist_op: public indexable
568{
d02548c0
GH
569 histogram_type htype;
570 expression* stat;
571 std::vector<int64_t> params;
572 void print (std::ostream& o) const;
6a7bfd81 573 void visit (visitor* u);
d02548c0 574 // overrides of type 'indexable'
d02548c0
GH
575 bool is_hist_op(hist_op *& hist_out);
576};
577
56099f08
FCE
578// ------------------------------------------------------------------------
579
580
6a7bfd81 581struct symboldecl // unique object per (possibly implicit)
56099f08
FCE
582 // symbol declaration
583{
584 const token* tok;
a07a2c28 585 const token* systemtap_v_conditional; //checking systemtap compatibility
9fef07ff
DS
586 interned_string name; // mangled name
587 interned_string unmangled_name;
56099f08 588 exp_type type;
eb79eb0a 589 exp_type_ptr type_details;
56099f08
FCE
590 symboldecl ();
591 virtual ~symboldecl ();
cc9ee605
FCE
592 virtual void print (std::ostream &o) const = 0;
593 virtual void printsig (std::ostream &o) const = 0;
56099f08
FCE
594};
595
596
cc9ee605 597std::ostream& operator << (std::ostream& o, const symboldecl& k);
56099f08
FCE
598
599
600struct vardecl: public symboldecl
601{
cc9ee605
FCE
602 void print (std::ostream& o) const;
603 void printsig (std::ostream& o) const;
56099f08 604 vardecl ();
58701b78 605 void set_arity (int arity, const token* t);
313b2f74 606 bool compatible_arity (int a);
58701b78 607 const token* arity_tok; // site where arity was first resolved
2b066ec1 608 int arity; // -1: unknown; 0: scalar; >0: array
ef474d24 609 int maxsize; // upperbound on size for arrays
2b066ec1 610 std::vector<exp_type> index_types; // for arrays only
9ba8c134 611 literal *init; // for global scalars only
69aa668e 612 bool synthetic; // for probe locals only, don't init on entry
74e6cc92 613 bool wrap;
e92d43e9 614 bool char_ptr_arg; // set in ::emit_common_header(), only used if a formal_arg
56099f08
FCE
615};
616
617
0fefb486
FCE
618struct vardecl_builtin: public vardecl
619{
620};
621
54dfabe9 622struct statement;
56099f08
FCE
623struct functiondecl: public symboldecl
624{
2b066ec1
FCE
625 std::vector<vardecl*> formal_args;
626 std::vector<vardecl*> locals;
c3a3c0c9 627 std::vector<vardecl*> unused_locals;
54dfabe9 628 statement* body;
59de45f1 629 bool synthetic;
49b68a33 630 bool mangle_oldstyle;
7b5b30a8 631 int64_t priority;
56099f08 632 functiondecl ();
cc9ee605
FCE
633 void print (std::ostream& o) const;
634 void printsig (std::ostream& o) const;
eb9ea966 635 void printsigtags (std::ostream& o, bool all_tags) const;
f8809d54 636 void join (systemtap_session& s); // for synthetic functions only
56099f08
FCE
637};
638
7b5b30a8
FL
639struct function_priority_order
640{
641 bool operator() (const functiondecl* f1, const functiondecl* f2)
642 {
643 return f1->priority < f2->priority;
644 }
645};
646
56099f08
FCE
647
648// ------------------------------------------------------------------------
649
650
d15d767c 651struct statement : public visitable
2f1a1aea 652{
cc9ee605 653 virtual void print (std::ostream& o) const = 0;
82919855 654 virtual void visit (visitor* u) = 0;
56099f08
FCE
655 const token* tok;
656 statement ();
f946b10f 657 statement (const token* tok);
2f1a1aea
FCE
658 virtual ~statement ();
659};
660
cc9ee605 661std::ostream& operator << (std::ostream& o, const statement& k);
2f1a1aea
FCE
662
663
54dfabe9
FCE
664struct embeddedcode: public statement
665{
47d349b1 666 interned_string code;
cc9ee605 667 void print (std::ostream& o) const;
54dfabe9
FCE
668 void visit (visitor* u);
669};
670
671
2f1a1aea
FCE
672struct block: public statement
673{
2b066ec1 674 std::vector<statement*> statements;
cc9ee605 675 void print (std::ostream& o) const;
82919855 676 void visit (visitor* u);
ba6f838d
FCE
677 block () {}
678 block (statement* car, statement* cdr);
4310926e 679 virtual ~block () {}
2f1a1aea
FCE
680};
681
69c68955 682
f4fe2e93
FCE
683struct try_block: public statement
684{
fdba3aba
JS
685 statement* try_block; // may be 0
686 statement* catch_block; // may be 0
f4fe2e93
FCE
687 symbol* catch_error_var; // may be 0
688 void print (std::ostream& o) const;
689 void visit (visitor* u);
690};
691
692
f3c26ea5 693struct expr_statement;
2f1a1aea
FCE
694struct for_loop: public statement
695{
cbfbbf69 696 expr_statement* init; // may be 0
2f1a1aea 697 expression* cond;
cbfbbf69 698 expr_statement* incr; // may be 0
2f1a1aea 699 statement* block;
cc9ee605 700 void print (std::ostream& o) const;
82919855 701 void visit (visitor* u);
2f1a1aea
FCE
702};
703
56099f08 704
69c68955
FCE
705struct foreach_loop: public statement
706{
707 // this part is a specialization of arrayindex
708 std::vector<symbol*> indexes;
3040bf3a 709 std::vector<expression*> array_slice; // optional array slice to iterate over
d02548c0 710 indexable *base;
93484556
FCE
711 int sort_direction; // -1: decreasing, 0: none, 1: increasing
712 unsigned sort_column; // 0: value, 1..N: index
fd5689dc 713 enum stat_component_type sort_aggr; // for aggregate arrays, which aggregate to sort on
c261711d 714 symbol* value; // optional iteration value
27f21e8c 715 expression* limit; // optional iteration limit
69c68955
FCE
716
717 statement* block;
cc9ee605 718 void print (std::ostream& o) const;
69c68955
FCE
719 void visit (visitor* u);
720};
721
722
2f1a1aea
FCE
723struct null_statement: public statement
724{
cc9ee605 725 void print (std::ostream& o) const;
82919855 726 void visit (visitor* u);
f946b10f 727 null_statement (const token* tok);
2f1a1aea
FCE
728};
729
2f1a1aea
FCE
730
731struct expr_statement: public statement
732{
733 expression* value; // executed for side-effects
cc9ee605 734 void print (std::ostream& o) const;
82919855 735 void visit (visitor* u);
2f1a1aea
FCE
736};
737
56099f08 738
2f1a1aea
FCE
739struct if_statement: public statement
740{
741 expression* condition;
742 statement* thenblock;
cbfbbf69 743 statement* elseblock; // may be 0
cc9ee605 744 void print (std::ostream& o) const;
82919855 745 void visit (visitor* u);
56099f08
FCE
746};
747
748
749struct return_statement: public expr_statement
750{
cc9ee605 751 void print (std::ostream& o) const;
82919855 752 void visit (visitor* u);
56099f08
FCE
753};
754
755
756struct delete_statement: public expr_statement
757{
cc9ee605 758 void print (std::ostream& o) const;
82919855 759 void visit (visitor* u);
2f1a1aea
FCE
760};
761
2f1a1aea 762
f3c26ea5
FCE
763struct break_statement: public statement
764{
cc9ee605 765 void print (std::ostream& o) const;
f3c26ea5
FCE
766 void visit (visitor* u);
767};
768
769
770struct continue_statement: public statement
771{
cc9ee605 772 void print (std::ostream& o) const;
f3c26ea5
FCE
773 void visit (visitor* u);
774};
775
776
777struct next_statement: public statement
778{
cc9ee605 779 void print (std::ostream& o) const;
f3c26ea5
FCE
780 void visit (visitor* u);
781};
782
783
56099f08 784struct probe;
c3a3c0c9 785struct derived_probe;
20c6c071 786struct probe_alias;
54dfabe9 787struct embeddedcode;
2f1a1aea
FCE
788struct stapfile
789{
2b066ec1
FCE
790 std::string name;
791 std::vector<probe*> probes;
20c6c071 792 std::vector<probe_alias*> aliases;
2b066ec1
FCE
793 std::vector<functiondecl*> functions;
794 std::vector<vardecl*> globals;
54dfabe9 795 std::vector<embeddedcode*> embeds;
47d349b1 796 interned_string file_contents;
377b8831 797 bool privileged;
101b0805 798 bool synthetic; // via parse_synthetic_*
4915b3e4 799 stapfile ():
101b0805 800 privileged (false), synthetic (false) {}
cc9ee605 801 void print (std::ostream& o) const;
2f1a1aea
FCE
802};
803
804
9c0c0e46
FCE
805struct probe_point
806{
807 struct component // XXX: sort of a restricted functioncall
6a7bfd81 808 {
47d349b1 809 interned_string functor;
82919855 810 literal* arg; // optional
d2eaa03b 811 bool from_glob;
9c0c0e46 812 component ();
f1a0157a 813 const token* tok; // points to component's functor
47d349b1 814 component(interned_string f, literal *a=NULL, bool from_glob=false);
9c0c0e46 815 };
2b066ec1 816 std::vector<component*> components;
6e3347a9 817 bool optional;
d898100a 818 bool sufficient;
e2fee59d 819 bool well_formed; // used in derived_probe::script_location()
cbbe8080 820 expression* condition;
37ae3931 821 void print (std::ostream& o, bool print_extras=true) const;
9c0c0e46 822 probe_point ();
1939ea32 823 probe_point(const probe_point& pp);
f1a0157a 824 probe_point(std::vector<component*> const & comps);
37ae3931 825 std::string str(bool print_extras=true) const;
d2eaa03b 826 bool from_globby_comp(const std::string& comp);
2f1a1aea
FCE
827};
828
cc9ee605 829std::ostream& operator << (std::ostream& o, const probe_point& k);
82919855 830
2f1a1aea
FCE
831
832struct probe
833{
1341a03c
JS
834 static unsigned last_probeidx;
835
2b066ec1 836 std::vector<probe_point*> locations;
ba6f838d 837 statement* body;
d885563b 838 struct probe* base;
82919855 839 const token* tok;
5750ecc6 840 const token* systemtap_v_conditional; //checking systemtap compatibility
2b066ec1 841 std::vector<vardecl*> locals;
c3a3c0c9 842 std::vector<vardecl*> unused_locals;
1341a03c
JS
843 bool privileged;
844 unsigned id;
845
82919855 846 probe ();
d885563b 847 probe (probe* p, probe_point *l);
cc9ee605 848 void print (std::ostream& o) const;
1341a03c 849 std::string name () const;
cc9ee605 850 virtual void printsig (std::ostream &o) const;
d885563b
FCE
851 virtual void collect_derivation_chain (std::vector<probe*> &probes_list) const;
852 virtual void collect_derivation_pp_chain (std::vector<probe_point*> &) const;
2c5a19c6 853 virtual const probe_alias *get_alias () const { return 0; }
8eb6206c 854 virtual probe_point *get_alias_loc () const { return 0; }
20c6c071 855 virtual ~probe() {}
1341a03c
JS
856
857private:
858
859 probe (const probe&);
860 probe& operator = (const probe&);
2f1a1aea 861};
82919855 862
54dfabe9 863struct probe_alias: public probe
20c6c071
GH
864{
865 probe_alias(std::vector<probe_point*> const & aliases);
6a7bfd81 866 std::vector<probe_point*> alias_names;
cc9ee605 867 virtual void printsig (std::ostream &o) const;
97266278 868 bool epilogue_style;
20c6c071 869};
82919855
FCE
870
871
f4b28491 872// A derived visitor instance is used to visit the entire
82919855
FCE
873// statement/expression tree.
874struct visitor
875{
d7f3e0c5
GH
876 // Machinery for differentiating lvalue visits from non-lvalue.
877 std::vector<expression *> active_lvalues;
878 bool is_active_lvalue(expression *e);
879 void push_active_lvalue(expression *e);
880 void pop_active_lvalue();
881
82919855
FCE
882 virtual ~visitor () {}
883 virtual void visit_block (block *s) = 0;
f4fe2e93 884 virtual void visit_try_block (try_block *s) = 0;
54dfabe9 885 virtual void visit_embeddedcode (embeddedcode *s) = 0;
82919855
FCE
886 virtual void visit_null_statement (null_statement *s) = 0;
887 virtual void visit_expr_statement (expr_statement *s) = 0;
888 virtual void visit_if_statement (if_statement* s) = 0;
889 virtual void visit_for_loop (for_loop* s) = 0;
69c68955 890 virtual void visit_foreach_loop (foreach_loop* s) = 0;
82919855
FCE
891 virtual void visit_return_statement (return_statement* s) = 0;
892 virtual void visit_delete_statement (delete_statement* s) = 0;
f3c26ea5
FCE
893 virtual void visit_next_statement (next_statement* s) = 0;
894 virtual void visit_break_statement (break_statement* s) = 0;
895 virtual void visit_continue_statement (continue_statement* s) = 0;
82919855
FCE
896 virtual void visit_literal_string (literal_string* e) = 0;
897 virtual void visit_literal_number (literal_number* e) = 0;
7d902887 898 virtual void visit_embedded_expr (embedded_expr* e) = 0;
82919855
FCE
899 virtual void visit_binary_expression (binary_expression* e) = 0;
900 virtual void visit_unary_expression (unary_expression* e) = 0;
901 virtual void visit_pre_crement (pre_crement* e) = 0;
902 virtual void visit_post_crement (post_crement* e) = 0;
903 virtual void visit_logical_or_expr (logical_or_expr* e) = 0;
904 virtual void visit_logical_and_expr (logical_and_expr* e) = 0;
905 virtual void visit_array_in (array_in* e) = 0;
93daaca8 906 virtual void visit_regex_query (regex_query* e) = 0;
82919855
FCE
907 virtual void visit_comparison (comparison* e) = 0;
908 virtual void visit_concatenation (concatenation* e) = 0;
82919855
FCE
909 virtual void visit_ternary_expression (ternary_expression* e) = 0;
910 virtual void visit_assignment (assignment* e) = 0;
911 virtual void visit_symbol (symbol* e) = 0;
d7f3e0c5 912 virtual void visit_target_symbol (target_symbol* e) = 0;
82919855
FCE
913 virtual void visit_arrayindex (arrayindex* e) = 0;
914 virtual void visit_functioncall (functioncall* e) = 0;
d02548c0
GH
915 virtual void visit_print_format (print_format* e) = 0;
916 virtual void visit_stat_op (stat_op* e) = 0;
917 virtual void visit_hist_op (hist_op* e) = 0;
9b5af295 918 virtual void visit_cast_op (cast_op* e) = 0;
251707c8 919 virtual void visit_autocast_op (autocast_op* e) = 0;
bd1fcbad 920 virtual void visit_atvar_op (atvar_op* e) = 0;
30263a73 921 virtual void visit_defined_op (defined_op* e) = 0;
8cc799a5 922 virtual void visit_entry_op (entry_op* e) = 0;
3689db05 923 virtual void visit_perf_op (perf_op* e) = 0;
82919855
FCE
924};
925
926
f281029c
JS
927// A NOP visitor doesn't do anything. It's a useful base class if you need to
928// take action only for specific types, without even traversing the rest.
929struct nop_visitor: public visitor
930{
931 virtual ~nop_visitor () {}
dabd71bb
MW
932 virtual void visit_block (block *) {};
933 virtual void visit_try_block (try_block *) {};
934 virtual void visit_embeddedcode (embeddedcode *) {};
935 virtual void visit_null_statement (null_statement *) {};
936 virtual void visit_expr_statement (expr_statement *) {};
937 virtual void visit_if_statement (if_statement*) {};
938 virtual void visit_for_loop (for_loop*) {};
939 virtual void visit_foreach_loop (foreach_loop*) {};
940 virtual void visit_return_statement (return_statement*) {};
941 virtual void visit_delete_statement (delete_statement*) {};
942 virtual void visit_next_statement (next_statement*) {};
943 virtual void visit_break_statement (break_statement*) {};
944 virtual void visit_continue_statement (continue_statement*) {};
945 virtual void visit_literal_string (literal_string*) {};
946 virtual void visit_literal_number (literal_number*) {};
947 virtual void visit_embedded_expr (embedded_expr*) {};
948 virtual void visit_binary_expression (binary_expression*) {};
949 virtual void visit_unary_expression (unary_expression*) {};
950 virtual void visit_pre_crement (pre_crement*) {};
951 virtual void visit_post_crement (post_crement*) {};
952 virtual void visit_logical_or_expr (logical_or_expr*) {};
953 virtual void visit_logical_and_expr (logical_and_expr*) {};
954 virtual void visit_array_in (array_in*) {};
955 virtual void visit_regex_query (regex_query*) {};
956 virtual void visit_comparison (comparison*) {};
957 virtual void visit_concatenation (concatenation*) {};
958 virtual void visit_ternary_expression (ternary_expression*) {};
959 virtual void visit_assignment (assignment*) {};
960 virtual void visit_symbol (symbol*) {};
961 virtual void visit_target_symbol (target_symbol*) {};
962 virtual void visit_arrayindex (arrayindex*) {};
963 virtual void visit_functioncall (functioncall*) {};
964 virtual void visit_print_format (print_format*) {};
965 virtual void visit_stat_op (stat_op*) {};
966 virtual void visit_hist_op (hist_op*) {};
967 virtual void visit_cast_op (cast_op*) {};
968 virtual void visit_autocast_op (autocast_op*) {};
969 virtual void visit_atvar_op (atvar_op*) {};
970 virtual void visit_defined_op (defined_op*) {};
971 virtual void visit_entry_op (entry_op*) {};
972 virtual void visit_perf_op (perf_op*) {};
f281029c
JS
973};
974
975
cbfbbf69
FCE
976// A simple kind of visitor, which travels down to the leaves of the
977// statement/expression tree, up to but excluding following vardecls
978// and functioncalls.
82919855
FCE
979struct traversing_visitor: public visitor
980{
981 void visit_block (block *s);
f4fe2e93 982 void visit_try_block (try_block *s);
54dfabe9 983 void visit_embeddedcode (embeddedcode *s);
82919855
FCE
984 void visit_null_statement (null_statement *s);
985 void visit_expr_statement (expr_statement *s);
986 void visit_if_statement (if_statement* s);
987 void visit_for_loop (for_loop* s);
69c68955 988 void visit_foreach_loop (foreach_loop* s);
82919855
FCE
989 void visit_return_statement (return_statement* s);
990 void visit_delete_statement (delete_statement* s);
f3c26ea5
FCE
991 void visit_next_statement (next_statement* s);
992 void visit_break_statement (break_statement* s);
993 void visit_continue_statement (continue_statement* s);
82919855
FCE
994 void visit_literal_string (literal_string* e);
995 void visit_literal_number (literal_number* e);
7d902887 996 void visit_embedded_expr (embedded_expr* e);
82919855
FCE
997 void visit_binary_expression (binary_expression* e);
998 void visit_unary_expression (unary_expression* e);
999 void visit_pre_crement (pre_crement* e);
1000 void visit_post_crement (post_crement* e);
1001 void visit_logical_or_expr (logical_or_expr* e);
1002 void visit_logical_and_expr (logical_and_expr* e);
1003 void visit_array_in (array_in* e);
93daaca8 1004 void visit_regex_query (regex_query* e);
82919855
FCE
1005 void visit_comparison (comparison* e);
1006 void visit_concatenation (concatenation* e);
82919855
FCE
1007 void visit_ternary_expression (ternary_expression* e);
1008 void visit_assignment (assignment* e);
1009 void visit_symbol (symbol* e);
d7f3e0c5 1010 void visit_target_symbol (target_symbol* e);
82919855
FCE
1011 void visit_arrayindex (arrayindex* e);
1012 void visit_functioncall (functioncall* e);
d02548c0
GH
1013 void visit_print_format (print_format* e);
1014 void visit_stat_op (stat_op* e);
1015 void visit_hist_op (hist_op* e);
9b5af295 1016 void visit_cast_op (cast_op* e);
40a393cd
JS
1017 void visit_autocast_op (autocast_op* e);
1018 void visit_atvar_op (atvar_op* e);
1019 void visit_defined_op (defined_op* e);
1020 void visit_entry_op (entry_op* e);
1021 void visit_perf_op (perf_op* e);
1022};
1023
1024
1025// A visitor that calls a generic visit_expression on every expression.
1026struct expression_visitor: public traversing_visitor
1027{
1028 virtual void visit_expression(expression *e) = 0;
1029
1030 void visit_literal_string (literal_string* e);
1031 void visit_literal_number (literal_number* e);
1032 void visit_embedded_expr (embedded_expr* e);
1033 void visit_binary_expression (binary_expression* e);
1034 void visit_unary_expression (unary_expression* e);
1035 void visit_pre_crement (pre_crement* e);
1036 void visit_post_crement (post_crement* e);
1037 void visit_logical_or_expr (logical_or_expr* e);
1038 void visit_logical_and_expr (logical_and_expr* e);
1039 void visit_array_in (array_in* e);
1040 void visit_regex_query (regex_query* e);
1041 void visit_comparison (comparison* e);
1042 void visit_concatenation (concatenation* e);
1043 void visit_ternary_expression (ternary_expression* e);
1044 void visit_assignment (assignment* e);
1045 void visit_symbol (symbol* e);
1046 void visit_target_symbol (target_symbol* e);
1047 void visit_arrayindex (arrayindex* e);
1048 void visit_functioncall (functioncall* e);
1049 void visit_print_format (print_format* e);
1050 void visit_stat_op (stat_op* e);
1051 void visit_hist_op (hist_op* e);
1052 void visit_cast_op (cast_op* e);
251707c8 1053 void visit_autocast_op (autocast_op* e);
bd1fcbad 1054 void visit_atvar_op (atvar_op* e);
30263a73 1055 void visit_defined_op (defined_op* e);
8cc799a5 1056 void visit_entry_op (entry_op* e);
3689db05 1057 void visit_perf_op (perf_op* e);
82919855
FCE
1058};
1059
1060
cbfbbf69
FCE
1061// A kind of traversing visitor, which also follows function calls.
1062// It uses an internal set object to prevent infinite recursion.
1063struct functioncall_traversing_visitor: public traversing_visitor
1064{
13133f2c
AJ
1065 std::set<functiondecl*> seen;
1066 std::set<functiondecl*> nested;
3066c15c
FCE
1067 functiondecl* current_function;
1068 functioncall_traversing_visitor(): current_function(0) {}
cbfbbf69 1069 void visit_functioncall (functioncall* e);
f24849bd 1070 void enter_functioncall (functioncall* e);
8f8d261a 1071 virtual void note_recursive_functioncall (functioncall* e);
cbfbbf69
FCE
1072};
1073
1074
1075// A kind of traversing visitor, which also follows function calls,
1076// and stores the vardecl* referent of each variable read and/or
1077// written and other such sundry side-effect data. It's used by
1078// the elaboration-time optimizer pass.
1079struct varuse_collecting_visitor: public functioncall_traversing_visitor
1080{
313db8e6 1081 systemtap_session& session;
cbfbbf69
FCE
1082 std::set<vardecl*> read;
1083 std::set<vardecl*> written;
9d8a6ba3 1084 std::set<vardecl*> used;
cbfbbf69 1085 bool embedded_seen;
d20a83f8 1086 bool current_lvalue_read;
cbfbbf69
FCE
1087 expression* current_lvalue;
1088 expression* current_lrvalue;
313db8e6
DB
1089 varuse_collecting_visitor(systemtap_session& s):
1090 session (s),
cbfbbf69 1091 embedded_seen (false),
d20a83f8 1092 current_lvalue_read (false),
cbfbbf69
FCE
1093 current_lvalue(0),
1094 current_lrvalue(0) {}
f24849bd
JL
1095 void visit_if_statement (if_statement* s);
1096 void visit_for_loop (for_loop* s);
cbfbbf69 1097 void visit_embeddedcode (embeddedcode *s);
7d902887 1098 void visit_embedded_expr (embedded_expr *e);
f4fe2e93 1099 void visit_try_block (try_block *s);
f24849bd
JL
1100 void visit_functioncall (functioncall* e);
1101 void visit_return_statement (return_statement *s);
3066c15c 1102 void visit_delete_statement (delete_statement *s);
cbfbbf69
FCE
1103 void visit_print_format (print_format *e);
1104 void visit_assignment (assignment *e);
f24849bd 1105 void visit_ternary_expression (ternary_expression* e);
cbfbbf69 1106 void visit_arrayindex (arrayindex *e);
b0be9bdb 1107 void visit_target_symbol (target_symbol *e);
cbfbbf69
FCE
1108 void visit_symbol (symbol *e);
1109 void visit_pre_crement (pre_crement *e);
1110 void visit_post_crement (post_crement *e);
3066c15c 1111 void visit_foreach_loop (foreach_loop *s);
9b5af295 1112 void visit_cast_op (cast_op* e);
251707c8 1113 void visit_autocast_op (autocast_op* e);
bd1fcbad 1114 void visit_atvar_op (atvar_op *e);
30263a73 1115 void visit_defined_op (defined_op* e);
8cc799a5 1116 void visit_entry_op (entry_op* e);
3689db05 1117 void visit_perf_op (perf_op* e);
cf9ff341
FCE
1118 bool side_effect_free ();
1119 bool side_effect_free_wrt (const std::set<vardecl*>& vars);
1120};
cbfbbf69
FCE
1121
1122
1123
82919855
FCE
1124// A kind of visitor that throws an semantic_error exception
1125// whenever a non-overridden method is called.
1126struct throwing_visitor: public visitor
1127{
1128 std::string msg;
1129 throwing_visitor (const std::string& m);
1130 throwing_visitor ();
1131
1132 virtual void throwone (const token* t);
1133
1134 void visit_block (block *s);
f4fe2e93 1135 void visit_try_block (try_block *s);
54dfabe9 1136 void visit_embeddedcode (embeddedcode *s);
82919855
FCE
1137 void visit_null_statement (null_statement *s);
1138 void visit_expr_statement (expr_statement *s);
1139 void visit_if_statement (if_statement* s);
1140 void visit_for_loop (for_loop* s);
69c68955 1141 void visit_foreach_loop (foreach_loop* s);
82919855 1142 void visit_return_statement (return_statement* s);
85365d1b
GH
1143 void visit_delete_statement (delete_statement* s);
1144 void visit_next_statement (next_statement* s);
1145 void visit_break_statement (break_statement* s);
1146 void visit_continue_statement (continue_statement* s);
1147 void visit_literal_string (literal_string* e);
1148 void visit_literal_number (literal_number* e);
7d902887 1149 void visit_embedded_expr (embedded_expr* e);
85365d1b
GH
1150 void visit_binary_expression (binary_expression* e);
1151 void visit_unary_expression (unary_expression* e);
1152 void visit_pre_crement (pre_crement* e);
1153 void visit_post_crement (post_crement* e);
1154 void visit_logical_or_expr (logical_or_expr* e);
1155 void visit_logical_and_expr (logical_and_expr* e);
1156 void visit_array_in (array_in* e);
93daaca8 1157 void visit_regex_query (regex_query* e);
85365d1b
GH
1158 void visit_comparison (comparison* e);
1159 void visit_concatenation (concatenation* e);
1160 void visit_ternary_expression (ternary_expression* e);
1161 void visit_assignment (assignment* e);
1162 void visit_symbol (symbol* e);
d7f3e0c5 1163 void visit_target_symbol (target_symbol* e);
85365d1b
GH
1164 void visit_arrayindex (arrayindex* e);
1165 void visit_functioncall (functioncall* e);
d02548c0
GH
1166 void visit_print_format (print_format* e);
1167 void visit_stat_op (stat_op* e);
1168 void visit_hist_op (hist_op* e);
9b5af295 1169 void visit_cast_op (cast_op* e);
251707c8 1170 void visit_autocast_op (autocast_op* e);
bd1fcbad 1171 void visit_atvar_op (atvar_op* e);
30263a73 1172 void visit_defined_op (defined_op* e);
8cc799a5 1173 void visit_entry_op (entry_op* e);
3689db05 1174 void visit_perf_op (perf_op* e);
85365d1b
GH
1175};
1176
4b6455e8
JS
1177// A visitor similar to a traversing_visitor, but with the ability to rewrite
1178// parts of the tree through require/provide.
85365d1b 1179
4b6455e8 1180struct update_visitor: public visitor
85365d1b 1181{
3a4235b9 1182 template <typename T> T* require (T* src, bool clearok=false)
4ed05b15 1183 {
3a4235b9 1184 T* dst = NULL;
4ed05b15
JS
1185 if (src != NULL)
1186 {
1187 src->visit(this);
d15d767c
JS
1188 if (values.empty())
1189 throw std::runtime_error(_("update_visitor wasn't provided a value"));
1190 visitable *v = values.top();
1191 values.pop();
1192 if (v == NULL && !clearok)
1193 throw std::runtime_error(_("update_visitor was provided a NULL value"));
1194 dst = dynamic_cast<T*>(v);
1195 if (v != NULL && dst == NULL)
1196 throw std::runtime_error(_F("update_visitor can't set type \"%s\" with a \"%s\"",
1197 typeid(T).name(), typeid(*v).name()));
4ed05b15
JS
1198 }
1199 return dst;
1200 }
1201
3a4235b9 1202 template <typename T> void provide (T* src)
4ed05b15 1203 {
d15d767c 1204 values.push(src);
4ed05b15 1205 }
85365d1b 1206
8b095b45
JS
1207 template <typename T> void replace (T*& src, bool clearok=false)
1208 {
1209 src = require(src, clearok);
1210 }
1211
d15d767c 1212 virtual ~update_visitor() { assert(values.empty()); }
6a7bfd81 1213
77de5e9e 1214 virtual void visit_block (block *s);
f4fe2e93 1215 virtual void visit_try_block (try_block *s);
77de5e9e
GH
1216 virtual void visit_embeddedcode (embeddedcode *s);
1217 virtual void visit_null_statement (null_statement *s);
1218 virtual void visit_expr_statement (expr_statement *s);
1219 virtual void visit_if_statement (if_statement* s);
1220 virtual void visit_for_loop (for_loop* s);
1221 virtual void visit_foreach_loop (foreach_loop* s);
1222 virtual void visit_return_statement (return_statement* s);
1223 virtual void visit_delete_statement (delete_statement* s);
1224 virtual void visit_next_statement (next_statement* s);
1225 virtual void visit_break_statement (break_statement* s);
1226 virtual void visit_continue_statement (continue_statement* s);
1227 virtual void visit_literal_string (literal_string* e);
1228 virtual void visit_literal_number (literal_number* e);
7d902887 1229 virtual void visit_embedded_expr (embedded_expr* e);
77de5e9e
GH
1230 virtual void visit_binary_expression (binary_expression* e);
1231 virtual void visit_unary_expression (unary_expression* e);
1232 virtual void visit_pre_crement (pre_crement* e);
1233 virtual void visit_post_crement (post_crement* e);
1234 virtual void visit_logical_or_expr (logical_or_expr* e);
1235 virtual void visit_logical_and_expr (logical_and_expr* e);
1236 virtual void visit_array_in (array_in* e);
93daaca8 1237 virtual void visit_regex_query (regex_query* e);
77de5e9e
GH
1238 virtual void visit_comparison (comparison* e);
1239 virtual void visit_concatenation (concatenation* e);
1240 virtual void visit_ternary_expression (ternary_expression* e);
1241 virtual void visit_assignment (assignment* e);
1242 virtual void visit_symbol (symbol* e);
d7f3e0c5 1243 virtual void visit_target_symbol (target_symbol* e);
77de5e9e
GH
1244 virtual void visit_arrayindex (arrayindex* e);
1245 virtual void visit_functioncall (functioncall* e);
d02548c0
GH
1246 virtual void visit_print_format (print_format* e);
1247 virtual void visit_stat_op (stat_op* e);
1248 virtual void visit_hist_op (hist_op* e);
9b5af295 1249 virtual void visit_cast_op (cast_op* e);
251707c8 1250 virtual void visit_autocast_op (autocast_op* e);
bd1fcbad 1251 virtual void visit_atvar_op (atvar_op* e);
30263a73 1252 virtual void visit_defined_op (defined_op* e);
8cc799a5 1253 virtual void visit_entry_op (entry_op* e);
3689db05 1254 virtual void visit_perf_op (perf_op* e);
77de5e9e 1255
4ed05b15 1256private:
d15d767c 1257 std::stack<visitable *> values;
4ed05b15 1258};
d02548c0 1259
4b6455e8
JS
1260// A visitor which performs a deep copy of the root node it's applied
1261// to. NB: It does not copy any of the variable or function
1262// declarations; those fields are set to NULL, assuming you want to
1263// re-infer the declarations in a new context (the one you're copying
1264// to).
1265
1266struct deep_copy_visitor: public update_visitor
1267{
3a4235b9 1268 template <typename T> static T* deep_copy (T* e)
4b6455e8
JS
1269 {
1270 deep_copy_visitor v;
1271 return v.require (e);
1272 }
1273
1274 virtual void visit_block (block *s);
f4fe2e93 1275 virtual void visit_try_block (try_block *s);
4b6455e8
JS
1276 virtual void visit_embeddedcode (embeddedcode *s);
1277 virtual void visit_null_statement (null_statement *s);
1278 virtual void visit_expr_statement (expr_statement *s);
1279 virtual void visit_if_statement (if_statement* s);
1280 virtual void visit_for_loop (for_loop* s);
1281 virtual void visit_foreach_loop (foreach_loop* s);
1282 virtual void visit_return_statement (return_statement* s);
1283 virtual void visit_delete_statement (delete_statement* s);
1284 virtual void visit_next_statement (next_statement* s);
1285 virtual void visit_break_statement (break_statement* s);
1286 virtual void visit_continue_statement (continue_statement* s);
1287 virtual void visit_literal_string (literal_string* e);
1288 virtual void visit_literal_number (literal_number* e);
7d902887 1289 virtual void visit_embedded_expr (embedded_expr* e);
4b6455e8
JS
1290 virtual void visit_binary_expression (binary_expression* e);
1291 virtual void visit_unary_expression (unary_expression* e);
1292 virtual void visit_pre_crement (pre_crement* e);
1293 virtual void visit_post_crement (post_crement* e);
1294 virtual void visit_logical_or_expr (logical_or_expr* e);
1295 virtual void visit_logical_and_expr (logical_and_expr* e);
1296 virtual void visit_array_in (array_in* e);
93daaca8 1297 virtual void visit_regex_query (regex_query* e);
4b6455e8
JS
1298 virtual void visit_comparison (comparison* e);
1299 virtual void visit_concatenation (concatenation* e);
1300 virtual void visit_ternary_expression (ternary_expression* e);
1301 virtual void visit_assignment (assignment* e);
1302 virtual void visit_symbol (symbol* e);
1303 virtual void visit_target_symbol (target_symbol* e);
1304 virtual void visit_arrayindex (arrayindex* e);
1305 virtual void visit_functioncall (functioncall* e);
1306 virtual void visit_print_format (print_format* e);
1307 virtual void visit_stat_op (stat_op* e);
1308 virtual void visit_hist_op (hist_op* e);
9b5af295 1309 virtual void visit_cast_op (cast_op* e);
251707c8 1310 virtual void visit_autocast_op (autocast_op* e);
bd1fcbad 1311 virtual void visit_atvar_op (atvar_op* e);
30263a73 1312 virtual void visit_defined_op (defined_op* e);
8cc799a5 1313 virtual void visit_entry_op (entry_op* e);
3689db05 1314 virtual void visit_perf_op (perf_op* e);
4b6455e8 1315};
82919855 1316
b9086437
AJ
1317struct embedded_tags_visitor: public traversing_visitor
1318{
2451f2f1
AJ
1319 std::set<std::string> available_tags;
1320 std::set<std::string> tags; // set of the tags that appear in the code
b9086437 1321 embedded_tags_visitor(bool all_tags);
2451f2f1 1322 bool tagged_p (const std::string &tag);
b9086437
AJ
1323 void find_tags_in_code (const std::string& s);
1324 void visit_embeddedcode (embeddedcode *s);
1325 void visit_embedded_expr (embedded_expr *e);
1326};
1327
82919855 1328#endif // STAPTREE_H
73267b89
JS
1329
1330/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.378337 seconds and 5 git commands to generate.