1 // parse tree functions
2 // Copyright (C) 2005-2013 Red Hat Inc.
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
28 visitable::~visitable ()
33 expression::expression ():
34 type (pe_unknown
), tok (0)
39 expression::~expression ()
44 statement::statement ():
50 statement::statement (const token
* tok
):
56 null_statement::null_statement (const token
* tok
):
62 statement::~statement ()
73 arrayindex::arrayindex ():
79 functioncall::functioncall ():
85 symboldecl::symboldecl ():
86 tok (0), systemtap_v_conditional (0),
92 symboldecl::~symboldecl ()
96 probe_point::probe_point (std::vector
<component
*> const & comps
):
97 components(comps
), optional (false), sufficient (false),
102 // NB: shallow-copy of compoonents & condition!
103 probe_point::probe_point (const probe_point
& pp
):
104 components(pp
.components
), optional (pp
.optional
), sufficient (pp
.sufficient
),
105 condition (pp
.condition
)
110 probe_point::probe_point ():
111 optional (false), sufficient (false), condition (0)
116 unsigned probe::last_probeidx
= 0;
119 body (0), base (0), tok (0), systemtap_v_conditional (0), privileged (false)
121 this->name
= string ("probe_") + lex_cast(last_probeidx
++);
125 // Copy constructor, but with overriding probe-point. To be used when
126 // mapping script-level probe points to another one, early during pass
127 // 2. There should be no symbol resolution done yet.
128 probe::probe(probe
* p
, probe_point
* l
)
131 this->name
= string ("probe_") + lex_cast(last_probeidx
++);
133 this->locations
.push_back(l
);
134 this->body
= deep_copy_visitor::deep_copy(p
->body
);
135 this->privileged
= p
->privileged
;
136 this->systemtap_v_conditional
= p
->systemtap_v_conditional
;
137 assert (p
->locals
.size() == 0);
138 assert (p
->unused_locals
.size() == 0);
142 probe_point::component::component ():
148 probe_point::component::component (std::string
const & f
, literal
* a
):
149 functor(f
), arg(a
), tok(0)
155 arity_tok(0), arity (-1), maxsize(0), init(NULL
), synthetic(false), wrap(false)
161 vardecl::set_arity (int a
, const token
* t
)
166 if (a
== 0 && maxsize
> 0)
167 throw SEMANTIC_ERROR (_("inconsistent arity"), tok
);
169 if (arity
!= a
&& arity
>= 0)
171 semantic_error
err (ERR_SRC
, _F("inconsistent arity (%s vs %d)",
172 lex_cast(arity
).c_str(), a
), t
?:tok
);
174 err
.chain
= new SEMANTIC_ERROR (_F("arity %s first inferred here",
175 lex_cast(arity
).c_str()), arity_tok
);
183 index_types
.resize (arity
);
184 for (int i
=0; i
<arity
; i
++)
185 index_types
[i
] = pe_unknown
;
190 vardecl::compatible_arity (int a
)
192 if (a
== 0 && maxsize
> 0)
194 if (arity
== -1 || a
== -1)
200 functiondecl::functiondecl ():
201 body (0), synthetic (false), mangle_oldstyle (false)
206 functiondecl::join (systemtap_session
& s
)
209 throw SEMANTIC_ERROR (_("internal error, joining a non-synthetic function"), tok
);
210 if (!s
.functions
.insert (make_pair (name
, this)).second
)
211 throw SEMANTIC_ERROR (_F("synthetic function '%s' conflicts with an existing function",
213 tok
->location
.file
->functions
.push_back (this);
217 literal_number::literal_number (int64_t v
, bool hex
)
225 literal_string::literal_string (const string
& v
)
233 operator << (ostream
& o
, const exp_type
& e
)
237 case pe_unknown
: o
<< "unknown"; break;
238 case pe_long
: o
<< "long"; break;
239 case pe_string
: o
<< "string"; break;
240 case pe_stats
: o
<< "stats"; break;
241 default: o
<< "???"; break;
248 target_symbol::assert_no_components(const std::string
& tapset
, bool pretty_ok
)
250 if (components
.empty())
253 switch (components
[0].type
)
255 case comp_literal_array_index
:
256 case comp_expression_array_index
:
257 throw SEMANTIC_ERROR(_F("%s variable '%s' may not be used as array",
258 tapset
.c_str(), name
.c_str()), components
[0].tok
);
259 case comp_struct_member
:
260 throw SEMANTIC_ERROR(_F("%s variable '%s' may not be used as a structure",
261 tapset
.c_str(), name
.c_str()), components
[0].tok
);
262 case comp_pretty_print
:
264 throw SEMANTIC_ERROR(_F("%s variable '%s' may not be pretty-printed",
265 tapset
.c_str(), name
.c_str()), components
[0].tok
);
268 throw SEMANTIC_ERROR (_F("invalid use of %s variable '%s'",
269 tapset
.c_str(), name
.c_str()), components
[0].tok
);
274 void target_symbol::chain (const semantic_error
&er
)
276 semantic_error
* e
= new semantic_error(er
);
279 assert (e
->chain
== 0);
280 e
->chain
= this->saved_conversion_error
;
281 this->saved_conversion_error
= e
;
285 string
target_symbol::sym_name ()
287 return name
.substr(1);
291 string
atvar_op::sym_name ()
296 return target_name
.substr(0, target_name
.length() - cu_name
.length() - 1);
300 // ------------------------------------------------------------------------
301 // parse tree printing
303 ostream
& operator << (ostream
& o
, const expression
& k
)
310 void literal_string::print (ostream
& o
) const
313 for (unsigned i
=0; i
<value
.size(); i
++)
314 if (value
[i
] == '"') // or other escapeworthy characters?
322 void literal_number::print (ostream
& o
) const
325 o
<< hex
<< showbase
;
328 o
<< dec
<< noshowbase
;
332 void embedded_expr::print (ostream
& o
) const
334 o
<< "%{ " << code
<< " %}";
338 void binary_expression::print (ostream
& o
) const
340 o
<< "(" << *left
<< ") "
342 << " (" << *right
<< ")";
345 void regex_query::print (ostream
& o
) const
347 // NB: we need a custom printer, because the parser does not accept
348 // a parenthesized RHS.
349 o
<< "(" << *left
<< ") "
355 void unary_expression::print (ostream
& o
) const
357 o
<< op
<< '(' << *operand
<< ")";
360 void array_in::print (ostream
& o
) const
363 for (unsigned i
=0; i
<operand
->indexes
.size(); i
++)
365 if (i
> 0) o
<< ", ";
366 operand
->indexes
[i
]->print (o
);
369 operand
->base
->print (o
);
372 void post_crement::print (ostream
& o
) const
374 o
<< '(' << *operand
<< ")" << op
;
378 void ternary_expression::print (ostream
& o
) const
380 o
<< "(" << *cond
<< ")?("
381 << *truevalue
<< "):("
382 << *falsevalue
<< ")";
386 void symbol::print (ostream
& o
) const
392 void target_symbol::component::print (ostream
& o
) const
396 case comp_pretty_print
:
397 case comp_struct_member
:
400 case comp_literal_array_index
:
401 o
<< '[' << num_index
<< ']';
403 case comp_expression_array_index
:
404 o
<< '[' << *expr_index
<< ']';
410 std::ostream
& operator << (std::ostream
& o
, const target_symbol::component
& c
)
417 void target_symbol::print (ostream
& o
) const
422 for (unsigned i
= 0; i
< components
.size(); ++i
)
427 void atvar_op::print (ostream
& o
) const
431 o
<< name
<< "(\"" << target_name
<< "\")";
432 for (unsigned i
= 0; i
< components
.size(); ++i
)
437 void cast_op::print (ostream
& o
) const
441 o
<< name
<< '(' << *operand
;
442 o
<< ", " << lex_cast_qstring (type_name
);
443 if (module
.length() > 0)
444 o
<< ", " << lex_cast_qstring (module
);
446 for (unsigned i
= 0; i
< components
.size(); ++i
)
451 void defined_op::print (ostream
& o
) const
453 o
<< "@defined(" << *operand
<< ")";
457 void entry_op::print (ostream
& o
) const
459 o
<< "@entry(" << *operand
<< ")";
463 void perf_op::print (ostream
& o
) const
465 o
<< "@perf(" << *operand
<< ")";
469 void vardecl::print (ostream
& o
) const
475 o
<< "[" << maxsize
<< "]";
476 if (arity
> 0 || index_types
.size() > 0)
486 void vardecl::printsig (ostream
& o
) const
492 o
<< "[" << maxsize
<< "]";
494 if (index_types
.size() > 0)
497 for (unsigned i
=0; i
<index_types
.size(); i
++)
498 o
<< (i
>0 ? ", " : "") << index_types
[i
];
504 void functiondecl::print (ostream
& o
) const
506 o
<< "function " << name
<< " (";
507 for (unsigned i
=0; i
<formal_args
.size(); i
++)
508 o
<< (i
>0 ? ", " : "") << *formal_args
[i
];
514 void functiondecl::printsig (ostream
& o
) const
516 o
<< name
<< ":" << type
<< " (";
517 for (unsigned i
=0; i
<formal_args
.size(); i
++)
518 o
<< (i
>0 ? ", " : "")
521 << formal_args
[i
]->type
;
526 void arrayindex::print (ostream
& o
) const
530 for (unsigned i
=0; i
<indexes
.size(); i
++)
531 o
<< (i
>0 ? ", " : "") << *indexes
[i
];
536 void functioncall::print (ostream
& o
) const
538 o
<< function
<< "(";
539 for (unsigned i
=0; i
<args
.size(); i
++)
540 o
<< (i
>0 ? ", " : "") << *args
[i
];
546 print_format::create(const token
*t
, const char *n
)
548 bool stream
, format
, delim
, newline
, _char
;
549 if (n
== NULL
) n
= t
->content
.c_str();
553 format
= delim
= newline
= _char
= false;
555 if (strcmp(n
, "print_char") == 0)
565 if (0 != strncmp(n
, "print", 5))
582 if (*n
== 'l' && *(n
+1) == 'n')
593 print_format
*pf
= new print_format(stream
, format
, delim
, newline
, _char
, o
);
600 print_format::components_to_string(vector
<format_component
> const & components
)
604 for (vector
<format_component
>::const_iterator i
= components
.begin();
605 i
!= components
.end(); ++i
)
608 assert (i
->type
!= conv_unspecified
);
610 if (i
->type
== conv_literal
)
612 assert(!i
->literal_string
.empty());
613 for (string::const_iterator j
= i
->literal_string
.begin();
614 j
!= i
->literal_string
.end(); ++j
)
616 // See also: c_unparser::visit_literal_string and lex_cast_qstring
628 if (i
->test_flag (fmt_flag_zeropad
))
631 if (i
->test_flag (fmt_flag_plus
))
634 if (i
->test_flag (fmt_flag_space
))
637 if (i
->test_flag (fmt_flag_left
))
640 if (i
->test_flag (fmt_flag_special
))
643 if (i
->widthtype
== width_dynamic
)
645 else if (i
->widthtype
!= width_unspecified
&& i
->width
> 0)
648 if (i
->prectype
== prec_dynamic
)
650 else if (i
->prectype
!= prec_unspecified
&& i
->precision
> 0)
651 oss
<< '.' << i
->precision
;
666 if (i
->test_flag (fmt_flag_large
))
671 else if (i
->base
== 8)
673 else if (i
->test_flag (fmt_flag_sign
))
691 case conv_memory_hex
:
703 vector
<print_format::format_component
>
704 print_format::string_to_components(string
const & str
)
706 format_component curr
;
707 vector
<format_component
> res
;
711 string::const_iterator i
= str
.begin();
713 while (i
!= str
.end())
717 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
718 curr
.type
= conv_literal
;
719 curr
.literal_string
+= *i
;
723 else if (i
+1 == str
.end() || *(i
+1) == '%')
726 // *i == '%' and *(i+1) == '%'; append only one '%' to the literal string
727 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
728 curr
.type
= conv_literal
;
729 curr
.literal_string
+= '%';
736 if (curr
.type
!= conv_unspecified
)
738 // Flush any component we were previously accumulating
739 assert (curr
.type
== conv_literal
);
749 // Now we are definitely parsing a conversion.
750 // Begin by parsing flags (which are optional).
755 curr
.set_flag (fmt_flag_zeropad
);
760 curr
.set_flag (fmt_flag_plus
);
765 curr
.set_flag (fmt_flag_left
);
770 curr
.set_flag (fmt_flag_space
);
775 curr
.set_flag (fmt_flag_special
);
786 // Parse optional width
789 curr
.widthtype
= width_dynamic
;
792 else if (isdigit(*i
))
794 curr
.widthtype
= width_static
;
799 curr
.width
+= (*i
- '0');
802 while (i
!= str
.end() && isdigit(*i
));
808 // Parse optional precision
816 curr
.prectype
= prec_dynamic
;
819 else if (isdigit(*i
))
821 curr
.prectype
= prec_static
;
825 curr
.precision
*= 10;
826 curr
.precision
+= (*i
- '0');
829 while (i
!= str
.end() && isdigit(*i
));
836 // Parse the type modifier
847 // Parse the actual conversion specifier (bcsmdioupxXn)
850 // Valid conversion types
852 curr
.type
= conv_binary
;
856 curr
.type
= conv_char
;
860 curr
.type
= conv_string
;
864 curr
.type
= conv_memory
;
868 curr
.type
= conv_memory_hex
;
873 curr
.set_flag (fmt_flag_sign
);
875 curr
.type
= conv_number
;
880 curr
.type
= conv_number
;
885 curr
.set_flag (fmt_flag_large
);
887 curr
.type
= conv_number
;
892 // Since stap 1.3, %p == %#x.
893 curr
.set_flag (fmt_flag_special
);
894 curr
.type
= conv_pointer
;
896 // Oddness for stap < 1.3 is handled in translation
903 if (curr
.type
== conv_unspecified
)
904 throw PARSE_ERROR(_("invalid or missing conversion specifier"));
911 // If there's a remaining partly-composed conversion, fail.
912 if (!curr
.is_empty())
914 if (curr
.type
== conv_literal
)
917 throw PARSE_ERROR(_("trailing incomplete print format conversion"));
924 void print_format::print (ostream
& o
) const
926 o
<< print_format_type
<< "(";
927 if (print_with_format
)
928 o
<< lex_cast_qstring (raw_components
);
929 if (print_with_delim
)
930 o
<< lex_cast_qstring (delimiter
.literal_string
);
933 for (vector
<expression
*>::const_iterator i
= args
.begin();
934 i
!= args
.end(); ++i
)
936 if (i
!= args
.begin() || print_with_format
|| print_with_delim
)
943 void stat_op::print (ostream
& o
) const
969 assert (0); // should not happen, as sc_none is only used in foreach sorts
977 hist_op::print (ostream
& o
) const
983 assert(params
.size() == 3);
986 for (size_t i
= 0; i
< params
.size(); ++i
)
988 o
<< ", " << params
[i
];
994 assert(params
.size() == 0);
1002 ostream
& operator << (ostream
& o
, const statement
& k
)
1009 void embeddedcode::print (ostream
&o
) const
1016 void block::print (ostream
& o
) const
1019 for (unsigned i
=0; i
<statements
.size(); i
++)
1020 o
<< *statements
[i
] << endl
;
1024 block::block (statement
* car
, statement
* cdr
)
1026 statements
.push_back(car
);
1027 statements
.push_back(cdr
);
1028 this->tok
= car
->tok
;
1033 void try_block::print (ostream
& o
) const
1035 o
<< "try {" << endl
;
1036 if (try_block
) o
<< *try_block
<< endl
;
1038 if (catch_error_var
) o
<< "(" << *catch_error_var
<< ") ";
1040 if (catch_block
) o
<< *catch_block
<< endl
;
1045 void for_loop::print (ostream
& o
) const
1048 if (init
) init
->print (o
);
1052 if (incr
) incr
->print (o
);
1058 void foreach_loop::print (ostream
& o
) const
1067 for (unsigned i
=0; i
<indexes
.size(); i
++)
1069 if (i
> 0) o
<< ", ";
1070 indexes
[i
]->print (o
);
1071 if (sort_direction
!= 0 && sort_column
== i
+1)
1072 o
<< (sort_direction
> 0 ? "+" : "-");
1076 if (sort_direction
!= 0 && sort_column
== 0)
1080 case sc_count
: o
<< " @count"; break;
1081 case sc_average
: o
<< " @avg"; break;
1082 case sc_min
: o
<< " @min"; break;
1083 case sc_max
: o
<< " @max"; break;
1084 case sc_sum
: o
<< " @sum"; break;
1090 o
<< (sort_direction
> 0 ? "+" : "-");
1102 void null_statement::print (ostream
& o
) const
1108 void expr_statement::print (ostream
& o
) const
1114 void return_statement::print (ostream
& o
) const
1116 o
<< "return " << *value
;
1120 void delete_statement::print (ostream
& o
) const
1122 o
<< "delete " << *value
;
1125 void next_statement::print (ostream
& o
) const
1130 void break_statement::print (ostream
& o
) const
1135 void continue_statement::print (ostream
& o
) const
1140 void if_statement::print (ostream
& o
) const
1142 o
<< "if (" << *condition
<< ") "
1143 << *thenblock
<< endl
;
1145 o
<< "else " << *elseblock
<< endl
;
1149 void stapfile::print (ostream
& o
) const
1151 o
<< "# file " << name
<< endl
;
1153 for (unsigned i
=0; i
<embeds
.size(); i
++)
1154 embeds
[i
]->print (o
);
1156 for (unsigned i
=0; i
<globals
.size(); i
++)
1159 globals
[i
]->print (o
);
1163 for (unsigned i
=0; i
<aliases
.size(); i
++)
1165 aliases
[i
]->print (o
);
1169 for (unsigned i
=0; i
<probes
.size(); i
++)
1171 probes
[i
]->print (o
);
1175 for (unsigned j
= 0; j
< functions
.size(); j
++)
1177 functions
[j
]->print (o
);
1183 void probe::print (ostream
& o
) const
1191 void probe::printsig (ostream
& o
) const
1193 const probe_alias
*alias
= get_alias ();
1196 alias
->printsig (o
);
1200 for (unsigned i
=0; i
<locations
.size(); i
++)
1202 if (i
> 0) o
<< ",";
1203 locations
[i
]->print (o
);
1209 probe::collect_derivation_chain (std::vector
<probe
*> &probes_list
) const
1211 probes_list
.push_back(const_cast<probe
*>(this));
1213 base
->collect_derivation_chain(probes_list
);
1218 probe::collect_derivation_pp_chain (std::vector
<probe_point
*> &pp_list
) const
1220 pp_list
.push_back(const_cast<probe_point
*>(this->locations
[0]));
1222 base
->collect_derivation_pp_chain(pp_list
);
1227 void probe_point::print (ostream
& o
, bool print_extras
) const
1229 for (unsigned i
=0; i
<components
.size(); i
++)
1232 probe_point::component
* c
= components
[i
];
1235 o
<< "(" << *c
->arg
<< ")";
1241 else if (optional
) // sufficient implies optional
1244 o
<< " if (" << *condition
<< ")";
1247 string
probe_point::str (bool print_extras
) const
1250 print(o
, print_extras
);
1255 probe_alias::probe_alias(std::vector
<probe_point
*> const & aliases
):
1256 probe (), alias_names (aliases
), epilogue_style(false)
1260 void probe_alias::printsig (ostream
& o
) const
1262 for (unsigned i
=0; i
<alias_names
.size(); i
++)
1264 o
<< (i
>0 ? " = " : "");
1265 alias_names
[i
]->print (o
);
1268 for (unsigned i
=0; i
<locations
.size(); i
++)
1270 if (i
> 0) o
<< ", ";
1271 locations
[i
]->print (o
);
1276 ostream
& operator << (ostream
& o
, const probe_point
& k
)
1283 ostream
& operator << (ostream
& o
, const symboldecl
& k
)
1291 // ------------------------------------------------------------------------
1296 block::visit (visitor
* u
)
1298 u
->visit_block (this);
1303 try_block::visit (visitor
* u
)
1305 u
->visit_try_block (this);
1310 embeddedcode::visit (visitor
* u
)
1312 u
->visit_embeddedcode (this);
1317 for_loop::visit (visitor
* u
)
1319 u
->visit_for_loop (this);
1323 foreach_loop::visit (visitor
* u
)
1325 u
->visit_foreach_loop (this);
1329 null_statement::visit (visitor
* u
)
1331 u
->visit_null_statement (this);
1335 expr_statement::visit (visitor
* u
)
1337 u
->visit_expr_statement (this);
1341 return_statement::visit (visitor
* u
)
1343 u
->visit_return_statement (this);
1347 delete_statement::visit (visitor
* u
)
1349 u
->push_active_lvalue (this->value
);
1350 u
->visit_delete_statement (this);
1351 u
->pop_active_lvalue ();
1355 if_statement::visit (visitor
* u
)
1357 u
->visit_if_statement (this);
1361 next_statement::visit (visitor
* u
)
1363 u
->visit_next_statement (this);
1367 break_statement::visit (visitor
* u
)
1369 u
->visit_break_statement (this);
1373 continue_statement::visit (visitor
* u
)
1375 u
->visit_continue_statement (this);
1379 literal_string::visit(visitor
* u
)
1381 u
->visit_literal_string (this);
1385 literal_number::visit(visitor
* u
)
1387 u
->visit_literal_number (this);
1391 binary_expression::visit (visitor
* u
)
1393 u
->visit_binary_expression (this);
1397 embedded_expr::visit (visitor
* u
)
1399 u
->visit_embedded_expr (this);
1403 unary_expression::visit (visitor
* u
)
1405 u
->visit_unary_expression (this);
1409 pre_crement::visit (visitor
* u
)
1411 u
->push_active_lvalue (this->operand
);
1412 u
->visit_pre_crement (this);
1413 u
->pop_active_lvalue ();
1417 post_crement::visit (visitor
* u
)
1419 u
->push_active_lvalue (this->operand
);
1420 u
->visit_post_crement (this);
1421 u
->pop_active_lvalue ();
1425 logical_or_expr::visit (visitor
* u
)
1427 u
->visit_logical_or_expr (this);
1431 logical_and_expr::visit (visitor
* u
)
1433 u
->visit_logical_and_expr (this);
1437 array_in::visit (visitor
* u
)
1439 u
->visit_array_in (this);
1443 regex_query::visit (visitor
* u
)
1445 u
->visit_regex_query (this);
1449 comparison::visit (visitor
* u
)
1451 u
->visit_comparison (this);
1455 concatenation::visit (visitor
* u
)
1457 u
->visit_concatenation (this);
1461 ternary_expression::visit (visitor
* u
)
1463 u
->visit_ternary_expression (this);
1467 assignment::visit (visitor
* u
)
1469 u
->push_active_lvalue (this->left
);
1470 u
->visit_assignment (this);
1471 u
->pop_active_lvalue ();
1475 symbol::visit (visitor
* u
)
1477 u
->visit_symbol (this);
1481 target_symbol::visit (visitor
* u
)
1483 u
->visit_target_symbol(this);
1487 target_symbol::visit_components (visitor
* u
)
1489 for (unsigned i
= 0; i
< components
.size(); ++i
)
1490 if (components
[i
].type
== comp_expression_array_index
)
1491 components
[i
].expr_index
->visit (u
);
1495 target_symbol::visit_components (update_visitor
* u
)
1497 for (unsigned i
= 0; i
< components
.size(); ++i
)
1498 if (components
[i
].type
== comp_expression_array_index
)
1499 u
->replace (components
[i
].expr_index
);
1503 cast_op::visit (visitor
* u
)
1505 u
->visit_cast_op(this);
1510 atvar_op::visit (visitor
* u
)
1512 u
->visit_atvar_op(this);
1517 defined_op::visit (visitor
* u
)
1519 u
->visit_defined_op(this);
1524 entry_op::visit (visitor
* u
)
1526 u
->visit_entry_op(this);
1531 perf_op::visit (visitor
* u
)
1533 u
->visit_perf_op(this);
1538 arrayindex::visit (visitor
* u
)
1540 u
->visit_arrayindex (this);
1544 functioncall::visit (visitor
* u
)
1546 u
->visit_functioncall (this);
1550 print_format::visit (visitor
*u
)
1552 u
->visit_print_format (this);
1556 stat_op::visit (visitor
*u
)
1558 u
->visit_stat_op (this);
1562 hist_op::visit (visitor
*u
)
1564 u
->visit_hist_op (this);
1569 indexable::is_symbol(symbol
*& sym_out
)
1576 indexable::is_hist_op(hist_op
*& hist_out
)
1583 symbol::is_symbol(symbol
*& sym_out
)
1590 hist_op::is_hist_op(hist_op
*& hist_out
)
1597 classify_indexable(indexable
* ix
,
1598 symbol
*& array_out
,
1599 hist_op
*& hist_out
)
1604 if (!(ix
->is_symbol (array_out
) || ix
->is_hist_op (hist_out
)))
1605 throw SEMANTIC_ERROR(_("Expecting symbol or histogram operator"), ix
->tok
);
1606 if (!(hist_out
|| array_out
))
1607 throw SEMANTIC_ERROR(_("Failed to classify indexable"), ix
->tok
);
1611 // ------------------------------------------------------------------------
1614 visitor::is_active_lvalue(expression
*e
)
1616 for (unsigned i
= 0; i
< active_lvalues
.size(); ++i
)
1618 if (active_lvalues
[i
] == e
)
1625 visitor::push_active_lvalue(expression
*e
)
1627 active_lvalues
.push_back(e
);
1631 visitor::pop_active_lvalue()
1633 assert(!active_lvalues
.empty());
1634 active_lvalues
.pop_back();
1639 // ------------------------------------------------------------------------
1642 traversing_visitor::visit_block (block
* s
)
1644 for (unsigned i
=0; i
<s
->statements
.size(); i
++)
1645 s
->statements
[i
]->visit (this);
1649 traversing_visitor::visit_try_block (try_block
* s
)
1652 s
->try_block
->visit (this);
1653 if (s
->catch_error_var
)
1654 s
->catch_error_var
->visit (this);
1656 s
->catch_block
->visit (this);
1660 traversing_visitor::visit_embeddedcode (embeddedcode
*)
1665 traversing_visitor::visit_null_statement (null_statement
*)
1670 traversing_visitor::visit_expr_statement (expr_statement
* s
)
1672 s
->value
->visit (this);
1676 traversing_visitor::visit_if_statement (if_statement
* s
)
1678 s
->condition
->visit (this);
1679 s
->thenblock
->visit (this);
1681 s
->elseblock
->visit (this);
1685 traversing_visitor::visit_for_loop (for_loop
* s
)
1687 if (s
->init
) s
->init
->visit (this);
1688 s
->cond
->visit (this);
1689 if (s
->incr
) s
->incr
->visit (this);
1690 s
->block
->visit (this);
1694 traversing_visitor::visit_foreach_loop (foreach_loop
* s
)
1696 s
->base
->visit(this);
1698 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
1699 s
->indexes
[i
]->visit (this);
1702 s
->value
->visit (this);
1705 s
->limit
->visit (this);
1707 s
->block
->visit (this);
1711 traversing_visitor::visit_return_statement (return_statement
* s
)
1713 s
->value
->visit (this);
1717 traversing_visitor::visit_delete_statement (delete_statement
* s
)
1719 s
->value
->visit (this);
1723 traversing_visitor::visit_next_statement (next_statement
*)
1728 traversing_visitor::visit_break_statement (break_statement
*)
1733 traversing_visitor::visit_continue_statement (continue_statement
*)
1738 traversing_visitor::visit_literal_string (literal_string
*)
1743 traversing_visitor::visit_literal_number (literal_number
*)
1748 traversing_visitor::visit_embedded_expr (embedded_expr
*)
1753 traversing_visitor::visit_binary_expression (binary_expression
* e
)
1755 e
->left
->visit (this);
1756 e
->right
->visit (this);
1760 traversing_visitor::visit_unary_expression (unary_expression
* e
)
1762 e
->operand
->visit (this);
1766 traversing_visitor::visit_pre_crement (pre_crement
* e
)
1768 e
->operand
->visit (this);
1772 traversing_visitor::visit_post_crement (post_crement
* e
)
1774 e
->operand
->visit (this);
1779 traversing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
1781 e
->left
->visit (this);
1782 e
->right
->visit (this);
1786 traversing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
1788 e
->left
->visit (this);
1789 e
->right
->visit (this);
1793 traversing_visitor::visit_array_in (array_in
* e
)
1795 e
->operand
->visit (this);
1799 traversing_visitor::visit_regex_query (regex_query
* e
)
1801 e
->left
->visit (this);
1802 e
->right
->visit (this);
1806 traversing_visitor::visit_comparison (comparison
* e
)
1808 e
->left
->visit (this);
1809 e
->right
->visit (this);
1813 traversing_visitor::visit_concatenation (concatenation
* e
)
1815 e
->left
->visit (this);
1816 e
->right
->visit (this);
1820 traversing_visitor::visit_ternary_expression (ternary_expression
* e
)
1822 e
->cond
->visit (this);
1823 e
->truevalue
->visit (this);
1824 e
->falsevalue
->visit (this);
1828 traversing_visitor::visit_assignment (assignment
* e
)
1830 e
->left
->visit (this);
1831 e
->right
->visit (this);
1835 traversing_visitor::visit_symbol (symbol
*)
1840 traversing_visitor::visit_target_symbol (target_symbol
* e
)
1842 e
->visit_components (this);
1846 traversing_visitor::visit_cast_op (cast_op
* e
)
1848 e
->operand
->visit (this);
1849 e
->visit_components (this);
1853 traversing_visitor::visit_atvar_op (atvar_op
* e
)
1855 e
->visit_components (this);
1859 traversing_visitor::visit_defined_op (defined_op
* e
)
1861 e
->operand
->visit (this);
1865 traversing_visitor::visit_entry_op (entry_op
* e
)
1867 e
->operand
->visit (this);
1872 traversing_visitor::visit_perf_op (perf_op
* e
)
1874 e
->operand
->visit (this);
1879 traversing_visitor::visit_arrayindex (arrayindex
* e
)
1881 for (unsigned i
=0; i
<e
->indexes
.size(); i
++)
1882 e
->indexes
[i
]->visit (this);
1884 e
->base
->visit(this);
1888 traversing_visitor::visit_functioncall (functioncall
* e
)
1890 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1891 e
->args
[i
]->visit (this);
1895 traversing_visitor::visit_print_format (print_format
* e
)
1897 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1898 e
->args
[i
]->visit (this);
1900 e
->hist
->visit(this);
1904 traversing_visitor::visit_stat_op (stat_op
* e
)
1906 e
->stat
->visit (this);
1910 traversing_visitor::visit_hist_op (hist_op
* e
)
1912 e
->stat
->visit (this);
1917 functioncall_traversing_visitor::visit_functioncall (functioncall
* e
)
1919 traversing_visitor::visit_functioncall (e
);
1921 // prevent infinite recursion
1922 if (traversed
.find (e
->referent
) == traversed
.end ())
1924 traversed
.insert (e
->referent
);
1926 functiondecl
* last_current_function
= current_function
;
1927 current_function
= e
->referent
;
1928 e
->referent
->body
->visit (this);
1929 current_function
= last_current_function
;
1935 varuse_collecting_visitor::visit_try_block (try_block
*s
)
1938 s
->try_block
->visit (this);
1939 if (s
->catch_error_var
)
1940 written
.insert (s
->catch_error_var
->referent
);
1942 s
->catch_block
->visit (this);
1944 // NB: don't functioncall_traversing_visitor::visit_try_block (s);
1945 // since that would count s->catch_error_var as a read also.
1950 varuse_collecting_visitor::visit_embeddedcode (embeddedcode
*s
)
1952 assert (current_function
); // only they get embedded code
1954 // Don't allow embedded C functions in unprivileged mode unless
1955 // they are tagged with /* unprivileged */ or /* myproc-unprivileged */
1956 // or we're in a usermode runtime.
1957 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1958 ! pr_contains (session
.privilege
, pr_stapsys
) &&
1959 ! session
.runtime_usermode_p () &&
1960 s
->code
.find ("/* unprivileged */") == string::npos
&&
1961 s
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1962 throw SEMANTIC_ERROR (_F("function may not be used when --privilege=%s is specified",
1963 pr_name (session
.privilege
)),
1964 current_function
->tok
);
1966 // Don't allow /* guru */ functions unless -g is active.
1967 if (!session
.guru_mode
&& s
->code
.find ("/* guru */") != string::npos
)
1968 throw SEMANTIC_ERROR (_("function may not be used unless -g is specified"),
1969 current_function
->tok
);
1971 // PR14524: Support old-style THIS->local syntax on per-function basis.
1972 if (s
->code
.find ("/* unmangled */") != string::npos
)
1973 current_function
->mangle_oldstyle
= true;
1975 // We want to elide embedded-C functions when possible. For
1976 // example, each $target variable access is expanded to an
1977 // embedded-C function call. Yet, for safety reasons, we should
1978 // presume that embedded-C functions have intentional side-effects.
1980 // To tell these two types of functions apart, we apply a
1981 // Kludge(tm): we look for a magic string within the function body.
1982 // $target variables as rvalues will have this; lvalues won't.
1983 // Also, explicit side-effect-free tapset functions will have this.
1985 if (s
->code
.find ("/* pure */") != string::npos
)
1988 embedded_seen
= true;
1992 // About the same case as above.
1994 varuse_collecting_visitor::visit_embedded_expr (embedded_expr
*e
)
1996 // Don't allow embedded C expressions in unprivileged mode unless
1997 // they are tagged with /* unprivileged */ or /* myproc-unprivileged */
1998 // or we're in a usermode runtime.
1999 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
2000 ! pr_contains (session
.privilege
, pr_stapsys
) &&
2001 ! session
.runtime_usermode_p () &&
2002 e
->code
.find ("/* unprivileged */") == string::npos
&&
2003 e
->code
.find ("/* myproc-unprivileged */") == string::npos
)
2004 throw SEMANTIC_ERROR (_F("embedded expression may not be used when --privilege=%s is specified",
2005 pr_name (session
.privilege
)),
2008 // Don't allow /* guru */ functions unless -g is active.
2009 if (!session
.guru_mode
&& e
->code
.find ("/* guru */") != string::npos
)
2010 throw SEMANTIC_ERROR (_("embedded expression may not be used unless -g is specified"),
2013 // We want to elide embedded-C functions when possible. For
2014 // example, each $target variable access is expanded to an
2015 // embedded-C function call. Yet, for safety reasons, we should
2016 // presume that embedded-C functions have intentional side-effects.
2018 // To tell these two types of functions apart, we apply a
2019 // Kludge(tm): we look for a magic string within the function body.
2020 // $target variables as rvalues will have this; lvalues won't.
2021 // Also, explicit side-effect-free tapset functions will have this.
2023 if (e
->code
.find ("/* pure */") != string::npos
)
2026 embedded_seen
= true;
2031 varuse_collecting_visitor::visit_target_symbol (target_symbol
*e
)
2033 // Still-unresolved target symbol assignments get treated as
2034 // generating side-effects like embedded-C, to prevent premature
2035 // elision and later error message suppression (PR5516). rvalue use
2036 // of unresolved target symbols is OTOH not considered a side-effect.
2038 if (is_active_lvalue (e
))
2039 embedded_seen
= true;
2041 functioncall_traversing_visitor::visit_target_symbol (e
);
2046 varuse_collecting_visitor::visit_atvar_op (atvar_op
*e
)
2048 // Similar to visit_target_symbol
2050 if (is_active_lvalue (e
))
2051 embedded_seen
= true;
2053 functioncall_traversing_visitor::visit_atvar_op (e
);
2058 varuse_collecting_visitor::visit_cast_op (cast_op
*e
)
2060 // As with target_symbols, unresolved cast assignments need to preserved
2061 // for later error handling.
2062 if (is_active_lvalue (e
))
2063 embedded_seen
= true;
2065 functioncall_traversing_visitor::visit_cast_op (e
);
2069 varuse_collecting_visitor::visit_defined_op (defined_op
*e
)
2072 functioncall_traversing_visitor::visit_defined_op (e
);
2076 varuse_collecting_visitor::visit_entry_op (entry_op
*e
)
2079 functioncall_traversing_visitor::visit_entry_op (e
);
2084 varuse_collecting_visitor::visit_perf_op (perf_op
*e
)
2086 functioncall_traversing_visitor::visit_perf_op (e
);
2091 varuse_collecting_visitor::visit_print_format (print_format
* e
)
2093 // NB: Instead of being top-level statements, "print" and "printf"
2094 // are implemented as statement-expressions containing a
2095 // print_format. They have side-effects, but not via the
2096 // embedded-code detection method above.
2098 // But sprint and sprintf don't have side-effects.
2100 bool last_lvalue_read
= current_lvalue_read
;
2101 current_lvalue_read
= true;
2102 if (e
->print_to_stream
)
2103 embedded_seen
= true; // a proxy for "has unknown side-effects"
2105 functioncall_traversing_visitor::visit_print_format (e
);
2106 current_lvalue_read
= last_lvalue_read
;
2111 varuse_collecting_visitor::visit_assignment (assignment
*e
)
2113 if (e
->op
== "=" || e
->op
== "<<<") // pure writes
2115 expression
* last_lvalue
= current_lvalue
;
2116 bool last_lvalue_read
= current_lvalue_read
;
2117 current_lvalue
= e
->left
; // leave a mark for ::visit_symbol
2118 current_lvalue_read
= true;
2119 functioncall_traversing_visitor::visit_assignment (e
);
2120 current_lvalue
= last_lvalue
;
2121 current_lvalue_read
= last_lvalue_read
;
2123 else // read-modify-writes
2125 expression
* last_lrvalue
= current_lrvalue
;
2126 current_lrvalue
= e
->left
; // leave a mark for ::visit_symbol
2127 functioncall_traversing_visitor::visit_assignment (e
);
2128 current_lrvalue
= last_lrvalue
;
2133 varuse_collecting_visitor::visit_symbol (symbol
*e
)
2135 if (e
->referent
== 0)
2136 throw SEMANTIC_ERROR (_("symbol without referent"), e
->tok
);
2138 // We could handle initialized globals by marking them as "written".
2139 // However, this current visitor may be called for a function or
2140 // probe body, from the point of view of which this global is
2141 // already initialized, so not written.
2143 if (e->referent->init)
2144 written.insert (e->referent);
2147 if (current_lvalue
== e
|| current_lrvalue
== e
)
2149 written
.insert (e
->referent
);
2151 if (current_lvalue
!= e
|| current_lrvalue
== e
)
2153 read
.insert (e
->referent
);
2156 if (current_lrvalue
== e
)
2158 if (current_lvalue_read
)
2159 used
.insert (e
->referent
);
2161 else if (current_lvalue
!= e
)
2162 used
.insert (e
->referent
);
2165 // NB: stat_op need not be overridden, since it will get to
2166 // visit_symbol and only as a possible rvalue.
2170 varuse_collecting_visitor::visit_arrayindex (arrayindex
*e
)
2172 // Hooking this callback is necessary because of the hacky
2173 // statistics representation. For the expression "i[4] = 5", the
2174 // incoming lvalue will point to this arrayindex. However, the
2175 // symbol corresponding to the "i[4]" is multiply inherited with
2176 // arrayindex. If the symbol base part of this object is not at
2177 // offset 0, then static_cast<symbol*>(e) may result in a different
2178 // address, and not match lvalue by number when we recurse that way.
2179 // So we explicitly override the incoming lvalue/lrvalue values to
2180 // point at the embedded objects' actual base addresses.
2182 expression
* last_lrvalue
= current_lrvalue
;
2183 expression
* last_lvalue
= current_lvalue
;
2185 symbol
*array
= NULL
;
2186 hist_op
*hist
= NULL
;
2187 classify_indexable(e
->base
, array
, hist
);
2188 expression
*value
= array
?: hist
->stat
;
2190 if (current_lrvalue
== e
) current_lrvalue
= value
;
2191 if (current_lvalue
== e
) current_lvalue
= value
;
2192 functioncall_traversing_visitor::visit_arrayindex (e
);
2194 current_lrvalue
= last_lrvalue
;
2195 current_lvalue
= last_lvalue
;
2200 varuse_collecting_visitor::visit_pre_crement (pre_crement
*e
)
2202 expression
* last_lrvalue
= current_lrvalue
;
2203 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2204 functioncall_traversing_visitor::visit_pre_crement (e
);
2205 current_lrvalue
= last_lrvalue
;
2209 varuse_collecting_visitor::visit_post_crement (post_crement
*e
)
2211 expression
* last_lrvalue
= current_lrvalue
;
2212 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2213 functioncall_traversing_visitor::visit_post_crement (e
);
2214 current_lrvalue
= last_lrvalue
;
2218 varuse_collecting_visitor::visit_foreach_loop (foreach_loop
* s
)
2220 // NB: we duplicate so don't bother call
2221 // functioncall_traversing_visitor::visit_foreach_loop (s);
2223 s
->base
->visit(this);
2225 // If the collection is sorted, imply a "write" access to the
2226 // array in addition to the "read" one already noted above.
2227 if (s
->sort_direction
)
2229 symbol
*array
= NULL
;
2230 hist_op
*hist
= NULL
;
2231 classify_indexable (s
->base
, array
, hist
);
2232 if (array
) this->written
.insert (array
->referent
);
2233 // XXX: Can hist_op iterations be sorted?
2236 // NB: don't forget to visit the index expressions, which are lvalues.
2237 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
2239 expression
* last_lvalue
= current_lvalue
;
2240 current_lvalue
= s
->indexes
[i
]; // leave a mark for ::visit_symbol
2241 s
->indexes
[i
]->visit (this);
2242 current_lvalue
= last_lvalue
;
2245 // The value is an lvalue too
2248 expression
* last_lvalue
= current_lvalue
;
2249 current_lvalue
= s
->value
; // leave a mark for ::visit_symbol
2250 s
->value
->visit (this);
2251 current_lvalue
= last_lvalue
;
2255 s
->limit
->visit (this);
2257 s
->block
->visit (this);
2262 varuse_collecting_visitor::visit_delete_statement (delete_statement
* s
)
2264 // Ideally, this would be treated like an assignment: a plain write
2265 // to the underlying value ("lvalue"). XXX: However, the
2266 // optimization pass is not smart enough to remove an unneeded
2267 // "delete" yet, so we pose more like a *crement ("lrvalue"). This
2268 // should protect the underlying value from optimizional mischief.
2269 expression
* last_lrvalue
= current_lrvalue
;
2270 bool last_lvalue_read
= current_lvalue_read
;
2271 current_lrvalue
= s
->value
; // leave a mark for ::visit_symbol
2272 current_lvalue_read
= true;
2273 functioncall_traversing_visitor::visit_delete_statement (s
);
2274 current_lrvalue
= last_lrvalue
;
2275 current_lvalue_read
= last_lvalue_read
;
2279 varuse_collecting_visitor::side_effect_free ()
2281 return (written
.empty() && !embedded_seen
);
2286 varuse_collecting_visitor::side_effect_free_wrt (const set
<vardecl
*>& vars
)
2288 // A looser notion of side-effect-freeness with respect to a given
2289 // list of variables.
2291 // That's useful because the written list may consist of local
2292 // variables of called functions. But visible side-effects only
2293 // occur if the client's locals, or any globals are written-to.
2295 set
<vardecl
*> intersection
;
2296 insert_iterator
<set
<vardecl
*> > int_it (intersection
, intersection
.begin());
2297 set_intersection (written
.begin(), written
.end(),
2298 vars
.begin(), vars
.end(),
2301 return (intersection
.empty() && !embedded_seen
);
2307 // ------------------------------------------------------------------------
2310 throwing_visitor::throwing_visitor (const std::string
& m
): msg (m
) {}
2311 throwing_visitor::throwing_visitor (): msg (_("invalid element")) {}
2315 throwing_visitor::throwone (const token
* t
)
2317 throw SEMANTIC_ERROR (msg
, t
);
2321 throwing_visitor::visit_block (block
* s
)
2327 throwing_visitor::visit_try_block (try_block
* s
)
2334 throwing_visitor::visit_embeddedcode (embeddedcode
* s
)
2340 throwing_visitor::visit_null_statement (null_statement
* s
)
2346 throwing_visitor::visit_expr_statement (expr_statement
* s
)
2352 throwing_visitor::visit_if_statement (if_statement
* s
)
2358 throwing_visitor::visit_for_loop (for_loop
* s
)
2364 throwing_visitor::visit_foreach_loop (foreach_loop
* s
)
2370 throwing_visitor::visit_return_statement (return_statement
* s
)
2376 throwing_visitor::visit_delete_statement (delete_statement
* s
)
2382 throwing_visitor::visit_next_statement (next_statement
* s
)
2388 throwing_visitor::visit_break_statement (break_statement
* s
)
2394 throwing_visitor::visit_continue_statement (continue_statement
* s
)
2400 throwing_visitor::visit_literal_string (literal_string
* e
)
2406 throwing_visitor::visit_literal_number (literal_number
* e
)
2412 throwing_visitor::visit_embedded_expr (embedded_expr
* e
)
2418 throwing_visitor::visit_binary_expression (binary_expression
* e
)
2424 throwing_visitor::visit_unary_expression (unary_expression
* e
)
2430 throwing_visitor::visit_pre_crement (pre_crement
* e
)
2436 throwing_visitor::visit_post_crement (post_crement
* e
)
2443 throwing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2449 throwing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2455 throwing_visitor::visit_array_in (array_in
* e
)
2461 throwing_visitor::visit_regex_query (regex_query
* e
)
2467 throwing_visitor::visit_comparison (comparison
* e
)
2473 throwing_visitor::visit_concatenation (concatenation
* e
)
2479 throwing_visitor::visit_ternary_expression (ternary_expression
* e
)
2485 throwing_visitor::visit_assignment (assignment
* e
)
2491 throwing_visitor::visit_symbol (symbol
* e
)
2497 throwing_visitor::visit_target_symbol (target_symbol
* e
)
2503 throwing_visitor::visit_atvar_op (atvar_op
* e
)
2509 throwing_visitor::visit_cast_op (cast_op
* e
)
2515 throwing_visitor::visit_defined_op (defined_op
* e
)
2521 throwing_visitor::visit_entry_op (entry_op
* e
)
2528 throwing_visitor::visit_perf_op (perf_op
* e
)
2535 throwing_visitor::visit_arrayindex (arrayindex
* e
)
2541 throwing_visitor::visit_functioncall (functioncall
* e
)
2547 throwing_visitor::visit_print_format (print_format
* e
)
2553 throwing_visitor::visit_stat_op (stat_op
* e
)
2559 throwing_visitor::visit_hist_op (hist_op
* e
)
2565 // ------------------------------------------------------------------------
2569 update_visitor::visit_block (block
* s
)
2571 for (unsigned i
= 0; i
< s
->statements
.size(); ++i
)
2572 replace (s
->statements
[i
]);
2577 update_visitor::visit_try_block (try_block
* s
)
2579 replace (s
->try_block
);
2580 replace (s
->catch_error_var
);
2581 replace (s
->catch_block
);
2586 update_visitor::visit_embeddedcode (embeddedcode
* s
)
2592 update_visitor::visit_null_statement (null_statement
* s
)
2598 update_visitor::visit_expr_statement (expr_statement
* s
)
2605 update_visitor::visit_if_statement (if_statement
* s
)
2607 replace (s
->condition
);
2608 replace (s
->thenblock
);
2609 replace (s
->elseblock
);
2614 update_visitor::visit_for_loop (for_loop
* s
)
2624 update_visitor::visit_foreach_loop (foreach_loop
* s
)
2626 for (unsigned i
= 0; i
< s
->indexes
.size(); ++i
)
2627 replace (s
->indexes
[i
]);
2636 update_visitor::visit_return_statement (return_statement
* s
)
2643 update_visitor::visit_delete_statement (delete_statement
* s
)
2650 update_visitor::visit_next_statement (next_statement
* s
)
2656 update_visitor::visit_break_statement (break_statement
* s
)
2662 update_visitor::visit_continue_statement (continue_statement
* s
)
2668 update_visitor::visit_literal_string (literal_string
* e
)
2674 update_visitor::visit_literal_number (literal_number
* e
)
2680 update_visitor::visit_embedded_expr (embedded_expr
* e
)
2686 update_visitor::visit_binary_expression (binary_expression
* e
)
2694 update_visitor::visit_unary_expression (unary_expression
* e
)
2696 replace (e
->operand
);
2701 update_visitor::visit_pre_crement (pre_crement
* e
)
2703 replace (e
->operand
);
2708 update_visitor::visit_post_crement (post_crement
* e
)
2710 replace (e
->operand
);
2716 update_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2724 update_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2732 update_visitor::visit_array_in (array_in
* e
)
2734 replace (e
->operand
);
2739 update_visitor::visit_regex_query (regex_query
* e
)
2742 replace (e
->right
); // XXX: do we *need* to replace literal in RHS?
2747 update_visitor::visit_comparison (comparison
* e
)
2755 update_visitor::visit_concatenation (concatenation
* e
)
2763 update_visitor::visit_ternary_expression (ternary_expression
* e
)
2766 replace (e
->truevalue
);
2767 replace (e
->falsevalue
);
2772 update_visitor::visit_assignment (assignment
* e
)
2780 update_visitor::visit_symbol (symbol
* e
)
2786 update_visitor::visit_target_symbol (target_symbol
* e
)
2788 e
->visit_components (this);
2793 update_visitor::visit_cast_op (cast_op
* e
)
2795 replace (e
->operand
);
2796 e
->visit_components (this);
2801 update_visitor::visit_atvar_op (atvar_op
* e
)
2803 e
->visit_components (this);
2808 update_visitor::visit_defined_op (defined_op
* e
)
2810 replace (e
->operand
);
2815 update_visitor::visit_entry_op (entry_op
* e
)
2817 replace (e
->operand
);
2822 update_visitor::visit_perf_op (perf_op
* e
)
2824 replace (e
->operand
);
2829 update_visitor::visit_arrayindex (arrayindex
* e
)
2832 for (unsigned i
= 0; i
< e
->indexes
.size(); ++i
)
2833 replace (e
->indexes
[i
]);
2838 update_visitor::visit_functioncall (functioncall
* e
)
2840 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2841 replace (e
->args
[i
]);
2846 update_visitor::visit_print_format (print_format
* e
)
2848 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2849 replace (e
->args
[i
]);
2855 update_visitor::visit_stat_op (stat_op
* e
)
2862 update_visitor::visit_hist_op (hist_op
* e
)
2869 // ------------------------------------------------------------------------
2873 deep_copy_visitor::visit_block (block
* s
)
2875 update_visitor::visit_block(new block(*s
));
2879 deep_copy_visitor::visit_try_block (try_block
* s
)
2881 update_visitor::visit_try_block(new try_block(*s
));
2885 deep_copy_visitor::visit_embeddedcode (embeddedcode
* s
)
2887 update_visitor::visit_embeddedcode(new embeddedcode(*s
));
2891 deep_copy_visitor::visit_null_statement (null_statement
* s
)
2893 update_visitor::visit_null_statement(new null_statement(*s
));
2897 deep_copy_visitor::visit_expr_statement (expr_statement
* s
)
2899 update_visitor::visit_expr_statement(new expr_statement(*s
));
2903 deep_copy_visitor::visit_if_statement (if_statement
* s
)
2905 update_visitor::visit_if_statement(new if_statement(*s
));
2909 deep_copy_visitor::visit_for_loop (for_loop
* s
)
2911 update_visitor::visit_for_loop(new for_loop(*s
));
2915 deep_copy_visitor::visit_foreach_loop (foreach_loop
* s
)
2917 update_visitor::visit_foreach_loop(new foreach_loop(*s
));
2921 deep_copy_visitor::visit_return_statement (return_statement
* s
)
2923 update_visitor::visit_return_statement(new return_statement(*s
));
2927 deep_copy_visitor::visit_delete_statement (delete_statement
* s
)
2929 update_visitor::visit_delete_statement(new delete_statement(*s
));
2933 deep_copy_visitor::visit_next_statement (next_statement
* s
)
2935 update_visitor::visit_next_statement(new next_statement(*s
));
2939 deep_copy_visitor::visit_break_statement (break_statement
* s
)
2941 update_visitor::visit_break_statement(new break_statement(*s
));
2945 deep_copy_visitor::visit_continue_statement (continue_statement
* s
)
2947 update_visitor::visit_continue_statement(new continue_statement(*s
));
2951 deep_copy_visitor::visit_literal_string (literal_string
* e
)
2953 update_visitor::visit_literal_string(new literal_string(*e
));
2957 deep_copy_visitor::visit_literal_number (literal_number
* e
)
2959 update_visitor::visit_literal_number(new literal_number(*e
));
2963 deep_copy_visitor::visit_embedded_expr (embedded_expr
* e
)
2965 update_visitor::visit_embedded_expr(new embedded_expr(*e
));
2969 deep_copy_visitor::visit_binary_expression (binary_expression
* e
)
2971 update_visitor::visit_binary_expression(new binary_expression(*e
));
2975 deep_copy_visitor::visit_unary_expression (unary_expression
* e
)
2977 update_visitor::visit_unary_expression(new unary_expression(*e
));
2981 deep_copy_visitor::visit_pre_crement (pre_crement
* e
)
2983 update_visitor::visit_pre_crement(new pre_crement(*e
));
2987 deep_copy_visitor::visit_post_crement (post_crement
* e
)
2989 update_visitor::visit_post_crement(new post_crement(*e
));
2994 deep_copy_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2996 update_visitor::visit_logical_or_expr(new logical_or_expr(*e
));
3000 deep_copy_visitor::visit_logical_and_expr (logical_and_expr
* e
)
3002 update_visitor::visit_logical_and_expr(new logical_and_expr(*e
));
3006 deep_copy_visitor::visit_array_in (array_in
* e
)
3008 update_visitor::visit_array_in(new array_in(*e
));
3012 deep_copy_visitor::visit_regex_query (regex_query
* e
)
3014 update_visitor::visit_regex_query(new regex_query(*e
));
3018 deep_copy_visitor::visit_comparison (comparison
* e
)
3020 update_visitor::visit_comparison(new comparison(*e
));
3024 deep_copy_visitor::visit_concatenation (concatenation
* e
)
3026 update_visitor::visit_concatenation(new concatenation(*e
));
3030 deep_copy_visitor::visit_ternary_expression (ternary_expression
* e
)
3032 update_visitor::visit_ternary_expression(new ternary_expression(*e
));
3036 deep_copy_visitor::visit_assignment (assignment
* e
)
3038 update_visitor::visit_assignment(new assignment(*e
));
3042 deep_copy_visitor::visit_symbol (symbol
* e
)
3044 symbol
* n
= new symbol(*e
);
3045 n
->referent
= NULL
; // don't copy!
3046 update_visitor::visit_symbol(n
);
3050 deep_copy_visitor::visit_target_symbol (target_symbol
* e
)
3052 target_symbol
* n
= new target_symbol(*e
);
3053 n
->referent
= NULL
; // don't copy!
3054 update_visitor::visit_target_symbol(n
);
3058 deep_copy_visitor::visit_cast_op (cast_op
* e
)
3060 update_visitor::visit_cast_op(new cast_op(*e
));
3064 deep_copy_visitor::visit_atvar_op (atvar_op
* e
)
3066 update_visitor::visit_atvar_op(new atvar_op(*e
));
3070 deep_copy_visitor::visit_defined_op (defined_op
* e
)
3072 update_visitor::visit_defined_op(new defined_op(*e
));
3076 deep_copy_visitor::visit_entry_op (entry_op
* e
)
3078 update_visitor::visit_entry_op(new entry_op(*e
));
3082 deep_copy_visitor::visit_perf_op (perf_op
* e
)
3084 update_visitor::visit_perf_op(new perf_op(*e
));
3088 deep_copy_visitor::visit_arrayindex (arrayindex
* e
)
3090 update_visitor::visit_arrayindex(new arrayindex(*e
));
3094 deep_copy_visitor::visit_functioncall (functioncall
* e
)
3096 functioncall
* n
= new functioncall(*e
);
3097 n
->referent
= NULL
; // don't copy!
3098 update_visitor::visit_functioncall(n
);
3102 deep_copy_visitor::visit_print_format (print_format
* e
)
3104 update_visitor::visit_print_format(new print_format(*e
));
3108 deep_copy_visitor::visit_stat_op (stat_op
* e
)
3110 update_visitor::visit_stat_op(new stat_op(*e
));
3114 deep_copy_visitor::visit_hist_op (hist_op
* e
)
3116 update_visitor::visit_hist_op(new hist_op(*e
));
3119 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */