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