]> sourceware.org Git - systemtap.git/blame - staptree.h
Correct systemtap.spec to match support currently available on aarch64
[systemtap.git] / staptree.h
CommitLineData
2f1a1aea 1// -*- C++ -*-
3689db05 2// Copyright (C) 2005-2013 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
JS
26#include "util.h"
27
82919855 28struct token; // parse.h
313db8e6
DB
29struct systemtap_session; // session.h
30
82919855
FCE
31struct semantic_error: public std::runtime_error
32{
33 const token* tok1;
82919855 34 const token* tok2;
e26c2f83 35 const semantic_error *chain;
6a7bfd81 36
82919855 37 ~semantic_error () throw () {}
02c997c0 38
1af1e62d 39 semantic_error (const std::string& msg, const token* t1=0):
7e41d3dc 40 runtime_error (msg), tok1 (t1), tok2 (0), chain (0) {}
e26c2f83 41
6a7bfd81 42 semantic_error (const std::string& msg, const token* t1,
e26c2f83 43 const token* t2):
02c997c0 44 runtime_error (msg), tok1 (t1), tok2 (t2), chain (0) {}
82919855
FCE
45};
46
57b73400 47// ------------------------------------------------------------------------
82919855 48
177a8ead 49/* struct statistic_decl moved to session.h */
57b73400
GH
50
51// ------------------------------------------------------------------------
82919855 52
56099f08
FCE
53enum exp_type
54 {
55 pe_unknown,
3a20432b
FCE
56 pe_long, // int64_t
57 pe_string, // std::string
6a7bfd81 58 pe_stats
56099f08 59 };
2f1a1aea 60
2b066ec1 61std::ostream& operator << (std::ostream& o, const exp_type& e);
2f1a1aea 62
56099f08 63struct token;
82919855 64struct visitor;
6fda2dff 65struct update_visitor;
82919855 66
d15d767c
JS
67struct visitable
68{
69 virtual ~visitable ();
70};
71
72struct expression : public visitable
2f1a1aea 73{
56099f08
FCE
74 exp_type type;
75 const token* tok;
56099f08 76 expression ();
2f1a1aea 77 virtual ~expression ();
cc9ee605 78 virtual void print (std::ostream& o) const = 0;
82919855 79 virtual void visit (visitor* u) = 0;
2f1a1aea
FCE
80};
81
cc9ee605 82std::ostream& operator << (std::ostream& o, const expression& k);
2f1a1aea 83
2f1a1aea
FCE
84
85struct literal: public expression
86{
87};
88
56099f08 89
2f1a1aea
FCE
90struct literal_string: public literal
91{
2b066ec1
FCE
92 std::string value;
93 literal_string (const std::string& v);
cc9ee605 94 void print (std::ostream& o) const;
82919855 95 void visit (visitor* u);
2f1a1aea
FCE
96};
97
56099f08 98
2f1a1aea
FCE
99struct literal_number: public literal
100{
3a20432b 101 int64_t value;
9ea68eb9
JS
102 bool print_hex;
103 literal_number (int64_t v, bool hex=false);
cc9ee605 104 void print (std::ostream& o) const;
82919855 105 void visit (visitor* u);
2f1a1aea
FCE
106};
107
108
7d902887
FCE
109struct embedded_expr: public expression
110{
111 std::string code;
112 void print (std::ostream& o) const;
113 void visit (visitor* u);
114};
115
116
2f1a1aea
FCE
117struct binary_expression: public expression
118{
119 expression* left;
2b066ec1 120 std::string op;
2f1a1aea 121 expression* right;
cc9ee605 122 void print (std::ostream& o) const;
82919855 123 void visit (visitor* u);
2f1a1aea
FCE
124};
125
56099f08 126
2f1a1aea
FCE
127struct unary_expression: public expression
128{
2b066ec1 129 std::string op;
2f1a1aea 130 expression* operand;
cc9ee605 131 void print (std::ostream& o) const;
82919855 132 void visit (visitor* u);
2f1a1aea
FCE
133};
134
56099f08 135
2f1a1aea
FCE
136struct pre_crement: public unary_expression
137{
82919855 138 void visit (visitor* u);
2f1a1aea
FCE
139};
140
56099f08 141
2f1a1aea
FCE
142struct post_crement: public unary_expression
143{
cc9ee605 144 void print (std::ostream& o) const;
82919855 145 void visit (visitor* u);
2f1a1aea
FCE
146};
147
56099f08 148
2f1a1aea
FCE
149struct logical_or_expr: public binary_expression
150{
82919855 151 void visit (visitor* u);
2f1a1aea
FCE
152};
153
56099f08 154
2f1a1aea
FCE
155struct logical_and_expr: public binary_expression
156{
82919855 157 void visit (visitor* u);
2f1a1aea
FCE
158};
159
56099f08 160
69c68955
FCE
161struct arrayindex;
162struct array_in: public expression
2f1a1aea 163{
69c68955 164 arrayindex* operand;
cc9ee605 165 void print (std::ostream& o) const;
82919855 166 void visit (visitor* u);
2f1a1aea
FCE
167};
168
946e4bbd 169struct regex_query: public expression
93daaca8 170{
946e4bbd
SM
171 expression* left;
172 std::string op;
173 literal_string* right;
93daaca8 174 void visit (visitor* u);
b4bb55ed 175 void print (std::ostream& o) const;
93daaca8 176};
56099f08 177
2f1a1aea
FCE
178struct comparison: public binary_expression
179{
82919855 180 void visit (visitor* u);
2f1a1aea
FCE
181};
182
56099f08 183
2f1a1aea
FCE
184struct concatenation: public binary_expression
185{
82919855 186 void visit (visitor* u);
2f1a1aea
FCE
187};
188
56099f08 189
2f1a1aea
FCE
190struct ternary_expression: public expression
191{
192 expression* cond;
193 expression* truevalue;
194 expression* falsevalue;
cc9ee605 195 void print (std::ostream& o) const;
82919855 196 void visit (visitor* u);
56099f08
FCE
197};
198
199
200struct assignment: public binary_expression
201{
82919855 202 void visit (visitor* u);
2f1a1aea
FCE
203};
204
d02548c0
GH
205struct symbol;
206struct hist_op;
d15d767c 207struct indexable : public expression
d02548c0
GH
208{
209 // This is a helper class which, type-wise, acts as a disjoint union
210 // of symbols and histograms. You can ask it whether it's a
211 // histogram or a symbol, and downcast accordingly.
d02548c0
GH
212 virtual bool is_symbol(symbol *& sym_out);
213 virtual bool is_hist_op(hist_op *& hist_out);
d02548c0
GH
214 virtual ~indexable() {}
215};
216
217// Perform a downcast to one out-value and NULL the other, throwing an
218// exception if neither downcast succeeds. This is (sadly) about the
219// best we can accomplish in C++.
220void
221classify_indexable(indexable* ix,
222 symbol *& array_out,
223 hist_op *& hist_out);
224
b9aa5bb4 225struct vardecl;
d15d767c 226struct symbol: public indexable
2f1a1aea 227{
2b066ec1 228 std::string name;
56099f08
FCE
229 vardecl *referent;
230 symbol ();
cc9ee605 231 void print (std::ostream& o) const;
82919855 232 void visit (visitor* u);
d02548c0 233 // overrides of type 'indexable'
d02548c0 234 bool is_symbol(symbol *& sym_out);
2f1a1aea
FCE
235};
236
56099f08 237
b0be9bdb 238struct target_symbol: public symbol
d7f3e0c5
GH
239{
240 enum component_type
241 {
242 comp_struct_member,
6fda2dff
JS
243 comp_literal_array_index,
244 comp_expression_array_index,
5f36109e 245 comp_pretty_print, // must be final
d7f3e0c5 246 };
c67847a0
JS
247
248 struct component
249 {
250 const token* tok;
251 component_type type;
5f36109e 252 std::string member; // comp_struct_member, comp_pretty_print
c67847a0 253 int64_t num_index; // comp_literal_array_index
6fda2dff 254 expression* expr_index; // comp_expression_array_index
c67847a0 255
5f36109e
JS
256 component(const token* t, const std::string& m, bool pprint=false):
257 tok(t),
258 type(pprint ? comp_pretty_print : comp_struct_member),
74fe61bc 259 member(m), num_index(0), expr_index(0)
5f36109e 260 {}
c67847a0 261 component(const token* t, int64_t n):
74fe61bc
LB
262 tok(t), type(comp_literal_array_index), num_index(n),
263 expr_index(0) {}
6fda2dff 264 component(const token* t, expression* e):
74fe61bc
LB
265 tok(t), type(comp_expression_array_index), num_index(0),
266 expr_index(e) {}
c67847a0
JS
267 void print (std::ostream& o) const;
268 };
269
03c75a4a 270 bool addressof;
c67847a0 271 std::vector<component> components;
c69a87e0 272 semantic_error* saved_conversion_error; // hand-made linked list
03c75a4a 273 target_symbol(): addressof(false), saved_conversion_error (0) {}
bd1fcbad 274 virtual std::string sym_name ();
1af1e62d 275 void chain (const semantic_error& er);
cc9ee605 276 void print (std::ostream& o) const;
6a7bfd81 277 void visit (visitor* u);
6fda2dff
JS
278 void visit_components (visitor* u);
279 void visit_components (update_visitor* u);
5f36109e 280 void assert_no_components(const std::string& tapset, bool pretty_ok=false);
d7f3e0c5
GH
281};
282
c67847a0
JS
283std::ostream& operator << (std::ostream& o, const target_symbol::component& c);
284
d7f3e0c5 285
9b5af295
JS
286struct cast_op: public target_symbol
287{
288 expression *operand;
7f6b80bd 289 std::string type_name, module;
9b5af295
JS
290 void print (std::ostream& o) const;
291 void visit (visitor* u);
292};
293
bd1fcbad
YZ
294struct atvar_op: public target_symbol
295{
296 std::string target_name, cu_name, module;
297 virtual std::string sym_name ();
298 void print (std::ostream& o) const;
299 void visit (visitor* u);
300};
9b5af295 301
30263a73
FCE
302struct defined_op: public expression
303{
304 target_symbol *operand;
305 void print (std::ostream& o) const;
306 void visit (visitor* u);
307};
308
309
8cc799a5
JS
310struct entry_op: public expression
311{
312 expression *operand;
313 void print (std::ostream& o) const;
314 void visit (visitor* u);
315};
316
317
3689db05
SC
318struct perf_op: public expression
319{
ace7c23f 320 literal_string *operand;
3689db05
SC
321 void print (std::ostream& o) const;
322 void visit (visitor* u);
323};
324
325
56099f08 326struct arrayindex: public expression
2f1a1aea 327{
2b066ec1 328 std::vector<expression*> indexes;
d02548c0 329 indexable *base;
56099f08 330 arrayindex ();
cc9ee605 331 void print (std::ostream& o) const;
82919855 332 void visit (visitor* u);
2f1a1aea
FCE
333};
334
56099f08 335
b9aa5bb4 336struct functiondecl;
56099f08 337struct functioncall: public expression
2f1a1aea 338{
2b066ec1
FCE
339 std::string function;
340 std::vector<expression*> args;
56099f08
FCE
341 functiondecl *referent;
342 functioncall ();
cc9ee605 343 void print (std::ostream& o) const;
82919855 344 void visit (visitor* u);
2f1a1aea
FCE
345};
346
347
d02548c0
GH
348struct print_format: public expression
349{
d02548c0 350 bool print_to_stream;
3cb17058
JS
351 bool print_with_format;
352 bool print_with_delim;
353 bool print_with_newline;
32784362 354 bool print_char;
d02548c0 355
929eb962
JS
356 // XXX match runtime/vsprintf.c's print_flag
357 // ... for use with number() & number_size()
d02548c0
GH
358 enum format_flag
359 {
360 fmt_flag_zeropad = 1,
929eb962
JS
361 fmt_flag_sign = 2,
362 fmt_flag_plus = 4,
363 fmt_flag_space = 8,
364 fmt_flag_left = 16,
365 fmt_flag_special = 32,
366 fmt_flag_large = 64,
d02548c0
GH
367 };
368
6a7bfd81 369 enum conversion_type
d02548c0
GH
370 {
371 conv_unspecified,
929eb962
JS
372 conv_pointer,
373 conv_number,
d02548c0 374 conv_string,
fecccf83 375 conv_char,
34201621 376 conv_memory,
30c94a80 377 conv_memory_hex,
dc0b623a 378 conv_literal,
b5852334 379 conv_binary
d02548c0
GH
380 };
381
34201621
DB
382 enum width_type
383 {
384 width_unspecified,
385 width_static,
386 width_dynamic
387 };
388
389 enum precision_type
390 {
391 prec_unspecified,
392 prec_static,
393 prec_dynamic
394 };
395
d02548c0
GH
396 struct format_component
397 {
398 unsigned long flags;
929eb962 399 unsigned base;
d02548c0
GH
400 unsigned width;
401 unsigned precision;
34201621
DB
402 width_type widthtype;
403 precision_type prectype;
d02548c0
GH
404 conversion_type type;
405 std::string literal_string;
07c17d67
GH
406 bool is_empty() const
407 {
6a7bfd81 408 return flags == 0
34201621
DB
409 && widthtype == width_unspecified
410 && prectype == prec_unspecified
07c17d67
GH
411 && type == conv_unspecified
412 && literal_string.empty();
413 }
d02548c0
GH
414 void clear()
415 {
416 flags = 0;
34201621
DB
417 widthtype = width_unspecified;
418 prectype = prec_unspecified;
d02548c0
GH
419 type = conv_unspecified;
420 literal_string.clear();
421 }
929eb962
JS
422 inline void set_flag(format_flag f) { flags |= f; }
423 inline bool test_flag(format_flag f) const { return flags & f; }
d02548c0
GH
424 };
425
a9c62ac9 426 std::string raw_components;
d02548c0 427 std::vector<format_component> components;
3cb17058 428 format_component delimiter;
d02548c0 429 std::vector<expression*> args;
a4636912 430 hist_op *hist;
d02548c0
GH
431
432 static std::string components_to_string(std::vector<format_component> const & components);
433 static std::vector<format_component> string_to_components(std::string const & str);
d5e178c1 434 static print_format* create(const token *t);
d02548c0
GH
435
436 void print (std::ostream& o) const;
437 void visit (visitor* u);
d5e178c1
JS
438
439private:
440 print_format(bool stream, bool format, bool delim, bool newline, bool _char):
441 print_to_stream(stream), print_with_format(format),
442 print_with_delim(delim), print_with_newline(newline),
443 print_char(_char), hist(NULL)
444 {}
d02548c0
GH
445};
446
447
448enum stat_component_type
449 {
450 sc_average,
451 sc_count,
452 sc_sum,
453 sc_min,
454 sc_max,
fd5689dc 455 sc_none,
d02548c0
GH
456 };
457
458struct stat_op: public expression
6a7bfd81 459{
d02548c0
GH
460 stat_component_type ctype;
461 expression* stat;
462 void print (std::ostream& o) const;
463 void visit (visitor* u);
464};
465
466enum histogram_type
467 {
468 hist_linear,
469 hist_log
470 };
471
472struct hist_op: public indexable
473{
d02548c0
GH
474 histogram_type htype;
475 expression* stat;
476 std::vector<int64_t> params;
477 void print (std::ostream& o) const;
6a7bfd81 478 void visit (visitor* u);
d02548c0 479 // overrides of type 'indexable'
d02548c0
GH
480 bool is_hist_op(hist_op *& hist_out);
481};
482
56099f08
FCE
483// ------------------------------------------------------------------------
484
485
6a7bfd81 486struct symboldecl // unique object per (possibly implicit)
56099f08
FCE
487 // symbol declaration
488{
489 const token* tok;
a07a2c28 490 const token* systemtap_v_conditional; //checking systemtap compatibility
2b066ec1 491 std::string name;
56099f08
FCE
492 exp_type type;
493 symboldecl ();
494 virtual ~symboldecl ();
cc9ee605
FCE
495 virtual void print (std::ostream &o) const = 0;
496 virtual void printsig (std::ostream &o) const = 0;
56099f08
FCE
497};
498
499
cc9ee605 500std::ostream& operator << (std::ostream& o, const symboldecl& k);
56099f08
FCE
501
502
503struct vardecl: public symboldecl
504{
cc9ee605
FCE
505 void print (std::ostream& o) const;
506 void printsig (std::ostream& o) const;
56099f08 507 vardecl ();
58701b78 508 void set_arity (int arity, const token* t);
313b2f74 509 bool compatible_arity (int a);
58701b78 510 const token* arity_tok; // site where arity was first resolved
2b066ec1 511 int arity; // -1: unknown; 0: scalar; >0: array
ef474d24 512 int maxsize; // upperbound on size for arrays
2b066ec1 513 std::vector<exp_type> index_types; // for arrays only
9ba8c134 514 literal *init; // for global scalars only
69aa668e 515 bool synthetic; // for probe locals only, don't init on entry
74e6cc92 516 bool wrap;
56099f08
FCE
517};
518
519
0fefb486
FCE
520struct vardecl_builtin: public vardecl
521{
522};
523
54dfabe9 524struct statement;
56099f08
FCE
525struct functiondecl: public symboldecl
526{
2b066ec1
FCE
527 std::vector<vardecl*> formal_args;
528 std::vector<vardecl*> locals;
c3a3c0c9 529 std::vector<vardecl*> unused_locals;
54dfabe9 530 statement* body;
59de45f1 531 bool synthetic;
49b68a33 532 bool mangle_oldstyle;
56099f08 533 functiondecl ();
cc9ee605
FCE
534 void print (std::ostream& o) const;
535 void printsig (std::ostream& o) const;
f8809d54 536 void join (systemtap_session& s); // for synthetic functions only
56099f08
FCE
537};
538
539
540// ------------------------------------------------------------------------
541
542
d15d767c 543struct statement : public visitable
2f1a1aea 544{
cc9ee605 545 virtual void print (std::ostream& o) const = 0;
82919855 546 virtual void visit (visitor* u) = 0;
56099f08
FCE
547 const token* tok;
548 statement ();
f946b10f 549 statement (const token* tok);
2f1a1aea
FCE
550 virtual ~statement ();
551};
552
cc9ee605 553std::ostream& operator << (std::ostream& o, const statement& k);
2f1a1aea
FCE
554
555
54dfabe9
FCE
556struct embeddedcode: public statement
557{
558 std::string code;
cc9ee605 559 void print (std::ostream& o) const;
54dfabe9
FCE
560 void visit (visitor* u);
561};
562
563
2f1a1aea
FCE
564struct block: public statement
565{
2b066ec1 566 std::vector<statement*> statements;
cc9ee605 567 void print (std::ostream& o) const;
82919855 568 void visit (visitor* u);
ba6f838d
FCE
569 block () {}
570 block (statement* car, statement* cdr);
4310926e 571 virtual ~block () {}
2f1a1aea
FCE
572};
573
69c68955 574
f4fe2e93
FCE
575struct try_block: public statement
576{
fdba3aba
JS
577 statement* try_block; // may be 0
578 statement* catch_block; // may be 0
f4fe2e93
FCE
579 symbol* catch_error_var; // may be 0
580 void print (std::ostream& o) const;
581 void visit (visitor* u);
582};
583
584
f3c26ea5 585struct expr_statement;
2f1a1aea
FCE
586struct for_loop: public statement
587{
cbfbbf69 588 expr_statement* init; // may be 0
2f1a1aea 589 expression* cond;
cbfbbf69 590 expr_statement* incr; // may be 0
2f1a1aea 591 statement* block;
cc9ee605 592 void print (std::ostream& o) const;
82919855 593 void visit (visitor* u);
2f1a1aea
FCE
594};
595
56099f08 596
69c68955
FCE
597struct foreach_loop: public statement
598{
599 // this part is a specialization of arrayindex
600 std::vector<symbol*> indexes;
d02548c0 601 indexable *base;
93484556
FCE
602 int sort_direction; // -1: decreasing, 0: none, 1: increasing
603 unsigned sort_column; // 0: value, 1..N: index
fd5689dc 604 enum stat_component_type sort_aggr; // for aggregate arrays, which aggregate to sort on
c261711d 605 symbol* value; // optional iteration value
27f21e8c 606 expression* limit; // optional iteration limit
69c68955
FCE
607
608 statement* block;
cc9ee605 609 void print (std::ostream& o) const;
69c68955
FCE
610 void visit (visitor* u);
611};
612
613
2f1a1aea
FCE
614struct null_statement: public statement
615{
cc9ee605 616 void print (std::ostream& o) const;
82919855 617 void visit (visitor* u);
f946b10f 618 null_statement (const token* tok);
2f1a1aea
FCE
619};
620
2f1a1aea
FCE
621
622struct expr_statement: public statement
623{
624 expression* value; // executed for side-effects
cc9ee605 625 void print (std::ostream& o) const;
82919855 626 void visit (visitor* u);
2f1a1aea
FCE
627};
628
56099f08 629
2f1a1aea
FCE
630struct if_statement: public statement
631{
632 expression* condition;
633 statement* thenblock;
cbfbbf69 634 statement* elseblock; // may be 0
cc9ee605 635 void print (std::ostream& o) const;
82919855 636 void visit (visitor* u);
56099f08
FCE
637};
638
639
640struct return_statement: public expr_statement
641{
cc9ee605 642 void print (std::ostream& o) const;
82919855 643 void visit (visitor* u);
56099f08
FCE
644};
645
646
647struct delete_statement: public expr_statement
648{
cc9ee605 649 void print (std::ostream& o) const;
82919855 650 void visit (visitor* u);
2f1a1aea
FCE
651};
652
2f1a1aea 653
f3c26ea5
FCE
654struct break_statement: public statement
655{
cc9ee605 656 void print (std::ostream& o) const;
f3c26ea5
FCE
657 void visit (visitor* u);
658};
659
660
661struct continue_statement: public statement
662{
cc9ee605 663 void print (std::ostream& o) const;
f3c26ea5
FCE
664 void visit (visitor* u);
665};
666
667
668struct next_statement: public statement
669{
cc9ee605 670 void print (std::ostream& o) const;
f3c26ea5
FCE
671 void visit (visitor* u);
672};
673
674
56099f08 675struct probe;
c3a3c0c9 676struct derived_probe;
20c6c071 677struct probe_alias;
54dfabe9 678struct embeddedcode;
2f1a1aea
FCE
679struct stapfile
680{
2b066ec1
FCE
681 std::string name;
682 std::vector<probe*> probes;
20c6c071 683 std::vector<probe_alias*> aliases;
2b066ec1
FCE
684 std::vector<functiondecl*> functions;
685 std::vector<vardecl*> globals;
54dfabe9 686 std::vector<embeddedcode*> embeds;
1b1b4ceb 687 std::string file_contents;
377b8831 688 bool privileged;
1b1b4ceb
RA
689 stapfile (): file_contents (""),
690 privileged (false) {}
cc9ee605 691 void print (std::ostream& o) const;
2f1a1aea
FCE
692};
693
694
9c0c0e46
FCE
695struct probe_point
696{
697 struct component // XXX: sort of a restricted functioncall
6a7bfd81 698 {
2b066ec1 699 std::string functor;
82919855 700 literal* arg; // optional
9c0c0e46 701 component ();
f1a0157a 702 const token* tok; // points to component's functor
a229fcd7 703 component(std::string const & f, literal * a = NULL);
9c0c0e46 704 };
2b066ec1 705 std::vector<component*> components;
6e3347a9 706 bool optional;
d898100a 707 bool sufficient;
cbbe8080 708 expression* condition;
37ae3931 709 void print (std::ostream& o, bool print_extras=true) const;
9c0c0e46 710 probe_point ();
1939ea32 711 probe_point(const probe_point& pp);
f1a0157a 712 probe_point(std::vector<component*> const & comps);
37ae3931 713 std::string str(bool print_extras=true) const;
2f1a1aea
FCE
714};
715
cc9ee605 716std::ostream& operator << (std::ostream& o, const probe_point& k);
82919855 717
2f1a1aea
FCE
718
719struct probe
720{
2b066ec1 721 std::vector<probe_point*> locations;
ba6f838d 722 statement* body;
d885563b 723 struct probe* base;
82919855 724 const token* tok;
5750ecc6 725 const token* systemtap_v_conditional; //checking systemtap compatibility
2b066ec1 726 std::vector<vardecl*> locals;
c3a3c0c9 727 std::vector<vardecl*> unused_locals;
7977a734 728 static unsigned last_probeidx;
82919855 729 probe ();
d885563b 730 probe (probe* p, probe_point *l);
cc9ee605
FCE
731 void print (std::ostream& o) const;
732 virtual void printsig (std::ostream &o) const;
d885563b
FCE
733 virtual void collect_derivation_chain (std::vector<probe*> &probes_list) const;
734 virtual void collect_derivation_pp_chain (std::vector<probe_point*> &) const;
2c5a19c6 735 virtual const probe_alias *get_alias () const { return 0; }
8eb6206c 736 virtual probe_point *get_alias_loc () const { return 0; }
c72aa911 737 virtual probe* create_alias(probe_point* l, probe_point* a);
20c6c071 738 virtual ~probe() {}
37ebca01 739 bool privileged;
c1d5f3f6 740 std::string name;
2f1a1aea 741};
82919855 742
54dfabe9 743struct probe_alias: public probe
20c6c071
GH
744{
745 probe_alias(std::vector<probe_point*> const & aliases);
6a7bfd81 746 std::vector<probe_point*> alias_names;
cc9ee605 747 virtual void printsig (std::ostream &o) const;
97266278 748 bool epilogue_style;
20c6c071 749};
82919855
FCE
750
751
f4b28491 752// A derived visitor instance is used to visit the entire
82919855
FCE
753// statement/expression tree.
754struct visitor
755{
d7f3e0c5
GH
756 // Machinery for differentiating lvalue visits from non-lvalue.
757 std::vector<expression *> active_lvalues;
758 bool is_active_lvalue(expression *e);
759 void push_active_lvalue(expression *e);
760 void pop_active_lvalue();
761
82919855
FCE
762 virtual ~visitor () {}
763 virtual void visit_block (block *s) = 0;
f4fe2e93 764 virtual void visit_try_block (try_block *s) = 0;
54dfabe9 765 virtual void visit_embeddedcode (embeddedcode *s) = 0;
82919855
FCE
766 virtual void visit_null_statement (null_statement *s) = 0;
767 virtual void visit_expr_statement (expr_statement *s) = 0;
768 virtual void visit_if_statement (if_statement* s) = 0;
769 virtual void visit_for_loop (for_loop* s) = 0;
69c68955 770 virtual void visit_foreach_loop (foreach_loop* s) = 0;
82919855
FCE
771 virtual void visit_return_statement (return_statement* s) = 0;
772 virtual void visit_delete_statement (delete_statement* s) = 0;
f3c26ea5
FCE
773 virtual void visit_next_statement (next_statement* s) = 0;
774 virtual void visit_break_statement (break_statement* s) = 0;
775 virtual void visit_continue_statement (continue_statement* s) = 0;
82919855
FCE
776 virtual void visit_literal_string (literal_string* e) = 0;
777 virtual void visit_literal_number (literal_number* e) = 0;
7d902887 778 virtual void visit_embedded_expr (embedded_expr* e) = 0;
82919855
FCE
779 virtual void visit_binary_expression (binary_expression* e) = 0;
780 virtual void visit_unary_expression (unary_expression* e) = 0;
781 virtual void visit_pre_crement (pre_crement* e) = 0;
782 virtual void visit_post_crement (post_crement* e) = 0;
783 virtual void visit_logical_or_expr (logical_or_expr* e) = 0;
784 virtual void visit_logical_and_expr (logical_and_expr* e) = 0;
785 virtual void visit_array_in (array_in* e) = 0;
93daaca8 786 virtual void visit_regex_query (regex_query* e) = 0;
82919855
FCE
787 virtual void visit_comparison (comparison* e) = 0;
788 virtual void visit_concatenation (concatenation* e) = 0;
82919855
FCE
789 virtual void visit_ternary_expression (ternary_expression* e) = 0;
790 virtual void visit_assignment (assignment* e) = 0;
791 virtual void visit_symbol (symbol* e) = 0;
d7f3e0c5 792 virtual void visit_target_symbol (target_symbol* e) = 0;
82919855
FCE
793 virtual void visit_arrayindex (arrayindex* e) = 0;
794 virtual void visit_functioncall (functioncall* e) = 0;
d02548c0
GH
795 virtual void visit_print_format (print_format* e) = 0;
796 virtual void visit_stat_op (stat_op* e) = 0;
797 virtual void visit_hist_op (hist_op* e) = 0;
9b5af295 798 virtual void visit_cast_op (cast_op* e) = 0;
bd1fcbad 799 virtual void visit_atvar_op (atvar_op* e) = 0;
30263a73 800 virtual void visit_defined_op (defined_op* e) = 0;
8cc799a5 801 virtual void visit_entry_op (entry_op* e) = 0;
3689db05 802 virtual void visit_perf_op (perf_op* e) = 0;
82919855
FCE
803};
804
805
cbfbbf69
FCE
806// A simple kind of visitor, which travels down to the leaves of the
807// statement/expression tree, up to but excluding following vardecls
808// and functioncalls.
82919855
FCE
809struct traversing_visitor: public visitor
810{
811 void visit_block (block *s);
f4fe2e93 812 void visit_try_block (try_block *s);
54dfabe9 813 void visit_embeddedcode (embeddedcode *s);
82919855
FCE
814 void visit_null_statement (null_statement *s);
815 void visit_expr_statement (expr_statement *s);
816 void visit_if_statement (if_statement* s);
817 void visit_for_loop (for_loop* s);
69c68955 818 void visit_foreach_loop (foreach_loop* s);
82919855
FCE
819 void visit_return_statement (return_statement* s);
820 void visit_delete_statement (delete_statement* s);
f3c26ea5
FCE
821 void visit_next_statement (next_statement* s);
822 void visit_break_statement (break_statement* s);
823 void visit_continue_statement (continue_statement* s);
82919855
FCE
824 void visit_literal_string (literal_string* e);
825 void visit_literal_number (literal_number* e);
7d902887 826 void visit_embedded_expr (embedded_expr* e);
82919855
FCE
827 void visit_binary_expression (binary_expression* e);
828 void visit_unary_expression (unary_expression* e);
829 void visit_pre_crement (pre_crement* e);
830 void visit_post_crement (post_crement* e);
831 void visit_logical_or_expr (logical_or_expr* e);
832 void visit_logical_and_expr (logical_and_expr* e);
833 void visit_array_in (array_in* e);
93daaca8 834 void visit_regex_query (regex_query* e);
82919855
FCE
835 void visit_comparison (comparison* e);
836 void visit_concatenation (concatenation* e);
82919855
FCE
837 void visit_ternary_expression (ternary_expression* e);
838 void visit_assignment (assignment* e);
839 void visit_symbol (symbol* e);
d7f3e0c5 840 void visit_target_symbol (target_symbol* e);
82919855
FCE
841 void visit_arrayindex (arrayindex* e);
842 void visit_functioncall (functioncall* e);
d02548c0
GH
843 void visit_print_format (print_format* e);
844 void visit_stat_op (stat_op* e);
845 void visit_hist_op (hist_op* e);
9b5af295 846 void visit_cast_op (cast_op* e);
bd1fcbad 847 void visit_atvar_op (atvar_op* e);
30263a73 848 void visit_defined_op (defined_op* e);
8cc799a5 849 void visit_entry_op (entry_op* e);
3689db05 850 void visit_perf_op (perf_op* e);
82919855
FCE
851};
852
853
cbfbbf69
FCE
854// A kind of traversing visitor, which also follows function calls.
855// It uses an internal set object to prevent infinite recursion.
856struct functioncall_traversing_visitor: public traversing_visitor
857{
858 std::set<functiondecl*> traversed;
3066c15c
FCE
859 functiondecl* current_function;
860 functioncall_traversing_visitor(): current_function(0) {}
cbfbbf69
FCE
861 void visit_functioncall (functioncall* e);
862};
863
864
865// A kind of traversing visitor, which also follows function calls,
866// and stores the vardecl* referent of each variable read and/or
867// written and other such sundry side-effect data. It's used by
868// the elaboration-time optimizer pass.
869struct varuse_collecting_visitor: public functioncall_traversing_visitor
870{
313db8e6 871 systemtap_session& session;
cbfbbf69
FCE
872 std::set<vardecl*> read;
873 std::set<vardecl*> written;
9d8a6ba3 874 std::set<vardecl*> used;
cbfbbf69 875 bool embedded_seen;
d20a83f8 876 bool current_lvalue_read;
cbfbbf69
FCE
877 expression* current_lvalue;
878 expression* current_lrvalue;
313db8e6
DB
879 varuse_collecting_visitor(systemtap_session& s):
880 session (s),
cbfbbf69 881 embedded_seen (false),
d20a83f8 882 current_lvalue_read (false),
cbfbbf69
FCE
883 current_lvalue(0),
884 current_lrvalue(0) {}
885 void visit_embeddedcode (embeddedcode *s);
7d902887 886 void visit_embedded_expr (embedded_expr *e);
f4fe2e93 887 void visit_try_block (try_block *s);
3066c15c 888 void visit_delete_statement (delete_statement *s);
cbfbbf69
FCE
889 void visit_print_format (print_format *e);
890 void visit_assignment (assignment *e);
891 void visit_arrayindex (arrayindex *e);
b0be9bdb 892 void visit_target_symbol (target_symbol *e);
cbfbbf69
FCE
893 void visit_symbol (symbol *e);
894 void visit_pre_crement (pre_crement *e);
895 void visit_post_crement (post_crement *e);
3066c15c 896 void visit_foreach_loop (foreach_loop *s);
9b5af295 897 void visit_cast_op (cast_op* e);
bd1fcbad 898 void visit_atvar_op (atvar_op *e);
30263a73 899 void visit_defined_op (defined_op* e);
8cc799a5 900 void visit_entry_op (entry_op* e);
3689db05 901 void visit_perf_op (perf_op* e);
cf9ff341
FCE
902 bool side_effect_free ();
903 bool side_effect_free_wrt (const std::set<vardecl*>& vars);
904};
cbfbbf69
FCE
905
906
907
82919855
FCE
908// A kind of visitor that throws an semantic_error exception
909// whenever a non-overridden method is called.
910struct throwing_visitor: public visitor
911{
912 std::string msg;
913 throwing_visitor (const std::string& m);
914 throwing_visitor ();
915
916 virtual void throwone (const token* t);
917
918 void visit_block (block *s);
f4fe2e93 919 void visit_try_block (try_block *s);
54dfabe9 920 void visit_embeddedcode (embeddedcode *s);
82919855
FCE
921 void visit_null_statement (null_statement *s);
922 void visit_expr_statement (expr_statement *s);
923 void visit_if_statement (if_statement* s);
924 void visit_for_loop (for_loop* s);
69c68955 925 void visit_foreach_loop (foreach_loop* s);
82919855 926 void visit_return_statement (return_statement* s);
85365d1b
GH
927 void visit_delete_statement (delete_statement* s);
928 void visit_next_statement (next_statement* s);
929 void visit_break_statement (break_statement* s);
930 void visit_continue_statement (continue_statement* s);
931 void visit_literal_string (literal_string* e);
932 void visit_literal_number (literal_number* e);
7d902887 933 void visit_embedded_expr (embedded_expr* e);
85365d1b
GH
934 void visit_binary_expression (binary_expression* e);
935 void visit_unary_expression (unary_expression* e);
936 void visit_pre_crement (pre_crement* e);
937 void visit_post_crement (post_crement* e);
938 void visit_logical_or_expr (logical_or_expr* e);
939 void visit_logical_and_expr (logical_and_expr* e);
940 void visit_array_in (array_in* e);
93daaca8 941 void visit_regex_query (regex_query* e);
85365d1b
GH
942 void visit_comparison (comparison* e);
943 void visit_concatenation (concatenation* e);
944 void visit_ternary_expression (ternary_expression* e);
945 void visit_assignment (assignment* e);
946 void visit_symbol (symbol* e);
d7f3e0c5 947 void visit_target_symbol (target_symbol* e);
85365d1b
GH
948 void visit_arrayindex (arrayindex* e);
949 void visit_functioncall (functioncall* e);
d02548c0
GH
950 void visit_print_format (print_format* e);
951 void visit_stat_op (stat_op* e);
952 void visit_hist_op (hist_op* e);
9b5af295 953 void visit_cast_op (cast_op* e);
bd1fcbad 954 void visit_atvar_op (atvar_op* e);
30263a73 955 void visit_defined_op (defined_op* e);
8cc799a5 956 void visit_entry_op (entry_op* e);
3689db05 957 void visit_perf_op (perf_op* e);
85365d1b
GH
958};
959
4b6455e8
JS
960// A visitor similar to a traversing_visitor, but with the ability to rewrite
961// parts of the tree through require/provide.
85365d1b 962
4b6455e8 963struct update_visitor: public visitor
85365d1b 964{
3a4235b9 965 template <typename T> T* require (T* src, bool clearok=false)
4ed05b15 966 {
3a4235b9 967 T* dst = NULL;
4ed05b15
JS
968 if (src != NULL)
969 {
970 src->visit(this);
d15d767c
JS
971 if (values.empty())
972 throw std::runtime_error(_("update_visitor wasn't provided a value"));
973 visitable *v = values.top();
974 values.pop();
975 if (v == NULL && !clearok)
976 throw std::runtime_error(_("update_visitor was provided a NULL value"));
977 dst = dynamic_cast<T*>(v);
978 if (v != NULL && dst == NULL)
979 throw std::runtime_error(_F("update_visitor can't set type \"%s\" with a \"%s\"",
980 typeid(T).name(), typeid(*v).name()));
4ed05b15
JS
981 }
982 return dst;
983 }
984
3a4235b9 985 template <typename T> void provide (T* src)
4ed05b15 986 {
d15d767c 987 values.push(src);
4ed05b15 988 }
85365d1b 989
8b095b45
JS
990 template <typename T> void replace (T*& src, bool clearok=false)
991 {
992 src = require(src, clearok);
993 }
994
d15d767c 995 virtual ~update_visitor() { assert(values.empty()); }
6a7bfd81 996
77de5e9e 997 virtual void visit_block (block *s);
f4fe2e93 998 virtual void visit_try_block (try_block *s);
77de5e9e
GH
999 virtual void visit_embeddedcode (embeddedcode *s);
1000 virtual void visit_null_statement (null_statement *s);
1001 virtual void visit_expr_statement (expr_statement *s);
1002 virtual void visit_if_statement (if_statement* s);
1003 virtual void visit_for_loop (for_loop* s);
1004 virtual void visit_foreach_loop (foreach_loop* s);
1005 virtual void visit_return_statement (return_statement* s);
1006 virtual void visit_delete_statement (delete_statement* s);
1007 virtual void visit_next_statement (next_statement* s);
1008 virtual void visit_break_statement (break_statement* s);
1009 virtual void visit_continue_statement (continue_statement* s);
1010 virtual void visit_literal_string (literal_string* e);
1011 virtual void visit_literal_number (literal_number* e);
7d902887 1012 virtual void visit_embedded_expr (embedded_expr* e);
77de5e9e
GH
1013 virtual void visit_binary_expression (binary_expression* e);
1014 virtual void visit_unary_expression (unary_expression* e);
1015 virtual void visit_pre_crement (pre_crement* e);
1016 virtual void visit_post_crement (post_crement* e);
1017 virtual void visit_logical_or_expr (logical_or_expr* e);
1018 virtual void visit_logical_and_expr (logical_and_expr* e);
1019 virtual void visit_array_in (array_in* e);
93daaca8 1020 virtual void visit_regex_query (regex_query* e);
77de5e9e
GH
1021 virtual void visit_comparison (comparison* e);
1022 virtual void visit_concatenation (concatenation* e);
1023 virtual void visit_ternary_expression (ternary_expression* e);
1024 virtual void visit_assignment (assignment* e);
1025 virtual void visit_symbol (symbol* e);
d7f3e0c5 1026 virtual void visit_target_symbol (target_symbol* e);
77de5e9e
GH
1027 virtual void visit_arrayindex (arrayindex* e);
1028 virtual void visit_functioncall (functioncall* e);
d02548c0
GH
1029 virtual void visit_print_format (print_format* e);
1030 virtual void visit_stat_op (stat_op* e);
1031 virtual void visit_hist_op (hist_op* e);
9b5af295 1032 virtual void visit_cast_op (cast_op* e);
bd1fcbad 1033 virtual void visit_atvar_op (atvar_op* e);
30263a73 1034 virtual void visit_defined_op (defined_op* e);
8cc799a5 1035 virtual void visit_entry_op (entry_op* e);
3689db05 1036 virtual void visit_perf_op (perf_op* e);
77de5e9e 1037
4ed05b15 1038private:
d15d767c 1039 std::stack<visitable *> values;
4ed05b15 1040};
d02548c0 1041
4b6455e8
JS
1042// A visitor which performs a deep copy of the root node it's applied
1043// to. NB: It does not copy any of the variable or function
1044// declarations; those fields are set to NULL, assuming you want to
1045// re-infer the declarations in a new context (the one you're copying
1046// to).
1047
1048struct deep_copy_visitor: public update_visitor
1049{
3a4235b9 1050 template <typename T> static T* deep_copy (T* e)
4b6455e8
JS
1051 {
1052 deep_copy_visitor v;
1053 return v.require (e);
1054 }
1055
1056 virtual void visit_block (block *s);
f4fe2e93 1057 virtual void visit_try_block (try_block *s);
4b6455e8
JS
1058 virtual void visit_embeddedcode (embeddedcode *s);
1059 virtual void visit_null_statement (null_statement *s);
1060 virtual void visit_expr_statement (expr_statement *s);
1061 virtual void visit_if_statement (if_statement* s);
1062 virtual void visit_for_loop (for_loop* s);
1063 virtual void visit_foreach_loop (foreach_loop* s);
1064 virtual void visit_return_statement (return_statement* s);
1065 virtual void visit_delete_statement (delete_statement* s);
1066 virtual void visit_next_statement (next_statement* s);
1067 virtual void visit_break_statement (break_statement* s);
1068 virtual void visit_continue_statement (continue_statement* s);
1069 virtual void visit_literal_string (literal_string* e);
1070 virtual void visit_literal_number (literal_number* e);
7d902887 1071 virtual void visit_embedded_expr (embedded_expr* e);
4b6455e8
JS
1072 virtual void visit_binary_expression (binary_expression* e);
1073 virtual void visit_unary_expression (unary_expression* e);
1074 virtual void visit_pre_crement (pre_crement* e);
1075 virtual void visit_post_crement (post_crement* e);
1076 virtual void visit_logical_or_expr (logical_or_expr* e);
1077 virtual void visit_logical_and_expr (logical_and_expr* e);
1078 virtual void visit_array_in (array_in* e);
93daaca8 1079 virtual void visit_regex_query (regex_query* e);
4b6455e8
JS
1080 virtual void visit_comparison (comparison* e);
1081 virtual void visit_concatenation (concatenation* e);
1082 virtual void visit_ternary_expression (ternary_expression* e);
1083 virtual void visit_assignment (assignment* e);
1084 virtual void visit_symbol (symbol* e);
1085 virtual void visit_target_symbol (target_symbol* e);
1086 virtual void visit_arrayindex (arrayindex* e);
1087 virtual void visit_functioncall (functioncall* e);
1088 virtual void visit_print_format (print_format* e);
1089 virtual void visit_stat_op (stat_op* e);
1090 virtual void visit_hist_op (hist_op* e);
9b5af295 1091 virtual void visit_cast_op (cast_op* e);
bd1fcbad 1092 virtual void visit_atvar_op (atvar_op* e);
30263a73 1093 virtual void visit_defined_op (defined_op* e);
8cc799a5 1094 virtual void visit_entry_op (entry_op* e);
3689db05 1095 virtual void visit_perf_op (perf_op* e);
4b6455e8 1096};
82919855
FCE
1097
1098#endif // STAPTREE_H
73267b89
JS
1099
1100/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.314286 seconds and 5 git commands to generate.