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 (_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
)
548 bool stream
, format
, delim
, newline
, _char
;
549 const char *n
= t
->content
.c_str();
552 format
= delim
= newline
= _char
= false;
554 if (strcmp(n
, "print_char") == 0)
564 if (0 != strncmp(n
, "print", 5))
581 if (*n
== 'l' && *(n
+1) == 'n')
592 print_format
*pf
= new print_format(stream
, format
, delim
, newline
, _char
);
599 print_format::components_to_string(vector
<format_component
> const & components
)
603 for (vector
<format_component
>::const_iterator i
= components
.begin();
604 i
!= components
.end(); ++i
)
607 assert (i
->type
!= conv_unspecified
);
609 if (i
->type
== conv_literal
)
611 assert(!i
->literal_string
.empty());
612 for (string::const_iterator j
= i
->literal_string
.begin();
613 j
!= i
->literal_string
.end(); ++j
)
615 // See also: c_unparser::visit_literal_string and lex_cast_qstring
627 if (i
->test_flag (fmt_flag_zeropad
))
630 if (i
->test_flag (fmt_flag_plus
))
633 if (i
->test_flag (fmt_flag_space
))
636 if (i
->test_flag (fmt_flag_left
))
639 if (i
->test_flag (fmt_flag_special
))
642 if (i
->widthtype
== width_dynamic
)
644 else if (i
->widthtype
!= width_unspecified
&& i
->width
> 0)
647 if (i
->prectype
== prec_dynamic
)
649 else if (i
->prectype
!= prec_unspecified
&& i
->precision
> 0)
650 oss
<< '.' << i
->precision
;
665 if (i
->test_flag (fmt_flag_large
))
670 else if (i
->base
== 8)
672 else if (i
->test_flag (fmt_flag_sign
))
690 case conv_memory_hex
:
702 vector
<print_format::format_component
>
703 print_format::string_to_components(string
const & str
)
705 format_component curr
;
706 vector
<format_component
> res
;
710 string::const_iterator i
= str
.begin();
712 while (i
!= str
.end())
716 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
717 curr
.type
= conv_literal
;
718 curr
.literal_string
+= *i
;
722 else if (i
+1 == str
.end() || *(i
+1) == '%')
725 // *i == '%' and *(i+1) == '%'; append only one '%' to the literal string
726 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
727 curr
.type
= conv_literal
;
728 curr
.literal_string
+= '%';
735 if (curr
.type
!= conv_unspecified
)
737 // Flush any component we were previously accumulating
738 assert (curr
.type
== conv_literal
);
748 // Now we are definitely parsing a conversion.
749 // Begin by parsing flags (which are optional).
754 curr
.set_flag (fmt_flag_zeropad
);
759 curr
.set_flag (fmt_flag_plus
);
764 curr
.set_flag (fmt_flag_left
);
769 curr
.set_flag (fmt_flag_space
);
774 curr
.set_flag (fmt_flag_special
);
785 // Parse optional width
788 curr
.widthtype
= width_dynamic
;
791 else if (isdigit(*i
))
793 curr
.widthtype
= width_static
;
798 curr
.width
+= (*i
- '0');
801 while (i
!= str
.end() && isdigit(*i
));
807 // Parse optional precision
815 curr
.prectype
= prec_dynamic
;
818 else if (isdigit(*i
))
820 curr
.prectype
= prec_static
;
824 curr
.precision
*= 10;
825 curr
.precision
+= (*i
- '0');
828 while (i
!= str
.end() && isdigit(*i
));
835 // Parse the type modifier
846 // Parse the actual conversion specifier (bcsmdioupxXn)
849 // Valid conversion types
851 curr
.type
= conv_binary
;
855 curr
.type
= conv_char
;
859 curr
.type
= conv_string
;
863 curr
.type
= conv_memory
;
867 curr
.type
= conv_memory_hex
;
872 curr
.set_flag (fmt_flag_sign
);
874 curr
.type
= conv_number
;
879 curr
.type
= conv_number
;
884 curr
.set_flag (fmt_flag_large
);
886 curr
.type
= conv_number
;
891 // Since stap 1.3, %p == %#x.
892 curr
.set_flag (fmt_flag_special
);
893 curr
.type
= conv_pointer
;
895 // Oddness for stap < 1.3 is handled in translation
902 if (curr
.type
== conv_unspecified
)
903 throw parse_error(_("invalid or missing conversion specifier"));
910 // If there's a remaining partly-composed conversion, fail.
911 if (!curr
.is_empty())
913 if (curr
.type
== conv_literal
)
916 throw parse_error(_("trailing incomplete print format conversion"));
923 void print_format::print (ostream
& o
) const
925 o
<< tok
->content
<< "(";
926 if (print_with_format
)
927 o
<< lex_cast_qstring (raw_components
);
928 if (print_with_delim
)
929 o
<< lex_cast_qstring (delimiter
.literal_string
);
932 for (vector
<expression
*>::const_iterator i
= args
.begin();
933 i
!= args
.end(); ++i
)
935 if (i
!= args
.begin() || print_with_format
|| print_with_delim
)
942 void stat_op::print (ostream
& o
) const
968 assert (0); // should not happen, as sc_none is only used in foreach sorts
976 hist_op::print (ostream
& o
) const
982 assert(params
.size() == 3);
985 for (size_t i
= 0; i
< params
.size(); ++i
)
987 o
<< ", " << params
[i
];
993 assert(params
.size() == 0);
1001 ostream
& operator << (ostream
& o
, const statement
& k
)
1008 void embeddedcode::print (ostream
&o
) const
1015 void block::print (ostream
& o
) const
1018 for (unsigned i
=0; i
<statements
.size(); i
++)
1019 o
<< *statements
[i
] << endl
;
1023 block::block (statement
* car
, statement
* cdr
)
1025 statements
.push_back(car
);
1026 statements
.push_back(cdr
);
1027 this->tok
= car
->tok
;
1032 void try_block::print (ostream
& o
) const
1034 o
<< "try {" << endl
;
1035 if (try_block
) o
<< *try_block
<< endl
;
1037 if (catch_error_var
) o
<< "(" << *catch_error_var
<< ") ";
1039 if (catch_block
) o
<< *catch_block
<< endl
;
1044 void for_loop::print (ostream
& o
) const
1047 if (init
) init
->print (o
);
1051 if (incr
) incr
->print (o
);
1057 void foreach_loop::print (ostream
& o
) const
1066 for (unsigned i
=0; i
<indexes
.size(); i
++)
1068 if (i
> 0) o
<< ", ";
1069 indexes
[i
]->print (o
);
1070 if (sort_direction
!= 0 && sort_column
== i
+1)
1071 o
<< (sort_direction
> 0 ? "+" : "-");
1075 if (sort_direction
!= 0 && sort_column
== 0)
1079 case sc_count
: o
<< " @count"; break;
1080 case sc_average
: o
<< " @avg"; break;
1081 case sc_min
: o
<< " @min"; break;
1082 case sc_max
: o
<< " @max"; break;
1083 case sc_sum
: o
<< " @sum"; break;
1089 o
<< (sort_direction
> 0 ? "+" : "-");
1101 void null_statement::print (ostream
& o
) const
1107 void expr_statement::print (ostream
& o
) const
1113 void return_statement::print (ostream
& o
) const
1115 o
<< "return " << *value
;
1119 void delete_statement::print (ostream
& o
) const
1121 o
<< "delete " << *value
;
1124 void next_statement::print (ostream
& o
) const
1129 void break_statement::print (ostream
& o
) const
1134 void continue_statement::print (ostream
& o
) const
1139 void if_statement::print (ostream
& o
) const
1141 o
<< "if (" << *condition
<< ") "
1142 << *thenblock
<< endl
;
1144 o
<< "else " << *elseblock
<< endl
;
1148 void stapfile::print (ostream
& o
) const
1150 o
<< "# file " << name
<< endl
;
1152 for (unsigned i
=0; i
<embeds
.size(); i
++)
1153 embeds
[i
]->print (o
);
1155 for (unsigned i
=0; i
<globals
.size(); i
++)
1158 globals
[i
]->print (o
);
1162 for (unsigned i
=0; i
<aliases
.size(); i
++)
1164 aliases
[i
]->print (o
);
1168 for (unsigned i
=0; i
<probes
.size(); i
++)
1170 probes
[i
]->print (o
);
1174 for (unsigned j
= 0; j
< functions
.size(); j
++)
1176 functions
[j
]->print (o
);
1182 void probe::print (ostream
& o
) const
1190 void probe::printsig (ostream
& o
) const
1192 const probe_alias
*alias
= get_alias ();
1195 alias
->printsig (o
);
1199 for (unsigned i
=0; i
<locations
.size(); i
++)
1201 if (i
> 0) o
<< ",";
1202 locations
[i
]->print (o
);
1208 probe::collect_derivation_chain (std::vector
<probe
*> &probes_list
) const
1210 probes_list
.push_back(const_cast<probe
*>(this));
1212 base
->collect_derivation_chain(probes_list
);
1217 probe::collect_derivation_pp_chain (std::vector
<probe_point
*> &pp_list
) const
1219 pp_list
.push_back(const_cast<probe_point
*>(this->locations
[0]));
1221 base
->collect_derivation_pp_chain(pp_list
);
1226 void probe_point::print (ostream
& o
, bool print_extras
) const
1228 for (unsigned i
=0; i
<components
.size(); i
++)
1231 probe_point::component
* c
= components
[i
];
1234 o
<< "(" << *c
->arg
<< ")";
1240 else if (optional
) // sufficient implies optional
1243 o
<< " if (" << *condition
<< ")";
1246 string
probe_point::str (bool print_extras
) const
1249 print(o
, print_extras
);
1254 probe_alias::probe_alias(std::vector
<probe_point
*> const & aliases
):
1255 probe (), alias_names (aliases
), epilogue_style(false)
1259 void probe_alias::printsig (ostream
& o
) const
1261 for (unsigned i
=0; i
<alias_names
.size(); i
++)
1263 o
<< (i
>0 ? " = " : "");
1264 alias_names
[i
]->print (o
);
1267 for (unsigned i
=0; i
<locations
.size(); i
++)
1269 if (i
> 0) o
<< ", ";
1270 locations
[i
]->print (o
);
1275 ostream
& operator << (ostream
& o
, const probe_point
& k
)
1282 ostream
& operator << (ostream
& o
, const symboldecl
& k
)
1290 // ------------------------------------------------------------------------
1295 block::visit (visitor
* u
)
1297 u
->visit_block (this);
1302 try_block::visit (visitor
* u
)
1304 u
->visit_try_block (this);
1309 embeddedcode::visit (visitor
* u
)
1311 u
->visit_embeddedcode (this);
1316 for_loop::visit (visitor
* u
)
1318 u
->visit_for_loop (this);
1322 foreach_loop::visit (visitor
* u
)
1324 u
->visit_foreach_loop (this);
1328 null_statement::visit (visitor
* u
)
1330 u
->visit_null_statement (this);
1334 expr_statement::visit (visitor
* u
)
1336 u
->visit_expr_statement (this);
1340 return_statement::visit (visitor
* u
)
1342 u
->visit_return_statement (this);
1346 delete_statement::visit (visitor
* u
)
1348 u
->push_active_lvalue (this->value
);
1349 u
->visit_delete_statement (this);
1350 u
->pop_active_lvalue ();
1354 if_statement::visit (visitor
* u
)
1356 u
->visit_if_statement (this);
1360 next_statement::visit (visitor
* u
)
1362 u
->visit_next_statement (this);
1366 break_statement::visit (visitor
* u
)
1368 u
->visit_break_statement (this);
1372 continue_statement::visit (visitor
* u
)
1374 u
->visit_continue_statement (this);
1378 literal_string::visit(visitor
* u
)
1380 u
->visit_literal_string (this);
1384 literal_number::visit(visitor
* u
)
1386 u
->visit_literal_number (this);
1390 binary_expression::visit (visitor
* u
)
1392 u
->visit_binary_expression (this);
1396 embedded_expr::visit (visitor
* u
)
1398 u
->visit_embedded_expr (this);
1402 unary_expression::visit (visitor
* u
)
1404 u
->visit_unary_expression (this);
1408 pre_crement::visit (visitor
* u
)
1410 u
->push_active_lvalue (this->operand
);
1411 u
->visit_pre_crement (this);
1412 u
->pop_active_lvalue ();
1416 post_crement::visit (visitor
* u
)
1418 u
->push_active_lvalue (this->operand
);
1419 u
->visit_post_crement (this);
1420 u
->pop_active_lvalue ();
1424 logical_or_expr::visit (visitor
* u
)
1426 u
->visit_logical_or_expr (this);
1430 logical_and_expr::visit (visitor
* u
)
1432 u
->visit_logical_and_expr (this);
1436 array_in::visit (visitor
* u
)
1438 u
->visit_array_in (this);
1442 regex_query::visit (visitor
* u
)
1444 u
->visit_regex_query (this);
1448 comparison::visit (visitor
* u
)
1450 u
->visit_comparison (this);
1454 concatenation::visit (visitor
* u
)
1456 u
->visit_concatenation (this);
1460 ternary_expression::visit (visitor
* u
)
1462 u
->visit_ternary_expression (this);
1466 assignment::visit (visitor
* u
)
1468 u
->push_active_lvalue (this->left
);
1469 u
->visit_assignment (this);
1470 u
->pop_active_lvalue ();
1474 symbol::visit (visitor
* u
)
1476 u
->visit_symbol (this);
1480 target_symbol::visit (visitor
* u
)
1482 u
->visit_target_symbol(this);
1486 target_symbol::visit_components (visitor
* u
)
1488 for (unsigned i
= 0; i
< components
.size(); ++i
)
1489 if (components
[i
].type
== comp_expression_array_index
)
1490 components
[i
].expr_index
->visit (u
);
1494 target_symbol::visit_components (update_visitor
* u
)
1496 for (unsigned i
= 0; i
< components
.size(); ++i
)
1497 if (components
[i
].type
== comp_expression_array_index
)
1498 u
->replace (components
[i
].expr_index
);
1502 cast_op::visit (visitor
* u
)
1504 u
->visit_cast_op(this);
1509 atvar_op::visit (visitor
* u
)
1511 u
->visit_atvar_op(this);
1516 defined_op::visit (visitor
* u
)
1518 u
->visit_defined_op(this);
1523 entry_op::visit (visitor
* u
)
1525 u
->visit_entry_op(this);
1530 perf_op::visit (visitor
* u
)
1532 u
->visit_perf_op(this);
1537 arrayindex::visit (visitor
* u
)
1539 u
->visit_arrayindex (this);
1543 functioncall::visit (visitor
* u
)
1545 u
->visit_functioncall (this);
1549 print_format::visit (visitor
*u
)
1551 u
->visit_print_format (this);
1555 stat_op::visit (visitor
*u
)
1557 u
->visit_stat_op (this);
1561 hist_op::visit (visitor
*u
)
1563 u
->visit_hist_op (this);
1568 indexable::is_symbol(symbol
*& sym_out
)
1575 indexable::is_hist_op(hist_op
*& hist_out
)
1582 symbol::is_symbol(symbol
*& sym_out
)
1589 hist_op::is_hist_op(hist_op
*& hist_out
)
1596 classify_indexable(indexable
* ix
,
1597 symbol
*& array_out
,
1598 hist_op
*& hist_out
)
1603 if (!(ix
->is_symbol (array_out
) || ix
->is_hist_op (hist_out
)))
1604 throw semantic_error(_("Expecting symbol or histogram operator"), ix
->tok
);
1605 if (!(hist_out
|| array_out
))
1606 throw semantic_error(_("Failed to classify indexable"), ix
->tok
);
1610 // ------------------------------------------------------------------------
1613 visitor::is_active_lvalue(expression
*e
)
1615 for (unsigned i
= 0; i
< active_lvalues
.size(); ++i
)
1617 if (active_lvalues
[i
] == e
)
1624 visitor::push_active_lvalue(expression
*e
)
1626 active_lvalues
.push_back(e
);
1630 visitor::pop_active_lvalue()
1632 assert(!active_lvalues
.empty());
1633 active_lvalues
.pop_back();
1638 // ------------------------------------------------------------------------
1641 traversing_visitor::visit_block (block
* s
)
1643 for (unsigned i
=0; i
<s
->statements
.size(); i
++)
1644 s
->statements
[i
]->visit (this);
1648 traversing_visitor::visit_try_block (try_block
* s
)
1651 s
->try_block
->visit (this);
1652 if (s
->catch_error_var
)
1653 s
->catch_error_var
->visit (this);
1655 s
->catch_block
->visit (this);
1659 traversing_visitor::visit_embeddedcode (embeddedcode
*)
1664 traversing_visitor::visit_null_statement (null_statement
*)
1669 traversing_visitor::visit_expr_statement (expr_statement
* s
)
1671 s
->value
->visit (this);
1675 traversing_visitor::visit_if_statement (if_statement
* s
)
1677 s
->condition
->visit (this);
1678 s
->thenblock
->visit (this);
1680 s
->elseblock
->visit (this);
1684 traversing_visitor::visit_for_loop (for_loop
* s
)
1686 if (s
->init
) s
->init
->visit (this);
1687 s
->cond
->visit (this);
1688 if (s
->incr
) s
->incr
->visit (this);
1689 s
->block
->visit (this);
1693 traversing_visitor::visit_foreach_loop (foreach_loop
* s
)
1695 s
->base
->visit(this);
1697 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
1698 s
->indexes
[i
]->visit (this);
1701 s
->value
->visit (this);
1704 s
->limit
->visit (this);
1706 s
->block
->visit (this);
1710 traversing_visitor::visit_return_statement (return_statement
* s
)
1712 s
->value
->visit (this);
1716 traversing_visitor::visit_delete_statement (delete_statement
* s
)
1718 s
->value
->visit (this);
1722 traversing_visitor::visit_next_statement (next_statement
*)
1727 traversing_visitor::visit_break_statement (break_statement
*)
1732 traversing_visitor::visit_continue_statement (continue_statement
*)
1737 traversing_visitor::visit_literal_string (literal_string
*)
1742 traversing_visitor::visit_literal_number (literal_number
*)
1747 traversing_visitor::visit_embedded_expr (embedded_expr
*)
1752 traversing_visitor::visit_binary_expression (binary_expression
* e
)
1754 e
->left
->visit (this);
1755 e
->right
->visit (this);
1759 traversing_visitor::visit_unary_expression (unary_expression
* e
)
1761 e
->operand
->visit (this);
1765 traversing_visitor::visit_pre_crement (pre_crement
* e
)
1767 e
->operand
->visit (this);
1771 traversing_visitor::visit_post_crement (post_crement
* e
)
1773 e
->operand
->visit (this);
1778 traversing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
1780 e
->left
->visit (this);
1781 e
->right
->visit (this);
1785 traversing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
1787 e
->left
->visit (this);
1788 e
->right
->visit (this);
1792 traversing_visitor::visit_array_in (array_in
* e
)
1794 e
->operand
->visit (this);
1798 traversing_visitor::visit_regex_query (regex_query
* e
)
1800 e
->left
->visit (this);
1801 e
->right
->visit (this);
1805 traversing_visitor::visit_comparison (comparison
* e
)
1807 e
->left
->visit (this);
1808 e
->right
->visit (this);
1812 traversing_visitor::visit_concatenation (concatenation
* e
)
1814 e
->left
->visit (this);
1815 e
->right
->visit (this);
1819 traversing_visitor::visit_ternary_expression (ternary_expression
* e
)
1821 e
->cond
->visit (this);
1822 e
->truevalue
->visit (this);
1823 e
->falsevalue
->visit (this);
1827 traversing_visitor::visit_assignment (assignment
* e
)
1829 e
->left
->visit (this);
1830 e
->right
->visit (this);
1834 traversing_visitor::visit_symbol (symbol
*)
1839 traversing_visitor::visit_target_symbol (target_symbol
* e
)
1841 e
->visit_components (this);
1845 traversing_visitor::visit_cast_op (cast_op
* e
)
1847 e
->operand
->visit (this);
1848 e
->visit_components (this);
1852 traversing_visitor::visit_atvar_op (atvar_op
* e
)
1854 e
->visit_components (this);
1858 traversing_visitor::visit_defined_op (defined_op
* e
)
1860 e
->operand
->visit (this);
1864 traversing_visitor::visit_entry_op (entry_op
* e
)
1866 e
->operand
->visit (this);
1871 traversing_visitor::visit_perf_op (perf_op
* e
)
1873 e
->operand
->visit (this);
1878 traversing_visitor::visit_arrayindex (arrayindex
* e
)
1880 for (unsigned i
=0; i
<e
->indexes
.size(); i
++)
1881 e
->indexes
[i
]->visit (this);
1883 e
->base
->visit(this);
1887 traversing_visitor::visit_functioncall (functioncall
* e
)
1889 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1890 e
->args
[i
]->visit (this);
1894 traversing_visitor::visit_print_format (print_format
* e
)
1896 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1897 e
->args
[i
]->visit (this);
1899 e
->hist
->visit(this);
1903 traversing_visitor::visit_stat_op (stat_op
* e
)
1905 e
->stat
->visit (this);
1909 traversing_visitor::visit_hist_op (hist_op
* e
)
1911 e
->stat
->visit (this);
1916 functioncall_traversing_visitor::visit_functioncall (functioncall
* e
)
1918 traversing_visitor::visit_functioncall (e
);
1920 // prevent infinite recursion
1921 if (traversed
.find (e
->referent
) == traversed
.end ())
1923 traversed
.insert (e
->referent
);
1925 functiondecl
* last_current_function
= current_function
;
1926 current_function
= e
->referent
;
1927 e
->referent
->body
->visit (this);
1928 current_function
= last_current_function
;
1934 varuse_collecting_visitor::visit_try_block (try_block
*s
)
1937 s
->try_block
->visit (this);
1938 if (s
->catch_error_var
)
1939 written
.insert (s
->catch_error_var
->referent
);
1941 s
->catch_block
->visit (this);
1943 // NB: don't functioncall_traversing_visitor::visit_try_block (s);
1944 // since that would count s->catch_error_var as a read also.
1949 varuse_collecting_visitor::visit_embeddedcode (embeddedcode
*s
)
1951 assert (current_function
); // only they get embedded code
1953 // Don't allow embedded C functions in unprivileged mode unless
1954 // they are tagged with /* unprivileged */ or /* myproc-unprivileged */
1955 // or we're in a usermode runtime.
1956 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1957 ! pr_contains (session
.privilege
, pr_stapsys
) &&
1958 ! session
.runtime_usermode_p () &&
1959 s
->code
.find ("/* unprivileged */") == string::npos
&&
1960 s
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1961 throw semantic_error (_F("function may not be used when --privilege=%s is specified",
1962 pr_name (session
.privilege
)),
1963 current_function
->tok
);
1965 // Don't allow /* guru */ functions unless -g is active.
1966 if (!session
.guru_mode
&& s
->code
.find ("/* guru */") != string::npos
)
1967 throw semantic_error (_("function may not be used unless -g is specified"),
1968 current_function
->tok
);
1970 // PR14524: Support old-style THIS->local syntax on per-function basis.
1971 if (s
->code
.find ("/* unmangled */") != string::npos
)
1972 current_function
->mangle_oldstyle
= true;
1974 // We want to elide embedded-C functions when possible. For
1975 // example, each $target variable access is expanded to an
1976 // embedded-C function call. Yet, for safety reasons, we should
1977 // presume that embedded-C functions have intentional side-effects.
1979 // To tell these two types of functions apart, we apply a
1980 // Kludge(tm): we look for a magic string within the function body.
1981 // $target variables as rvalues will have this; lvalues won't.
1982 // Also, explicit side-effect-free tapset functions will have this.
1984 if (s
->code
.find ("/* pure */") != string::npos
)
1987 embedded_seen
= true;
1991 // About the same case as above.
1993 varuse_collecting_visitor::visit_embedded_expr (embedded_expr
*e
)
1995 // Don't allow embedded C expressions in unprivileged mode unless
1996 // they are tagged with /* unprivileged */ or /* myproc-unprivileged */
1997 // or we're in a usermode runtime.
1998 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1999 ! pr_contains (session
.privilege
, pr_stapsys
) &&
2000 ! session
.runtime_usermode_p () &&
2001 e
->code
.find ("/* unprivileged */") == string::npos
&&
2002 e
->code
.find ("/* myproc-unprivileged */") == string::npos
)
2003 throw semantic_error (_F("embedded expression may not be used when --privilege=%s is specified",
2004 pr_name (session
.privilege
)),
2007 // Don't allow /* guru */ functions unless -g is active.
2008 if (!session
.guru_mode
&& e
->code
.find ("/* guru */") != string::npos
)
2009 throw semantic_error (_("embedded expression may not be used unless -g is specified"),
2012 // We want to elide embedded-C functions when possible. For
2013 // example, each $target variable access is expanded to an
2014 // embedded-C function call. Yet, for safety reasons, we should
2015 // presume that embedded-C functions have intentional side-effects.
2017 // To tell these two types of functions apart, we apply a
2018 // Kludge(tm): we look for a magic string within the function body.
2019 // $target variables as rvalues will have this; lvalues won't.
2020 // Also, explicit side-effect-free tapset functions will have this.
2022 if (e
->code
.find ("/* pure */") != string::npos
)
2025 embedded_seen
= true;
2030 varuse_collecting_visitor::visit_target_symbol (target_symbol
*e
)
2032 // Still-unresolved target symbol assignments get treated as
2033 // generating side-effects like embedded-C, to prevent premature
2034 // elision and later error message suppression (PR5516). rvalue use
2035 // of unresolved target symbols is OTOH not considered a side-effect.
2037 if (is_active_lvalue (e
))
2038 embedded_seen
= true;
2040 functioncall_traversing_visitor::visit_target_symbol (e
);
2045 varuse_collecting_visitor::visit_atvar_op (atvar_op
*e
)
2047 // Similar to visit_target_symbol
2049 if (is_active_lvalue (e
))
2050 embedded_seen
= true;
2052 functioncall_traversing_visitor::visit_atvar_op (e
);
2057 varuse_collecting_visitor::visit_cast_op (cast_op
*e
)
2059 // As with target_symbols, unresolved cast assignments need to preserved
2060 // for later error handling.
2061 if (is_active_lvalue (e
))
2062 embedded_seen
= true;
2064 functioncall_traversing_visitor::visit_cast_op (e
);
2068 varuse_collecting_visitor::visit_defined_op (defined_op
*e
)
2071 functioncall_traversing_visitor::visit_defined_op (e
);
2075 varuse_collecting_visitor::visit_entry_op (entry_op
*e
)
2078 functioncall_traversing_visitor::visit_entry_op (e
);
2083 varuse_collecting_visitor::visit_perf_op (perf_op
*e
)
2085 functioncall_traversing_visitor::visit_perf_op (e
);
2090 varuse_collecting_visitor::visit_print_format (print_format
* e
)
2092 // NB: Instead of being top-level statements, "print" and "printf"
2093 // are implemented as statement-expressions containing a
2094 // print_format. They have side-effects, but not via the
2095 // embedded-code detection method above.
2097 // But sprint and sprintf don't have side-effects.
2099 bool last_lvalue_read
= current_lvalue_read
;
2100 current_lvalue_read
= true;
2101 if (e
->print_to_stream
)
2102 embedded_seen
= true; // a proxy for "has unknown side-effects"
2104 functioncall_traversing_visitor::visit_print_format (e
);
2105 current_lvalue_read
= last_lvalue_read
;
2110 varuse_collecting_visitor::visit_assignment (assignment
*e
)
2112 if (e
->op
== "=" || e
->op
== "<<<") // pure writes
2114 expression
* last_lvalue
= current_lvalue
;
2115 bool last_lvalue_read
= current_lvalue_read
;
2116 current_lvalue
= e
->left
; // leave a mark for ::visit_symbol
2117 current_lvalue_read
= true;
2118 functioncall_traversing_visitor::visit_assignment (e
);
2119 current_lvalue
= last_lvalue
;
2120 current_lvalue_read
= last_lvalue_read
;
2122 else // read-modify-writes
2124 expression
* last_lrvalue
= current_lrvalue
;
2125 current_lrvalue
= e
->left
; // leave a mark for ::visit_symbol
2126 functioncall_traversing_visitor::visit_assignment (e
);
2127 current_lrvalue
= last_lrvalue
;
2132 varuse_collecting_visitor::visit_symbol (symbol
*e
)
2134 if (e
->referent
== 0)
2135 throw semantic_error (_("symbol without referent"), e
->tok
);
2137 // We could handle initialized globals by marking them as "written".
2138 // However, this current visitor may be called for a function or
2139 // probe body, from the point of view of which this global is
2140 // already initialized, so not written.
2142 if (e->referent->init)
2143 written.insert (e->referent);
2146 if (current_lvalue
== e
|| current_lrvalue
== e
)
2148 written
.insert (e
->referent
);
2150 if (current_lvalue
!= e
|| current_lrvalue
== e
)
2152 read
.insert (e
->referent
);
2155 if (current_lrvalue
== e
)
2157 if (current_lvalue_read
)
2158 used
.insert (e
->referent
);
2160 else if (current_lvalue
!= e
)
2161 used
.insert (e
->referent
);
2164 // NB: stat_op need not be overridden, since it will get to
2165 // visit_symbol and only as a possible rvalue.
2169 varuse_collecting_visitor::visit_arrayindex (arrayindex
*e
)
2171 // Hooking this callback is necessary because of the hacky
2172 // statistics representation. For the expression "i[4] = 5", the
2173 // incoming lvalue will point to this arrayindex. However, the
2174 // symbol corresponding to the "i[4]" is multiply inherited with
2175 // arrayindex. If the symbol base part of this object is not at
2176 // offset 0, then static_cast<symbol*>(e) may result in a different
2177 // address, and not match lvalue by number when we recurse that way.
2178 // So we explicitly override the incoming lvalue/lrvalue values to
2179 // point at the embedded objects' actual base addresses.
2181 expression
* last_lrvalue
= current_lrvalue
;
2182 expression
* last_lvalue
= current_lvalue
;
2184 symbol
*array
= NULL
;
2185 hist_op
*hist
= NULL
;
2186 classify_indexable(e
->base
, array
, hist
);
2187 expression
*value
= array
?: hist
->stat
;
2189 if (current_lrvalue
== e
) current_lrvalue
= value
;
2190 if (current_lvalue
== e
) current_lvalue
= value
;
2191 functioncall_traversing_visitor::visit_arrayindex (e
);
2193 current_lrvalue
= last_lrvalue
;
2194 current_lvalue
= last_lvalue
;
2199 varuse_collecting_visitor::visit_pre_crement (pre_crement
*e
)
2201 expression
* last_lrvalue
= current_lrvalue
;
2202 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2203 functioncall_traversing_visitor::visit_pre_crement (e
);
2204 current_lrvalue
= last_lrvalue
;
2208 varuse_collecting_visitor::visit_post_crement (post_crement
*e
)
2210 expression
* last_lrvalue
= current_lrvalue
;
2211 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2212 functioncall_traversing_visitor::visit_post_crement (e
);
2213 current_lrvalue
= last_lrvalue
;
2217 varuse_collecting_visitor::visit_foreach_loop (foreach_loop
* s
)
2219 // NB: we duplicate so don't bother call
2220 // functioncall_traversing_visitor::visit_foreach_loop (s);
2222 s
->base
->visit(this);
2224 // If the collection is sorted, imply a "write" access to the
2225 // array in addition to the "read" one already noted above.
2226 if (s
->sort_direction
)
2228 symbol
*array
= NULL
;
2229 hist_op
*hist
= NULL
;
2230 classify_indexable (s
->base
, array
, hist
);
2231 if (array
) this->written
.insert (array
->referent
);
2232 // XXX: Can hist_op iterations be sorted?
2235 // NB: don't forget to visit the index expressions, which are lvalues.
2236 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
2238 expression
* last_lvalue
= current_lvalue
;
2239 current_lvalue
= s
->indexes
[i
]; // leave a mark for ::visit_symbol
2240 s
->indexes
[i
]->visit (this);
2241 current_lvalue
= last_lvalue
;
2244 // The value is an lvalue too
2247 expression
* last_lvalue
= current_lvalue
;
2248 current_lvalue
= s
->value
; // leave a mark for ::visit_symbol
2249 s
->value
->visit (this);
2250 current_lvalue
= last_lvalue
;
2254 s
->limit
->visit (this);
2256 s
->block
->visit (this);
2261 varuse_collecting_visitor::visit_delete_statement (delete_statement
* s
)
2263 // Ideally, this would be treated like an assignment: a plain write
2264 // to the underlying value ("lvalue"). XXX: However, the
2265 // optimization pass is not smart enough to remove an unneeded
2266 // "delete" yet, so we pose more like a *crement ("lrvalue"). This
2267 // should protect the underlying value from optimizional mischief.
2268 expression
* last_lrvalue
= current_lrvalue
;
2269 bool last_lvalue_read
= current_lvalue_read
;
2270 current_lrvalue
= s
->value
; // leave a mark for ::visit_symbol
2271 current_lvalue_read
= true;
2272 functioncall_traversing_visitor::visit_delete_statement (s
);
2273 current_lrvalue
= last_lrvalue
;
2274 current_lvalue_read
= last_lvalue_read
;
2278 varuse_collecting_visitor::side_effect_free ()
2280 return (written
.empty() && !embedded_seen
);
2285 varuse_collecting_visitor::side_effect_free_wrt (const set
<vardecl
*>& vars
)
2287 // A looser notion of side-effect-freeness with respect to a given
2288 // list of variables.
2290 // That's useful because the written list may consist of local
2291 // variables of called functions. But visible side-effects only
2292 // occur if the client's locals, or any globals are written-to.
2294 set
<vardecl
*> intersection
;
2295 insert_iterator
<set
<vardecl
*> > int_it (intersection
, intersection
.begin());
2296 set_intersection (written
.begin(), written
.end(),
2297 vars
.begin(), vars
.end(),
2300 return (intersection
.empty() && !embedded_seen
);
2306 // ------------------------------------------------------------------------
2309 throwing_visitor::throwing_visitor (const std::string
& m
): msg (m
) {}
2310 throwing_visitor::throwing_visitor (): msg (_("invalid element")) {}
2314 throwing_visitor::throwone (const token
* t
)
2316 throw semantic_error (msg
, t
);
2320 throwing_visitor::visit_block (block
* s
)
2326 throwing_visitor::visit_try_block (try_block
* s
)
2333 throwing_visitor::visit_embeddedcode (embeddedcode
* s
)
2339 throwing_visitor::visit_null_statement (null_statement
* s
)
2345 throwing_visitor::visit_expr_statement (expr_statement
* s
)
2351 throwing_visitor::visit_if_statement (if_statement
* s
)
2357 throwing_visitor::visit_for_loop (for_loop
* s
)
2363 throwing_visitor::visit_foreach_loop (foreach_loop
* s
)
2369 throwing_visitor::visit_return_statement (return_statement
* s
)
2375 throwing_visitor::visit_delete_statement (delete_statement
* s
)
2381 throwing_visitor::visit_next_statement (next_statement
* s
)
2387 throwing_visitor::visit_break_statement (break_statement
* s
)
2393 throwing_visitor::visit_continue_statement (continue_statement
* s
)
2399 throwing_visitor::visit_literal_string (literal_string
* e
)
2405 throwing_visitor::visit_literal_number (literal_number
* e
)
2411 throwing_visitor::visit_embedded_expr (embedded_expr
* e
)
2417 throwing_visitor::visit_binary_expression (binary_expression
* e
)
2423 throwing_visitor::visit_unary_expression (unary_expression
* e
)
2429 throwing_visitor::visit_pre_crement (pre_crement
* e
)
2435 throwing_visitor::visit_post_crement (post_crement
* e
)
2442 throwing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2448 throwing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2454 throwing_visitor::visit_array_in (array_in
* e
)
2460 throwing_visitor::visit_regex_query (regex_query
* e
)
2466 throwing_visitor::visit_comparison (comparison
* e
)
2472 throwing_visitor::visit_concatenation (concatenation
* e
)
2478 throwing_visitor::visit_ternary_expression (ternary_expression
* e
)
2484 throwing_visitor::visit_assignment (assignment
* e
)
2490 throwing_visitor::visit_symbol (symbol
* e
)
2496 throwing_visitor::visit_target_symbol (target_symbol
* e
)
2502 throwing_visitor::visit_atvar_op (atvar_op
* e
)
2508 throwing_visitor::visit_cast_op (cast_op
* e
)
2514 throwing_visitor::visit_defined_op (defined_op
* e
)
2520 throwing_visitor::visit_entry_op (entry_op
* e
)
2527 throwing_visitor::visit_perf_op (perf_op
* e
)
2534 throwing_visitor::visit_arrayindex (arrayindex
* e
)
2540 throwing_visitor::visit_functioncall (functioncall
* e
)
2546 throwing_visitor::visit_print_format (print_format
* e
)
2552 throwing_visitor::visit_stat_op (stat_op
* e
)
2558 throwing_visitor::visit_hist_op (hist_op
* e
)
2564 // ------------------------------------------------------------------------
2568 update_visitor::visit_block (block
* s
)
2570 for (unsigned i
= 0; i
< s
->statements
.size(); ++i
)
2571 replace (s
->statements
[i
]);
2576 update_visitor::visit_try_block (try_block
* s
)
2578 replace (s
->try_block
);
2579 replace (s
->catch_error_var
);
2580 replace (s
->catch_block
);
2585 update_visitor::visit_embeddedcode (embeddedcode
* s
)
2591 update_visitor::visit_null_statement (null_statement
* s
)
2597 update_visitor::visit_expr_statement (expr_statement
* s
)
2604 update_visitor::visit_if_statement (if_statement
* s
)
2606 replace (s
->condition
);
2607 replace (s
->thenblock
);
2608 replace (s
->elseblock
);
2613 update_visitor::visit_for_loop (for_loop
* s
)
2623 update_visitor::visit_foreach_loop (foreach_loop
* s
)
2625 for (unsigned i
= 0; i
< s
->indexes
.size(); ++i
)
2626 replace (s
->indexes
[i
]);
2635 update_visitor::visit_return_statement (return_statement
* s
)
2642 update_visitor::visit_delete_statement (delete_statement
* s
)
2649 update_visitor::visit_next_statement (next_statement
* s
)
2655 update_visitor::visit_break_statement (break_statement
* s
)
2661 update_visitor::visit_continue_statement (continue_statement
* s
)
2667 update_visitor::visit_literal_string (literal_string
* e
)
2673 update_visitor::visit_literal_number (literal_number
* e
)
2679 update_visitor::visit_embedded_expr (embedded_expr
* e
)
2685 update_visitor::visit_binary_expression (binary_expression
* e
)
2693 update_visitor::visit_unary_expression (unary_expression
* e
)
2695 replace (e
->operand
);
2700 update_visitor::visit_pre_crement (pre_crement
* e
)
2702 replace (e
->operand
);
2707 update_visitor::visit_post_crement (post_crement
* e
)
2709 replace (e
->operand
);
2715 update_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2723 update_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2731 update_visitor::visit_array_in (array_in
* e
)
2733 replace (e
->operand
);
2738 update_visitor::visit_regex_query (regex_query
* e
)
2741 replace (e
->right
); // XXX: do we *need* to replace literal in RHS?
2746 update_visitor::visit_comparison (comparison
* e
)
2754 update_visitor::visit_concatenation (concatenation
* e
)
2762 update_visitor::visit_ternary_expression (ternary_expression
* e
)
2765 replace (e
->truevalue
);
2766 replace (e
->falsevalue
);
2771 update_visitor::visit_assignment (assignment
* e
)
2779 update_visitor::visit_symbol (symbol
* e
)
2785 update_visitor::visit_target_symbol (target_symbol
* e
)
2787 e
->visit_components (this);
2792 update_visitor::visit_cast_op (cast_op
* e
)
2794 replace (e
->operand
);
2795 e
->visit_components (this);
2800 update_visitor::visit_atvar_op (atvar_op
* e
)
2802 e
->visit_components (this);
2807 update_visitor::visit_defined_op (defined_op
* e
)
2809 replace (e
->operand
);
2814 update_visitor::visit_entry_op (entry_op
* e
)
2816 replace (e
->operand
);
2821 update_visitor::visit_perf_op (perf_op
* e
)
2823 replace (e
->operand
);
2828 update_visitor::visit_arrayindex (arrayindex
* e
)
2831 for (unsigned i
= 0; i
< e
->indexes
.size(); ++i
)
2832 replace (e
->indexes
[i
]);
2837 update_visitor::visit_functioncall (functioncall
* e
)
2839 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2840 replace (e
->args
[i
]);
2845 update_visitor::visit_print_format (print_format
* e
)
2847 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2848 replace (e
->args
[i
]);
2854 update_visitor::visit_stat_op (stat_op
* e
)
2861 update_visitor::visit_hist_op (hist_op
* e
)
2868 // ------------------------------------------------------------------------
2872 deep_copy_visitor::visit_block (block
* s
)
2874 update_visitor::visit_block(new block(*s
));
2878 deep_copy_visitor::visit_try_block (try_block
* s
)
2880 update_visitor::visit_try_block(new try_block(*s
));
2884 deep_copy_visitor::visit_embeddedcode (embeddedcode
* s
)
2886 update_visitor::visit_embeddedcode(new embeddedcode(*s
));
2890 deep_copy_visitor::visit_null_statement (null_statement
* s
)
2892 update_visitor::visit_null_statement(new null_statement(*s
));
2896 deep_copy_visitor::visit_expr_statement (expr_statement
* s
)
2898 update_visitor::visit_expr_statement(new expr_statement(*s
));
2902 deep_copy_visitor::visit_if_statement (if_statement
* s
)
2904 update_visitor::visit_if_statement(new if_statement(*s
));
2908 deep_copy_visitor::visit_for_loop (for_loop
* s
)
2910 update_visitor::visit_for_loop(new for_loop(*s
));
2914 deep_copy_visitor::visit_foreach_loop (foreach_loop
* s
)
2916 update_visitor::visit_foreach_loop(new foreach_loop(*s
));
2920 deep_copy_visitor::visit_return_statement (return_statement
* s
)
2922 update_visitor::visit_return_statement(new return_statement(*s
));
2926 deep_copy_visitor::visit_delete_statement (delete_statement
* s
)
2928 update_visitor::visit_delete_statement(new delete_statement(*s
));
2932 deep_copy_visitor::visit_next_statement (next_statement
* s
)
2934 update_visitor::visit_next_statement(new next_statement(*s
));
2938 deep_copy_visitor::visit_break_statement (break_statement
* s
)
2940 update_visitor::visit_break_statement(new break_statement(*s
));
2944 deep_copy_visitor::visit_continue_statement (continue_statement
* s
)
2946 update_visitor::visit_continue_statement(new continue_statement(*s
));
2950 deep_copy_visitor::visit_literal_string (literal_string
* e
)
2952 update_visitor::visit_literal_string(new literal_string(*e
));
2956 deep_copy_visitor::visit_literal_number (literal_number
* e
)
2958 update_visitor::visit_literal_number(new literal_number(*e
));
2962 deep_copy_visitor::visit_embedded_expr (embedded_expr
* e
)
2964 update_visitor::visit_embedded_expr(new embedded_expr(*e
));
2968 deep_copy_visitor::visit_binary_expression (binary_expression
* e
)
2970 update_visitor::visit_binary_expression(new binary_expression(*e
));
2974 deep_copy_visitor::visit_unary_expression (unary_expression
* e
)
2976 update_visitor::visit_unary_expression(new unary_expression(*e
));
2980 deep_copy_visitor::visit_pre_crement (pre_crement
* e
)
2982 update_visitor::visit_pre_crement(new pre_crement(*e
));
2986 deep_copy_visitor::visit_post_crement (post_crement
* e
)
2988 update_visitor::visit_post_crement(new post_crement(*e
));
2993 deep_copy_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2995 update_visitor::visit_logical_or_expr(new logical_or_expr(*e
));
2999 deep_copy_visitor::visit_logical_and_expr (logical_and_expr
* e
)
3001 update_visitor::visit_logical_and_expr(new logical_and_expr(*e
));
3005 deep_copy_visitor::visit_array_in (array_in
* e
)
3007 update_visitor::visit_array_in(new array_in(*e
));
3011 deep_copy_visitor::visit_regex_query (regex_query
* e
)
3013 update_visitor::visit_regex_query(new regex_query(*e
));
3017 deep_copy_visitor::visit_comparison (comparison
* e
)
3019 update_visitor::visit_comparison(new comparison(*e
));
3023 deep_copy_visitor::visit_concatenation (concatenation
* e
)
3025 update_visitor::visit_concatenation(new concatenation(*e
));
3029 deep_copy_visitor::visit_ternary_expression (ternary_expression
* e
)
3031 update_visitor::visit_ternary_expression(new ternary_expression(*e
));
3035 deep_copy_visitor::visit_assignment (assignment
* e
)
3037 update_visitor::visit_assignment(new assignment(*e
));
3041 deep_copy_visitor::visit_symbol (symbol
* e
)
3043 symbol
* n
= new symbol(*e
);
3044 n
->referent
= NULL
; // don't copy!
3045 update_visitor::visit_symbol(n
);
3049 deep_copy_visitor::visit_target_symbol (target_symbol
* e
)
3051 target_symbol
* n
= new target_symbol(*e
);
3052 n
->referent
= NULL
; // don't copy!
3053 update_visitor::visit_target_symbol(n
);
3057 deep_copy_visitor::visit_cast_op (cast_op
* e
)
3059 update_visitor::visit_cast_op(new cast_op(*e
));
3063 deep_copy_visitor::visit_atvar_op (atvar_op
* e
)
3065 update_visitor::visit_atvar_op(new atvar_op(*e
));
3069 deep_copy_visitor::visit_defined_op (defined_op
* e
)
3071 update_visitor::visit_defined_op(new defined_op(*e
));
3075 deep_copy_visitor::visit_entry_op (entry_op
* e
)
3077 update_visitor::visit_entry_op(new entry_op(*e
));
3081 deep_copy_visitor::visit_perf_op (perf_op
* e
)
3083 update_visitor::visit_perf_op(new perf_op(*e
));
3087 deep_copy_visitor::visit_arrayindex (arrayindex
* e
)
3089 update_visitor::visit_arrayindex(new arrayindex(*e
));
3093 deep_copy_visitor::visit_functioncall (functioncall
* e
)
3095 functioncall
* n
= new functioncall(*e
);
3096 n
->referent
= NULL
; // don't copy!
3097 update_visitor::visit_functioncall(n
);
3101 deep_copy_visitor::visit_print_format (print_format
* e
)
3103 update_visitor::visit_print_format(new print_format(*e
));
3107 deep_copy_visitor::visit_stat_op (stat_op
* e
)
3109 update_visitor::visit_stat_op(new stat_op(*e
));
3113 deep_copy_visitor::visit_hist_op (hist_op
* e
)
3115 update_visitor::visit_hist_op(new hist_op(*e
));
3118 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */