1 // parse tree functions
2 // Copyright (C) 2005-2011 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 expression::expression ():
29 type (pe_unknown
), tok (0)
34 expression::~expression ()
39 statement::statement ():
45 statement::statement (const token
* tok
):
51 null_statement::null_statement (const token
* tok
):
57 statement::~statement ()
68 arrayindex::arrayindex ():
74 functioncall::functioncall ():
80 symboldecl::symboldecl ():
81 tok (0), systemtap_v_conditional (0),
87 symboldecl::~symboldecl ()
91 probe_point::probe_point (std::vector
<component
*> const & comps
):
92 components(comps
), optional (false), sufficient (false),
97 // NB: shallow-copy of compoonents & condition!
98 probe_point::probe_point (const probe_point
& pp
):
99 components(pp
.components
), optional (pp
.optional
), sufficient (pp
.sufficient
),
100 condition (pp
.condition
)
105 probe_point::probe_point ():
106 optional (false), sufficient (false), condition (0)
111 unsigned probe::last_probeidx
= 0;
114 body (0), tok (0), systemtap_v_conditional (0), privileged (false)
116 this->name
= string ("probe_") + lex_cast(last_probeidx
++);
120 // Copy constructor, but with overriding probe-point. To be used when
121 // mapping script-level probe points to another one, early during pass
122 // 2. There should be no symbol resolution done yet.
123 probe::probe(const probe
& p
, probe_point
* l
)
125 this->name
= string ("probe_") + lex_cast(last_probeidx
++);
127 this->locations
.push_back(l
);
128 this->body
= p
.body
; // NB: not needed to be copied yet; a later derived_probe will
129 this->privileged
= p
.privileged
;
130 this->systemtap_v_conditional
= p
.systemtap_v_conditional
;
131 assert (p
.locals
.size() == 0);
132 assert (p
.unused_locals
.size() == 0);
136 probe_point::component::component ():
142 probe_point::component::component (std::string
const & f
, literal
* a
):
143 functor(f
), arg(a
), tok(0)
149 arity_tok(0), arity (-1), maxsize(0), init(NULL
), skip_init(false), wrap(false)
155 vardecl::set_arity (int a
, const token
* t
)
160 if (a
== 0 && maxsize
> 0)
161 throw semantic_error (_("inconsistent arity"), tok
);
163 if (arity
!= a
&& arity
>= 0)
165 semantic_error
err (_F("inconsistent arity (%s vs %d)",
166 lex_cast(arity
).c_str(), a
), t
?:tok
);
168 err
.chain
= new semantic_error (_F("arity %s first inferred here",
169 lex_cast(arity
).c_str()), arity_tok
);
177 index_types
.resize (arity
);
178 for (int i
=0; i
<arity
; i
++)
179 index_types
[i
] = pe_unknown
;
184 vardecl::compatible_arity (int a
)
186 if (a
== 0 && maxsize
> 0)
188 if (arity
== -1 || a
== -1)
194 functiondecl::functiondecl ():
195 body (0), synthetic (false)
200 functiondecl::join (systemtap_session
& s
)
203 throw semantic_error (_("internal error, joining a non-synthetic function"), tok
);
204 if (!s
.functions
.insert (make_pair (name
, this)).second
)
205 throw semantic_error (_F("synthetic function '%s' conflicts with an existing function",
207 tok
->location
.file
->functions
.push_back (this);
211 literal_number::literal_number (int64_t v
, bool hex
)
219 literal_string::literal_string (const string
& v
)
227 operator << (ostream
& o
, const exp_type
& e
)
231 case pe_unknown
: o
<< "unknown"; break;
232 case pe_long
: o
<< "long"; break;
233 case pe_string
: o
<< "string"; break;
234 case pe_stats
: o
<< "stats"; break;
235 default: o
<< "???"; break;
242 target_symbol::assert_no_components(const std::string
& tapset
, bool pretty_ok
)
244 if (components
.empty())
247 switch (components
[0].type
)
249 case comp_literal_array_index
:
250 case comp_expression_array_index
:
251 throw semantic_error(_F("%s variable '%s' may not be used as array",
252 tapset
.c_str(), name
.c_str()), components
[0].tok
);
253 case comp_struct_member
:
254 throw semantic_error(_F("%s variable '%s' may not be used as a structure",
255 tapset
.c_str(), name
.c_str()), components
[0].tok
);
256 case comp_pretty_print
:
258 throw semantic_error(_F("%s variable '%s' may not be pretty-printed",
259 tapset
.c_str(), name
.c_str()), components
[0].tok
);
262 throw semantic_error (_F("invalid use of %s variable '%s'",
263 tapset
.c_str(), name
.c_str()), components
[0].tok
);
268 void target_symbol::chain (const semantic_error
&er
)
270 semantic_error
* e
= new semantic_error(er
);
273 assert (e
->chain
== 0);
274 e
->chain
= this->saved_conversion_error
;
275 this->saved_conversion_error
= e
;
279 // ------------------------------------------------------------------------
280 // parse tree printing
282 ostream
& operator << (ostream
& o
, const expression
& k
)
289 void literal_string::print (ostream
& o
) const
292 for (unsigned i
=0; i
<value
.size(); i
++)
293 if (value
[i
] == '"') // or other escapeworthy characters?
301 void literal_number::print (ostream
& o
) const
304 o
<< hex
<< showbase
;
307 o
<< dec
<< noshowbase
;
311 void embedded_expr::print (ostream
& o
) const
313 o
<< "%{ " << code
<< " %}";
317 void binary_expression::print (ostream
& o
) const
319 o
<< "(" << *left
<< ") "
321 << " (" << *right
<< ")";
325 void unary_expression::print (ostream
& o
) const
327 o
<< op
<< '(' << *operand
<< ")";
330 void array_in::print (ostream
& o
) const
333 for (unsigned i
=0; i
<operand
->indexes
.size(); i
++)
335 if (i
> 0) o
<< ", ";
336 operand
->indexes
[i
]->print (o
);
339 operand
->base
->print_indexable (o
);
342 void post_crement::print (ostream
& o
) const
344 o
<< '(' << *operand
<< ")" << op
;
348 void ternary_expression::print (ostream
& o
) const
350 o
<< "(" << *cond
<< ")?("
351 << *truevalue
<< "):("
352 << *falsevalue
<< ")";
356 void symbol::print (ostream
& o
) const
362 void target_symbol::component::print (ostream
& o
) const
366 case comp_pretty_print
:
367 case comp_struct_member
:
370 case comp_literal_array_index
:
371 o
<< '[' << num_index
<< ']';
373 case comp_expression_array_index
:
374 o
<< '[' << *expr_index
<< ']';
380 std::ostream
& operator << (std::ostream
& o
, const target_symbol::component
& c
)
387 void target_symbol::print (ostream
& o
) const
392 for (unsigned i
= 0; i
< components
.size(); ++i
)
397 void cast_op::print (ostream
& o
) const
401 o
<< name
<< '(' << *operand
;
402 o
<< ", " << lex_cast_qstring (type_name
);
403 if (module
.length() > 0)
404 o
<< ", " << lex_cast_qstring (module
);
406 for (unsigned i
= 0; i
< components
.size(); ++i
)
411 void defined_op::print (ostream
& o
) const
413 o
<< "@defined(" << *operand
<< ")";
417 void entry_op::print (ostream
& o
) const
419 o
<< "@entry(" << *operand
<< ")";
423 void vardecl::print (ostream
& o
) const
429 o
<< "[" << maxsize
<< "]";
430 if (arity
> 0 || index_types
.size() > 0)
440 void vardecl::printsig (ostream
& o
) const
446 o
<< "[" << maxsize
<< "]";
448 if (index_types
.size() > 0)
451 for (unsigned i
=0; i
<index_types
.size(); i
++)
452 o
<< (i
>0 ? ", " : "") << index_types
[i
];
458 void functiondecl::print (ostream
& o
) const
460 o
<< "function " << name
<< " (";
461 for (unsigned i
=0; i
<formal_args
.size(); i
++)
462 o
<< (i
>0 ? ", " : "") << *formal_args
[i
];
468 void functiondecl::printsig (ostream
& o
) const
470 o
<< name
<< ":" << type
<< " (";
471 for (unsigned i
=0; i
<formal_args
.size(); i
++)
472 o
<< (i
>0 ? ", " : "")
475 << formal_args
[i
]->type
;
480 void arrayindex::print (ostream
& o
) const
482 base
->print_indexable (o
);
484 for (unsigned i
=0; i
<indexes
.size(); i
++)
485 o
<< (i
>0 ? ", " : "") << *indexes
[i
];
490 void functioncall::print (ostream
& o
) const
492 o
<< function
<< "(";
493 for (unsigned i
=0; i
<args
.size(); i
++)
494 o
<< (i
>0 ? ", " : "") << *args
[i
];
500 print_format::create(const token
*t
)
502 bool stream
, format
, delim
, newline
, _char
;
503 const char *n
= t
->content
.c_str();
506 format
= delim
= newline
= _char
= false;
508 if (strcmp(n
, "print_char") == 0)
518 if (0 != strncmp(n
, "print", 5))
535 if (*n
== 'l' && *(n
+1) == 'n')
546 print_format
*pf
= new print_format(stream
, format
, delim
, newline
, _char
);
553 print_format::components_to_string(vector
<format_component
> const & components
)
557 for (vector
<format_component
>::const_iterator i
= components
.begin();
558 i
!= components
.end(); ++i
)
561 assert (i
->type
!= conv_unspecified
);
563 if (i
->type
== conv_literal
)
565 assert(!i
->literal_string
.empty());
566 for (string::const_iterator j
= i
->literal_string
.begin();
567 j
!= i
->literal_string
.end(); ++j
)
569 // See also: c_unparser::visit_literal_string and lex_cast_qstring
581 if (i
->test_flag (fmt_flag_zeropad
))
584 if (i
->test_flag (fmt_flag_plus
))
587 if (i
->test_flag (fmt_flag_space
))
590 if (i
->test_flag (fmt_flag_left
))
593 if (i
->test_flag (fmt_flag_special
))
596 if (i
->widthtype
== width_dynamic
)
598 else if (i
->widthtype
!= width_unspecified
&& i
->width
> 0)
601 if (i
->prectype
== prec_dynamic
)
603 else if (i
->prectype
!= prec_unspecified
&& i
->precision
> 0)
604 oss
<< '.' << i
->precision
;
619 if (i
->test_flag (fmt_flag_large
))
624 else if (i
->base
== 8)
626 else if (i
->test_flag (fmt_flag_sign
))
644 case conv_memory_hex
:
656 vector
<print_format::format_component
>
657 print_format::string_to_components(string
const & str
)
659 format_component curr
;
660 vector
<format_component
> res
;
664 string::const_iterator i
= str
.begin();
666 while (i
!= str
.end())
670 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
671 curr
.type
= conv_literal
;
672 curr
.literal_string
+= *i
;
676 else if (i
+1 == str
.end() || *(i
+1) == '%')
679 // *i == '%' and *(i+1) == '%'; append only one '%' to the literal string
680 assert (curr
.type
== conv_unspecified
|| curr
.type
== conv_literal
);
681 curr
.type
= conv_literal
;
682 curr
.literal_string
+= '%';
689 if (curr
.type
!= conv_unspecified
)
691 // Flush any component we were previously accumulating
692 assert (curr
.type
== conv_literal
);
702 // Now we are definitely parsing a conversion.
703 // Begin by parsing flags (which are optional).
708 curr
.set_flag (fmt_flag_zeropad
);
713 curr
.set_flag (fmt_flag_plus
);
718 curr
.set_flag (fmt_flag_left
);
723 curr
.set_flag (fmt_flag_space
);
728 curr
.set_flag (fmt_flag_special
);
739 // Parse optional width
742 curr
.widthtype
= width_dynamic
;
745 else if (isdigit(*i
))
747 curr
.widthtype
= width_static
;
752 curr
.width
+= (*i
- '0');
755 while (i
!= str
.end() && isdigit(*i
));
761 // Parse optional precision
769 curr
.prectype
= prec_dynamic
;
772 else if (isdigit(*i
))
774 curr
.prectype
= prec_static
;
778 curr
.precision
*= 10;
779 curr
.precision
+= (*i
- '0');
782 while (i
!= str
.end() && isdigit(*i
));
789 // Parse the type modifier
800 // Parse the actual conversion specifier (bcsmdioupxXn)
803 // Valid conversion types
805 curr
.type
= conv_binary
;
809 curr
.type
= conv_char
;
813 curr
.type
= conv_string
;
817 curr
.type
= conv_memory
;
821 curr
.type
= conv_memory_hex
;
826 curr
.set_flag (fmt_flag_sign
);
828 curr
.type
= conv_number
;
833 curr
.type
= conv_number
;
838 curr
.set_flag (fmt_flag_large
);
840 curr
.type
= conv_number
;
845 // Since stap 1.3, %p == %#x.
846 curr
.set_flag (fmt_flag_special
);
847 curr
.type
= conv_pointer
;
849 // Oddness for stap < 1.3 is handled in translation
856 if (curr
.type
== conv_unspecified
)
857 throw parse_error(_("invalid or missing conversion specifier"));
864 // If there's a remaining partly-composed conversion, fail.
865 if (!curr
.is_empty())
867 if (curr
.type
== conv_literal
)
870 throw parse_error(_("trailing incomplete print format conversion"));
877 void print_format::print (ostream
& o
) const
879 o
<< tok
->content
<< "(";
880 if (print_with_format
)
881 o
<< lex_cast_qstring (raw_components
);
882 if (print_with_delim
)
883 o
<< lex_cast_qstring (delimiter
.literal_string
);
886 for (vector
<expression
*>::const_iterator i
= args
.begin();
887 i
!= args
.end(); ++i
)
889 if (i
!= args
.begin() || print_with_format
|| print_with_delim
)
896 void stat_op::print (ostream
& o
) const
926 hist_op::print (ostream
& o
) const
932 assert(params
.size() == 3);
935 for (size_t i
= 0; i
< params
.size(); ++i
)
937 o
<< ", " << params
[i
];
943 assert(params
.size() == 0);
951 ostream
& operator << (ostream
& o
, const statement
& k
)
958 void embeddedcode::print (ostream
&o
) const
965 void block::print (ostream
& o
) const
968 for (unsigned i
=0; i
<statements
.size(); i
++)
969 o
<< *statements
[i
] << endl
;
973 block::block (statement
* car
, statement
* cdr
)
975 statements
.push_back(car
);
976 statements
.push_back(cdr
);
977 this->tok
= car
->tok
;
982 void try_block::print (ostream
& o
) const
984 o
<< "try {" << endl
;
985 if (try_block
) o
<< *try_block
<< endl
;
987 if (catch_error_var
) o
<< "(" << *catch_error_var
<< ") ";
989 if (catch_block
) o
<< *catch_block
<< endl
;
994 void for_loop::print (ostream
& o
) const
997 if (init
) init
->print (o
);
1001 if (incr
) incr
->print (o
);
1007 void foreach_loop::print (ostream
& o
) const
1016 for (unsigned i
=0; i
<indexes
.size(); i
++)
1018 if (i
> 0) o
<< ", ";
1019 indexes
[i
]->print (o
);
1020 if (sort_direction
!= 0 && sort_column
== i
+1)
1021 o
<< (sort_direction
> 0 ? "+" : "-");
1024 base
->print_indexable (o
);
1025 if (sort_direction
!= 0 && sort_column
== 0)
1026 o
<< (sort_direction
> 0 ? "+" : "-");
1037 void null_statement::print (ostream
& o
) const
1043 void expr_statement::print (ostream
& o
) const
1049 void return_statement::print (ostream
& o
) const
1051 o
<< "return " << *value
;
1055 void delete_statement::print (ostream
& o
) const
1057 o
<< "delete " << *value
;
1060 void next_statement::print (ostream
& o
) const
1065 void break_statement::print (ostream
& o
) const
1070 void continue_statement::print (ostream
& o
) const
1075 void if_statement::print (ostream
& o
) const
1077 o
<< "if (" << *condition
<< ") "
1078 << *thenblock
<< endl
;
1080 o
<< "else " << *elseblock
<< endl
;
1084 void stapfile::print (ostream
& o
) const
1086 o
<< "# file " << name
<< endl
;
1088 for (unsigned i
=0; i
<embeds
.size(); i
++)
1089 embeds
[i
]->print (o
);
1091 for (unsigned i
=0; i
<globals
.size(); i
++)
1094 globals
[i
]->print (o
);
1098 for (unsigned i
=0; i
<aliases
.size(); i
++)
1100 aliases
[i
]->print (o
);
1104 for (unsigned i
=0; i
<probes
.size(); i
++)
1106 probes
[i
]->print (o
);
1110 for (unsigned j
= 0; j
< functions
.size(); j
++)
1112 functions
[j
]->print (o
);
1118 void probe::print (ostream
& o
) const
1126 void probe::printsig (ostream
& o
) const
1128 const probe_alias
*alias
= get_alias ();
1131 alias
->printsig (o
);
1135 for (unsigned i
=0; i
<locations
.size(); i
++)
1137 if (i
> 0) o
<< ",";
1138 locations
[i
]->print (o
);
1144 probe::collect_derivation_chain (std::vector
<probe
*> &probes_list
)
1146 probes_list
.push_back(this);
1150 void probe_point::print (ostream
& o
, bool print_extras
) const
1152 for (unsigned i
=0; i
<components
.size(); i
++)
1155 probe_point::component
* c
= components
[i
];
1158 o
<< "(" << *c
->arg
<< ")";
1164 else if (optional
) // sufficient implies optional
1167 o
<< " if (" << *condition
<< ")";
1170 string
probe_point::str (bool print_extras
) const
1173 print(o
, print_extras
);
1178 probe_alias::probe_alias(std::vector
<probe_point
*> const & aliases
):
1179 probe (), alias_names (aliases
), epilogue_style(false)
1183 void probe_alias::printsig (ostream
& o
) const
1185 for (unsigned i
=0; i
<alias_names
.size(); i
++)
1187 o
<< (i
>0 ? " = " : "");
1188 alias_names
[i
]->print (o
);
1191 for (unsigned i
=0; i
<locations
.size(); i
++)
1193 if (i
> 0) o
<< ", ";
1194 locations
[i
]->print (o
);
1199 ostream
& operator << (ostream
& o
, const probe_point
& k
)
1206 ostream
& operator << (ostream
& o
, const symboldecl
& k
)
1214 // ------------------------------------------------------------------------
1219 block::visit (visitor
* u
)
1221 u
->visit_block (this);
1226 try_block::visit (visitor
* u
)
1228 u
->visit_try_block (this);
1233 embeddedcode::visit (visitor
* u
)
1235 u
->visit_embeddedcode (this);
1240 for_loop::visit (visitor
* u
)
1242 u
->visit_for_loop (this);
1246 foreach_loop::visit (visitor
* u
)
1248 u
->visit_foreach_loop (this);
1252 null_statement::visit (visitor
* u
)
1254 u
->visit_null_statement (this);
1258 expr_statement::visit (visitor
* u
)
1260 u
->visit_expr_statement (this);
1264 return_statement::visit (visitor
* u
)
1266 u
->visit_return_statement (this);
1270 delete_statement::visit (visitor
* u
)
1272 u
->push_active_lvalue (this->value
);
1273 u
->visit_delete_statement (this);
1274 u
->pop_active_lvalue ();
1278 if_statement::visit (visitor
* u
)
1280 u
->visit_if_statement (this);
1284 next_statement::visit (visitor
* u
)
1286 u
->visit_next_statement (this);
1290 break_statement::visit (visitor
* u
)
1292 u
->visit_break_statement (this);
1296 continue_statement::visit (visitor
* u
)
1298 u
->visit_continue_statement (this);
1302 literal_string::visit(visitor
* u
)
1304 u
->visit_literal_string (this);
1308 literal_number::visit(visitor
* u
)
1310 u
->visit_literal_number (this);
1314 binary_expression::visit (visitor
* u
)
1316 u
->visit_binary_expression (this);
1320 embedded_expr::visit (visitor
* u
)
1322 u
->visit_embedded_expr (this);
1326 unary_expression::visit (visitor
* u
)
1328 u
->visit_unary_expression (this);
1332 pre_crement::visit (visitor
* u
)
1334 u
->push_active_lvalue (this->operand
);
1335 u
->visit_pre_crement (this);
1336 u
->pop_active_lvalue ();
1340 post_crement::visit (visitor
* u
)
1342 u
->push_active_lvalue (this->operand
);
1343 u
->visit_post_crement (this);
1344 u
->pop_active_lvalue ();
1348 logical_or_expr::visit (visitor
* u
)
1350 u
->visit_logical_or_expr (this);
1354 logical_and_expr::visit (visitor
* u
)
1356 u
->visit_logical_and_expr (this);
1360 array_in::visit (visitor
* u
)
1362 u
->visit_array_in (this);
1366 comparison::visit (visitor
* u
)
1368 u
->visit_comparison (this);
1372 concatenation::visit (visitor
* u
)
1374 u
->visit_concatenation (this);
1378 ternary_expression::visit (visitor
* u
)
1380 u
->visit_ternary_expression (this);
1384 assignment::visit (visitor
* u
)
1386 u
->push_active_lvalue (this->left
);
1387 u
->visit_assignment (this);
1388 u
->pop_active_lvalue ();
1392 symbol::visit (visitor
* u
)
1394 u
->visit_symbol (this);
1398 target_symbol::visit (visitor
* u
)
1400 u
->visit_target_symbol(this);
1404 target_symbol::visit_components (visitor
* u
)
1406 for (unsigned i
= 0; i
< components
.size(); ++i
)
1407 if (components
[i
].type
== comp_expression_array_index
)
1408 components
[i
].expr_index
->visit (u
);
1412 target_symbol::visit_components (update_visitor
* u
)
1414 for (unsigned i
= 0; i
< components
.size(); ++i
)
1415 if (components
[i
].type
== comp_expression_array_index
)
1416 u
->replace (components
[i
].expr_index
);
1420 cast_op::visit (visitor
* u
)
1422 u
->visit_cast_op(this);
1427 defined_op::visit (visitor
* u
)
1429 u
->visit_defined_op(this);
1434 entry_op::visit (visitor
* u
)
1436 u
->visit_entry_op(this);
1441 arrayindex::visit (visitor
* u
)
1443 u
->visit_arrayindex (this);
1447 functioncall::visit (visitor
* u
)
1449 u
->visit_functioncall (this);
1453 print_format::visit (visitor
*u
)
1455 u
->visit_print_format (this);
1459 stat_op::visit (visitor
*u
)
1461 u
->visit_stat_op (this);
1465 hist_op::visit (visitor
*u
)
1467 u
->visit_hist_op (this);
1471 indexable::print_indexable (std::ostream
& o
) const
1474 const hist_op
*hist
;
1475 classify_const_indexable(this, sym
, hist
);
1486 indexable::visit_indexable (visitor
* u
)
1490 classify_indexable(this, sym
, hist
);
1502 indexable::is_symbol(symbol
*& sym_out
)
1509 indexable::is_hist_op(hist_op
*& hist_out
)
1516 indexable::is_const_symbol(const symbol
*& sym_out
) const
1523 indexable::is_const_hist_op(const hist_op
*& hist_out
) const
1530 symbol::is_symbol(symbol
*& sym_out
)
1537 symbol::is_const_symbol(const symbol
*& sym_out
) const
1544 symbol::get_tok() const
1550 hist_op::is_hist_op(hist_op
*& hist_out
)
1557 hist_op::is_const_hist_op(const hist_op
*& hist_out
) const
1564 hist_op::get_tok() const
1570 classify_indexable(indexable
* ix
,
1571 symbol
*& array_out
,
1572 hist_op
*& hist_out
)
1577 if (!(ix
->is_symbol (array_out
) || ix
->is_hist_op (hist_out
)))
1578 throw semantic_error(_("Expecting symbol or histogram operator"), ix
->get_tok());
1579 if (!(hist_out
|| array_out
))
1580 throw semantic_error(_("Failed to classify indexable"), ix
->get_tok());
1584 classify_const_indexable(const indexable
* ix
,
1585 const symbol
*& array_out
,
1586 const hist_op
*& hist_out
)
1590 if (!(ix
->is_const_symbol(array_out
) || ix
->is_const_hist_op(hist_out
)))
1591 throw semantic_error(_("Expecting symbol or histogram operator"), ix
->get_tok());
1594 // ------------------------------------------------------------------------
1597 visitor::is_active_lvalue(expression
*e
)
1599 for (unsigned i
= 0; i
< active_lvalues
.size(); ++i
)
1601 if (active_lvalues
[i
] == e
)
1608 visitor::push_active_lvalue(expression
*e
)
1610 active_lvalues
.push_back(e
);
1614 visitor::pop_active_lvalue()
1616 assert(!active_lvalues
.empty());
1617 active_lvalues
.pop_back();
1622 // ------------------------------------------------------------------------
1625 traversing_visitor::visit_block (block
* s
)
1627 for (unsigned i
=0; i
<s
->statements
.size(); i
++)
1628 s
->statements
[i
]->visit (this);
1632 traversing_visitor::visit_try_block (try_block
* s
)
1635 s
->try_block
->visit (this);
1636 if (s
->catch_error_var
)
1637 s
->catch_error_var
->visit (this);
1639 s
->catch_block
->visit (this);
1643 traversing_visitor::visit_embeddedcode (embeddedcode
*)
1648 traversing_visitor::visit_null_statement (null_statement
*)
1653 traversing_visitor::visit_expr_statement (expr_statement
* s
)
1655 s
->value
->visit (this);
1659 traversing_visitor::visit_if_statement (if_statement
* s
)
1661 s
->condition
->visit (this);
1662 s
->thenblock
->visit (this);
1664 s
->elseblock
->visit (this);
1668 traversing_visitor::visit_for_loop (for_loop
* s
)
1670 if (s
->init
) s
->init
->visit (this);
1671 s
->cond
->visit (this);
1672 if (s
->incr
) s
->incr
->visit (this);
1673 s
->block
->visit (this);
1677 traversing_visitor::visit_foreach_loop (foreach_loop
* s
)
1679 symbol
*array
= NULL
;
1680 hist_op
*hist
= NULL
;
1681 classify_indexable (s
->base
, array
, hist
);
1687 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
1688 s
->indexes
[i
]->visit (this);
1691 s
->value
->visit (this);
1694 s
->limit
->visit (this);
1696 s
->block
->visit (this);
1700 traversing_visitor::visit_return_statement (return_statement
* s
)
1702 s
->value
->visit (this);
1706 traversing_visitor::visit_delete_statement (delete_statement
* s
)
1708 s
->value
->visit (this);
1712 traversing_visitor::visit_next_statement (next_statement
*)
1717 traversing_visitor::visit_break_statement (break_statement
*)
1722 traversing_visitor::visit_continue_statement (continue_statement
*)
1727 traversing_visitor::visit_literal_string (literal_string
*)
1732 traversing_visitor::visit_literal_number (literal_number
*)
1737 traversing_visitor::visit_embedded_expr (embedded_expr
*)
1742 traversing_visitor::visit_binary_expression (binary_expression
* e
)
1744 e
->left
->visit (this);
1745 e
->right
->visit (this);
1749 traversing_visitor::visit_unary_expression (unary_expression
* e
)
1751 e
->operand
->visit (this);
1755 traversing_visitor::visit_pre_crement (pre_crement
* e
)
1757 e
->operand
->visit (this);
1761 traversing_visitor::visit_post_crement (post_crement
* e
)
1763 e
->operand
->visit (this);
1768 traversing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
1770 e
->left
->visit (this);
1771 e
->right
->visit (this);
1775 traversing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
1777 e
->left
->visit (this);
1778 e
->right
->visit (this);
1782 traversing_visitor::visit_array_in (array_in
* e
)
1784 e
->operand
->visit (this);
1788 traversing_visitor::visit_comparison (comparison
* e
)
1790 e
->left
->visit (this);
1791 e
->right
->visit (this);
1795 traversing_visitor::visit_concatenation (concatenation
* e
)
1797 e
->left
->visit (this);
1798 e
->right
->visit (this);
1802 traversing_visitor::visit_ternary_expression (ternary_expression
* e
)
1804 e
->cond
->visit (this);
1805 e
->truevalue
->visit (this);
1806 e
->falsevalue
->visit (this);
1810 traversing_visitor::visit_assignment (assignment
* e
)
1812 e
->left
->visit (this);
1813 e
->right
->visit (this);
1817 traversing_visitor::visit_symbol (symbol
*)
1822 traversing_visitor::visit_target_symbol (target_symbol
* e
)
1824 e
->visit_components (this);
1828 traversing_visitor::visit_cast_op (cast_op
* e
)
1830 e
->operand
->visit (this);
1831 e
->visit_components (this);
1835 traversing_visitor::visit_defined_op (defined_op
* e
)
1837 e
->operand
->visit (this);
1841 traversing_visitor::visit_entry_op (entry_op
* e
)
1843 e
->operand
->visit (this);
1848 traversing_visitor::visit_arrayindex (arrayindex
* e
)
1850 for (unsigned i
=0; i
<e
->indexes
.size(); i
++)
1851 e
->indexes
[i
]->visit (this);
1853 symbol
*array
= NULL
;
1854 hist_op
*hist
= NULL
;
1855 classify_indexable(e
->base
, array
, hist
);
1857 return array
->visit(this);
1859 return hist
->visit(this);
1863 traversing_visitor::visit_functioncall (functioncall
* e
)
1865 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1866 e
->args
[i
]->visit (this);
1870 traversing_visitor::visit_print_format (print_format
* e
)
1872 for (unsigned i
=0; i
<e
->args
.size(); i
++)
1873 e
->args
[i
]->visit (this);
1875 e
->hist
->visit(this);
1879 traversing_visitor::visit_stat_op (stat_op
* e
)
1881 e
->stat
->visit (this);
1885 traversing_visitor::visit_hist_op (hist_op
* e
)
1887 e
->stat
->visit (this);
1892 functioncall_traversing_visitor::visit_functioncall (functioncall
* e
)
1894 traversing_visitor::visit_functioncall (e
);
1896 // prevent infinite recursion
1897 if (traversed
.find (e
->referent
) == traversed
.end ())
1899 traversed
.insert (e
->referent
);
1901 functiondecl
* last_current_function
= current_function
;
1902 current_function
= e
->referent
;
1903 e
->referent
->body
->visit (this);
1904 current_function
= last_current_function
;
1910 varuse_collecting_visitor::visit_try_block (try_block
*s
)
1913 s
->try_block
->visit (this);
1914 if (s
->catch_error_var
)
1915 written
.insert (s
->catch_error_var
->referent
);
1917 s
->catch_block
->visit (this);
1919 // NB: don't functioncall_traversing_visitor::visit_try_block (s);
1920 // since that would count s->catch_error_var as a read also.
1925 varuse_collecting_visitor::visit_embeddedcode (embeddedcode
*s
)
1927 assert (current_function
); // only they get embedded code
1929 // Don't allow embedded C functions in unprivileged mode unless
1930 // they are tagged with /* unprivileged */ or /* myproc-unprivileged */
1931 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1932 ! pr_contains (session
.privilege
, pr_stapsys
) &&
1933 s
->code
.find ("/* unprivileged */") == string::npos
&&
1934 s
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1935 throw semantic_error (_F("function may not be used when --privilege=%s is specified",
1936 pr_name (session
.privilege
)),
1937 current_function
->tok
);
1939 // Don't allow /* guru */ functions unless -g is active.
1940 if (!session
.guru_mode
&& s
->code
.find ("/* guru */") != string::npos
)
1941 throw semantic_error (_("function may not be used unless -g is specified"),
1942 current_function
->tok
);
1944 // We want to elide embedded-C functions when possible. For
1945 // example, each $target variable access is expanded to an
1946 // embedded-C function call. Yet, for safety reasons, we should
1947 // presume that embedded-C functions have intentional side-effects.
1949 // To tell these two types of functions apart, we apply a
1950 // Kludge(tm): we look for a magic string within the function body.
1951 // $target variables as rvalues will have this; lvalues won't.
1952 // Also, explicit side-effect-free tapset functions will have this.
1954 if (s
->code
.find ("/* pure */") != string::npos
)
1957 embedded_seen
= true;
1961 // About the same case as above.
1963 varuse_collecting_visitor::visit_embedded_expr (embedded_expr
*e
)
1965 // Don't allow embedded C expressions in unprivileged mode unless
1966 // they are tagged with /* unprivileged */
1967 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1968 ! pr_contains (session
.privilege
, pr_stapsys
) &&
1969 e
->code
.find ("/* unprivileged */") == string::npos
&&
1970 e
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1971 throw semantic_error (_F("embedded expression may not be used when --privilege=%s is specified",
1972 pr_name (session
.privilege
)),
1975 // Don't allow /* guru */ functions unless -g is active.
1976 if (!session
.guru_mode
&& e
->code
.find ("/* guru */") != string::npos
)
1977 throw semantic_error (_("embedded expression may not be used unless -g is specified"),
1980 // We want to elide embedded-C functions when possible. For
1981 // example, each $target variable access is expanded to an
1982 // embedded-C function call. Yet, for safety reasons, we should
1983 // presume that embedded-C functions have intentional side-effects.
1985 // To tell these two types of functions apart, we apply a
1986 // Kludge(tm): we look for a magic string within the function body.
1987 // $target variables as rvalues will have this; lvalues won't.
1988 // Also, explicit side-effect-free tapset functions will have this.
1990 if (e
->code
.find ("/* pure */") != string::npos
)
1993 embedded_seen
= true;
1998 varuse_collecting_visitor::visit_target_symbol (target_symbol
*e
)
2000 // Still-unresolved target symbol assignments get treated as
2001 // generating side-effects like embedded-C, to prevent premature
2002 // elision and later error message suppression (PR5516). rvalue use
2003 // of unresolved target symbols is OTOH not considered a side-effect.
2005 if (is_active_lvalue (e
))
2006 embedded_seen
= true;
2008 functioncall_traversing_visitor::visit_target_symbol (e
);
2012 varuse_collecting_visitor::visit_cast_op (cast_op
*e
)
2014 // As with target_symbols, unresolved cast assignments need to preserved
2015 // for later error handling.
2016 if (is_active_lvalue (e
))
2017 embedded_seen
= true;
2019 functioncall_traversing_visitor::visit_cast_op (e
);
2023 varuse_collecting_visitor::visit_defined_op (defined_op
*e
)
2026 functioncall_traversing_visitor::visit_defined_op (e
);
2030 varuse_collecting_visitor::visit_entry_op (entry_op
*e
)
2033 functioncall_traversing_visitor::visit_entry_op (e
);
2038 varuse_collecting_visitor::visit_print_format (print_format
* e
)
2040 // NB: Instead of being top-level statements, "print" and "printf"
2041 // are implemented as statement-expressions containing a
2042 // print_format. They have side-effects, but not via the
2043 // embedded-code detection method above.
2045 // But sprint and sprintf don't have side-effects.
2047 bool last_lvalue_read
= current_lvalue_read
;
2048 current_lvalue_read
= true;
2049 if (e
->print_to_stream
)
2050 embedded_seen
= true; // a proxy for "has unknown side-effects"
2052 functioncall_traversing_visitor::visit_print_format (e
);
2053 current_lvalue_read
= last_lvalue_read
;
2058 varuse_collecting_visitor::visit_assignment (assignment
*e
)
2060 if (e
->op
== "=" || e
->op
== "<<<") // pure writes
2062 expression
* last_lvalue
= current_lvalue
;
2063 bool last_lvalue_read
= current_lvalue_read
;
2064 current_lvalue
= e
->left
; // leave a mark for ::visit_symbol
2065 current_lvalue_read
= true;
2066 functioncall_traversing_visitor::visit_assignment (e
);
2067 current_lvalue
= last_lvalue
;
2068 current_lvalue_read
= last_lvalue_read
;
2070 else // read-modify-writes
2072 expression
* last_lrvalue
= current_lrvalue
;
2073 current_lrvalue
= e
->left
; // leave a mark for ::visit_symbol
2074 functioncall_traversing_visitor::visit_assignment (e
);
2075 current_lrvalue
= last_lrvalue
;
2080 varuse_collecting_visitor::visit_symbol (symbol
*e
)
2082 if (e
->referent
== 0)
2083 throw semantic_error (_("symbol without referent"), e
->tok
);
2085 // We could handle initialized globals by marking them as "written".
2086 // However, this current visitor may be called for a function or
2087 // probe body, from the point of view of which this global is
2088 // already initialized, so not written.
2090 if (e->referent->init)
2091 written.insert (e->referent);
2094 if (current_lvalue
== e
|| current_lrvalue
== e
)
2096 written
.insert (e
->referent
);
2098 if (current_lvalue
!= e
|| current_lrvalue
== e
)
2100 read
.insert (e
->referent
);
2103 if (current_lrvalue
== e
)
2105 if (current_lvalue_read
)
2106 used
.insert (e
->referent
);
2108 else if (current_lvalue
!= e
)
2109 used
.insert (e
->referent
);
2112 // NB: stat_op need not be overridden, since it will get to
2113 // visit_symbol and only as a possible rvalue.
2117 varuse_collecting_visitor::visit_arrayindex (arrayindex
*e
)
2119 // Hooking this callback is necessary because of the hacky
2120 // statistics representation. For the expression "i[4] = 5", the
2121 // incoming lvalue will point to this arrayindex. However, the
2122 // symbol corresponding to the "i[4]" is multiply inherited with
2123 // arrayindex. If the symbol base part of this object is not at
2124 // offset 0, then static_cast<symbol*>(e) may result in a different
2125 // address, and not match lvalue by number when we recurse that way.
2126 // So we explicitly override the incoming lvalue/lrvalue values to
2127 // point at the embedded objects' actual base addresses.
2129 expression
* last_lrvalue
= current_lrvalue
;
2130 expression
* last_lvalue
= current_lvalue
;
2132 symbol
*array
= NULL
;
2133 hist_op
*hist
= NULL
;
2134 classify_indexable(e
->base
, array
, hist
);
2138 if (current_lrvalue
== e
) current_lrvalue
= array
;
2139 if (current_lvalue
== e
) current_lvalue
= array
;
2140 functioncall_traversing_visitor::visit_arrayindex (e
);
2144 if (current_lrvalue
== e
) current_lrvalue
= hist
->stat
;
2145 if (current_lvalue
== e
) current_lvalue
= hist
->stat
;
2146 functioncall_traversing_visitor::visit_arrayindex (e
);
2149 current_lrvalue
= last_lrvalue
;
2150 current_lvalue
= last_lvalue
;
2155 varuse_collecting_visitor::visit_pre_crement (pre_crement
*e
)
2157 expression
* last_lrvalue
= current_lrvalue
;
2158 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2159 functioncall_traversing_visitor::visit_pre_crement (e
);
2160 current_lrvalue
= last_lrvalue
;
2164 varuse_collecting_visitor::visit_post_crement (post_crement
*e
)
2166 expression
* last_lrvalue
= current_lrvalue
;
2167 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2168 functioncall_traversing_visitor::visit_post_crement (e
);
2169 current_lrvalue
= last_lrvalue
;
2173 varuse_collecting_visitor::visit_foreach_loop (foreach_loop
* s
)
2175 // NB: we duplicate so don't bother call
2176 // functioncall_traversing_visitor::visit_foreach_loop (s);
2178 symbol
*array
= NULL
;
2179 hist_op
*hist
= NULL
;
2180 classify_indexable (s
->base
, array
, hist
);
2186 // If the collection is sorted, imply a "write" access to the
2187 // array in addition to the "read" one already noted above.
2188 if (s
->sort_direction
)
2190 symbol
*array
= NULL
;
2191 hist_op
*hist
= NULL
;
2192 classify_indexable (s
->base
, array
, hist
);
2193 if (array
) this->written
.insert (array
->referent
);
2194 // XXX: Can hist_op iterations be sorted?
2197 // NB: don't forget to visit the index expressions, which are lvalues.
2198 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
2200 expression
* last_lvalue
= current_lvalue
;
2201 current_lvalue
= s
->indexes
[i
]; // leave a mark for ::visit_symbol
2202 s
->indexes
[i
]->visit (this);
2203 current_lvalue
= last_lvalue
;
2206 // The value is an lvalue too
2209 expression
* last_lvalue
= current_lvalue
;
2210 current_lvalue
= s
->value
; // leave a mark for ::visit_symbol
2211 s
->value
->visit (this);
2212 current_lvalue
= last_lvalue
;
2216 s
->limit
->visit (this);
2218 s
->block
->visit (this);
2223 varuse_collecting_visitor::visit_delete_statement (delete_statement
* s
)
2225 // Ideally, this would be treated like an assignment: a plain write
2226 // to the underlying value ("lvalue"). XXX: However, the
2227 // optimization pass is not smart enough to remove an unneeded
2228 // "delete" yet, so we pose more like a *crement ("lrvalue"). This
2229 // should protect the underlying value from optimizional mischief.
2230 expression
* last_lrvalue
= current_lrvalue
;
2231 bool last_lvalue_read
= current_lvalue_read
;
2232 current_lrvalue
= s
->value
; // leave a mark for ::visit_symbol
2233 current_lvalue_read
= true;
2234 functioncall_traversing_visitor::visit_delete_statement (s
);
2235 current_lrvalue
= last_lrvalue
;
2236 current_lvalue_read
= last_lvalue_read
;
2240 varuse_collecting_visitor::side_effect_free ()
2242 return (written
.empty() && !embedded_seen
);
2247 varuse_collecting_visitor::side_effect_free_wrt (const set
<vardecl
*>& vars
)
2249 // A looser notion of side-effect-freeness with respect to a given
2250 // list of variables.
2252 // That's useful because the written list may consist of local
2253 // variables of called functions. But visible side-effects only
2254 // occur if the client's locals, or any globals are written-to.
2256 set
<vardecl
*> intersection
;
2257 insert_iterator
<set
<vardecl
*> > int_it (intersection
, intersection
.begin());
2258 set_intersection (written
.begin(), written
.end(),
2259 vars
.begin(), vars
.end(),
2262 return (intersection
.empty() && !embedded_seen
);
2268 // ------------------------------------------------------------------------
2271 throwing_visitor::throwing_visitor (const std::string
& m
): msg (m
) {}
2272 throwing_visitor::throwing_visitor (): msg (_("invalid element")) {}
2276 throwing_visitor::throwone (const token
* t
)
2278 throw semantic_error (msg
, t
);
2282 throwing_visitor::visit_block (block
* s
)
2288 throwing_visitor::visit_try_block (try_block
* s
)
2295 throwing_visitor::visit_embeddedcode (embeddedcode
* s
)
2301 throwing_visitor::visit_null_statement (null_statement
* s
)
2307 throwing_visitor::visit_expr_statement (expr_statement
* s
)
2313 throwing_visitor::visit_if_statement (if_statement
* s
)
2319 throwing_visitor::visit_for_loop (for_loop
* s
)
2325 throwing_visitor::visit_foreach_loop (foreach_loop
* s
)
2331 throwing_visitor::visit_return_statement (return_statement
* s
)
2337 throwing_visitor::visit_delete_statement (delete_statement
* s
)
2343 throwing_visitor::visit_next_statement (next_statement
* s
)
2349 throwing_visitor::visit_break_statement (break_statement
* s
)
2355 throwing_visitor::visit_continue_statement (continue_statement
* s
)
2361 throwing_visitor::visit_literal_string (literal_string
* e
)
2367 throwing_visitor::visit_literal_number (literal_number
* e
)
2373 throwing_visitor::visit_embedded_expr (embedded_expr
* e
)
2379 throwing_visitor::visit_binary_expression (binary_expression
* e
)
2385 throwing_visitor::visit_unary_expression (unary_expression
* e
)
2391 throwing_visitor::visit_pre_crement (pre_crement
* e
)
2397 throwing_visitor::visit_post_crement (post_crement
* e
)
2404 throwing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2410 throwing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2416 throwing_visitor::visit_array_in (array_in
* e
)
2422 throwing_visitor::visit_comparison (comparison
* e
)
2428 throwing_visitor::visit_concatenation (concatenation
* e
)
2434 throwing_visitor::visit_ternary_expression (ternary_expression
* e
)
2440 throwing_visitor::visit_assignment (assignment
* e
)
2446 throwing_visitor::visit_symbol (symbol
* e
)
2452 throwing_visitor::visit_target_symbol (target_symbol
* e
)
2458 throwing_visitor::visit_cast_op (cast_op
* e
)
2464 throwing_visitor::visit_defined_op (defined_op
* e
)
2470 throwing_visitor::visit_entry_op (entry_op
* e
)
2477 throwing_visitor::visit_arrayindex (arrayindex
* e
)
2483 throwing_visitor::visit_functioncall (functioncall
* e
)
2489 throwing_visitor::visit_print_format (print_format
* e
)
2495 throwing_visitor::visit_stat_op (stat_op
* e
)
2501 throwing_visitor::visit_hist_op (hist_op
* e
)
2507 // ------------------------------------------------------------------------
2511 update_visitor::visit_block (block
* s
)
2513 for (unsigned i
= 0; i
< s
->statements
.size(); ++i
)
2514 replace (s
->statements
[i
]);
2519 update_visitor::visit_try_block (try_block
* s
)
2521 replace (s
->try_block
);
2522 replace (s
->catch_error_var
);
2523 replace (s
->catch_block
);
2528 update_visitor::visit_embeddedcode (embeddedcode
* s
)
2534 update_visitor::visit_null_statement (null_statement
* s
)
2540 update_visitor::visit_expr_statement (expr_statement
* s
)
2547 update_visitor::visit_if_statement (if_statement
* s
)
2549 replace (s
->condition
);
2550 replace (s
->thenblock
);
2551 replace (s
->elseblock
);
2556 update_visitor::visit_for_loop (for_loop
* s
)
2566 update_visitor::visit_foreach_loop (foreach_loop
* s
)
2568 for (unsigned i
= 0; i
< s
->indexes
.size(); ++i
)
2569 replace (s
->indexes
[i
]);
2578 update_visitor::visit_return_statement (return_statement
* s
)
2585 update_visitor::visit_delete_statement (delete_statement
* s
)
2592 update_visitor::visit_next_statement (next_statement
* s
)
2598 update_visitor::visit_break_statement (break_statement
* s
)
2604 update_visitor::visit_continue_statement (continue_statement
* s
)
2610 update_visitor::visit_literal_string (literal_string
* e
)
2616 update_visitor::visit_literal_number (literal_number
* e
)
2622 update_visitor::visit_embedded_expr (embedded_expr
* e
)
2628 update_visitor::visit_binary_expression (binary_expression
* e
)
2636 update_visitor::visit_unary_expression (unary_expression
* e
)
2638 replace (e
->operand
);
2643 update_visitor::visit_pre_crement (pre_crement
* e
)
2645 replace (e
->operand
);
2650 update_visitor::visit_post_crement (post_crement
* e
)
2652 replace (e
->operand
);
2658 update_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2666 update_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2674 update_visitor::visit_array_in (array_in
* e
)
2676 replace (e
->operand
);
2681 update_visitor::visit_comparison (comparison
* e
)
2689 update_visitor::visit_concatenation (concatenation
* e
)
2697 update_visitor::visit_ternary_expression (ternary_expression
* e
)
2700 replace (e
->truevalue
);
2701 replace (e
->falsevalue
);
2706 update_visitor::visit_assignment (assignment
* e
)
2714 update_visitor::visit_symbol (symbol
* e
)
2720 update_visitor::visit_target_symbol (target_symbol
* e
)
2722 e
->visit_components (this);
2727 update_visitor::visit_cast_op (cast_op
* e
)
2729 replace (e
->operand
);
2730 e
->visit_components (this);
2735 update_visitor::visit_defined_op (defined_op
* e
)
2737 replace (e
->operand
);
2742 update_visitor::visit_entry_op (entry_op
* e
)
2744 replace (e
->operand
);
2749 update_visitor::visit_arrayindex (arrayindex
* e
)
2752 for (unsigned i
= 0; i
< e
->indexes
.size(); ++i
)
2753 replace (e
->indexes
[i
]);
2758 update_visitor::visit_functioncall (functioncall
* e
)
2760 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2761 replace (e
->args
[i
]);
2766 update_visitor::visit_print_format (print_format
* e
)
2768 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2769 replace (e
->args
[i
]);
2775 update_visitor::visit_stat_op (stat_op
* e
)
2782 update_visitor::visit_hist_op (hist_op
* e
)
2788 template <> indexable
*
2789 update_visitor::require
<indexable
> (indexable
* src
, bool clearok
)
2791 indexable
*dst
= NULL
;
2794 symbol
*array_src
=NULL
;
2795 hist_op
*hist_src
=NULL
;
2797 classify_indexable(src
, array_src
, hist_src
);
2800 dst
= require (array_src
);
2802 dst
= require (hist_src
);
2803 assert(clearok
|| dst
);
2809 // ------------------------------------------------------------------------
2813 deep_copy_visitor::visit_block (block
* s
)
2815 update_visitor::visit_block(new block(*s
));
2819 deep_copy_visitor::visit_try_block (try_block
* s
)
2821 update_visitor::visit_try_block(new try_block(*s
));
2825 deep_copy_visitor::visit_embeddedcode (embeddedcode
* s
)
2827 update_visitor::visit_embeddedcode(new embeddedcode(*s
));
2831 deep_copy_visitor::visit_null_statement (null_statement
* s
)
2833 update_visitor::visit_null_statement(new null_statement(*s
));
2837 deep_copy_visitor::visit_expr_statement (expr_statement
* s
)
2839 update_visitor::visit_expr_statement(new expr_statement(*s
));
2843 deep_copy_visitor::visit_if_statement (if_statement
* s
)
2845 update_visitor::visit_if_statement(new if_statement(*s
));
2849 deep_copy_visitor::visit_for_loop (for_loop
* s
)
2851 update_visitor::visit_for_loop(new for_loop(*s
));
2855 deep_copy_visitor::visit_foreach_loop (foreach_loop
* s
)
2857 update_visitor::visit_foreach_loop(new foreach_loop(*s
));
2861 deep_copy_visitor::visit_return_statement (return_statement
* s
)
2863 update_visitor::visit_return_statement(new return_statement(*s
));
2867 deep_copy_visitor::visit_delete_statement (delete_statement
* s
)
2869 update_visitor::visit_delete_statement(new delete_statement(*s
));
2873 deep_copy_visitor::visit_next_statement (next_statement
* s
)
2875 update_visitor::visit_next_statement(new next_statement(*s
));
2879 deep_copy_visitor::visit_break_statement (break_statement
* s
)
2881 update_visitor::visit_break_statement(new break_statement(*s
));
2885 deep_copy_visitor::visit_continue_statement (continue_statement
* s
)
2887 update_visitor::visit_continue_statement(new continue_statement(*s
));
2891 deep_copy_visitor::visit_literal_string (literal_string
* e
)
2893 update_visitor::visit_literal_string(new literal_string(*e
));
2897 deep_copy_visitor::visit_literal_number (literal_number
* e
)
2899 update_visitor::visit_literal_number(new literal_number(*e
));
2903 deep_copy_visitor::visit_embedded_expr (embedded_expr
* e
)
2905 update_visitor::visit_embedded_expr(new embedded_expr(*e
));
2909 deep_copy_visitor::visit_binary_expression (binary_expression
* e
)
2911 update_visitor::visit_binary_expression(new binary_expression(*e
));
2915 deep_copy_visitor::visit_unary_expression (unary_expression
* e
)
2917 update_visitor::visit_unary_expression(new unary_expression(*e
));
2921 deep_copy_visitor::visit_pre_crement (pre_crement
* e
)
2923 update_visitor::visit_pre_crement(new pre_crement(*e
));
2927 deep_copy_visitor::visit_post_crement (post_crement
* e
)
2929 update_visitor::visit_post_crement(new post_crement(*e
));
2934 deep_copy_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2936 update_visitor::visit_logical_or_expr(new logical_or_expr(*e
));
2940 deep_copy_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2942 update_visitor::visit_logical_and_expr(new logical_and_expr(*e
));
2946 deep_copy_visitor::visit_array_in (array_in
* e
)
2948 update_visitor::visit_array_in(new array_in(*e
));
2952 deep_copy_visitor::visit_comparison (comparison
* e
)
2954 update_visitor::visit_comparison(new comparison(*e
));
2958 deep_copy_visitor::visit_concatenation (concatenation
* e
)
2960 update_visitor::visit_concatenation(new concatenation(*e
));
2964 deep_copy_visitor::visit_ternary_expression (ternary_expression
* e
)
2966 update_visitor::visit_ternary_expression(new ternary_expression(*e
));
2970 deep_copy_visitor::visit_assignment (assignment
* e
)
2972 update_visitor::visit_assignment(new assignment(*e
));
2976 deep_copy_visitor::visit_symbol (symbol
* e
)
2978 symbol
* n
= new symbol(*e
);
2979 n
->referent
= NULL
; // don't copy!
2980 update_visitor::visit_symbol(n
);
2984 deep_copy_visitor::visit_target_symbol (target_symbol
* e
)
2986 target_symbol
* n
= new target_symbol(*e
);
2987 n
->referent
= NULL
; // don't copy!
2988 update_visitor::visit_target_symbol(n
);
2992 deep_copy_visitor::visit_cast_op (cast_op
* e
)
2994 update_visitor::visit_cast_op(new cast_op(*e
));
2998 deep_copy_visitor::visit_defined_op (defined_op
* e
)
3000 update_visitor::visit_defined_op(new defined_op(*e
));
3004 deep_copy_visitor::visit_entry_op (entry_op
* e
)
3006 update_visitor::visit_entry_op(new entry_op(*e
));
3010 deep_copy_visitor::visit_arrayindex (arrayindex
* e
)
3012 update_visitor::visit_arrayindex(new arrayindex(*e
));
3016 deep_copy_visitor::visit_functioncall (functioncall
* e
)
3018 functioncall
* n
= new functioncall(*e
);
3019 n
->referent
= NULL
; // don't copy!
3020 update_visitor::visit_functioncall(n
);
3024 deep_copy_visitor::visit_print_format (print_format
* e
)
3026 update_visitor::visit_print_format(new print_format(*e
));
3030 deep_copy_visitor::visit_stat_op (stat_op
* e
)
3032 update_visitor::visit_stat_op(new stat_op(*e
));
3036 deep_copy_visitor::visit_hist_op (hist_op
* e
)
3038 update_visitor::visit_hist_op(new hist_op(*e
));
3041 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */