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 s
->code
.find ("/* unprivileged */") == string::npos
&&
1933 s
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1934 throw semantic_error (_F("function may not be used when --privilege=%s is specified",
1935 pr_name (session
.privilege
)),
1936 current_function
->tok
);
1938 // Don't allow /* guru */ functions unless -g is active.
1939 if (!session
.guru_mode
&& s
->code
.find ("/* guru */") != string::npos
)
1940 throw semantic_error (_("function may not be used unless -g is specified"),
1941 current_function
->tok
);
1943 // We want to elide embedded-C functions when possible. For
1944 // example, each $target variable access is expanded to an
1945 // embedded-C function call. Yet, for safety reasons, we should
1946 // presume that embedded-C functions have intentional side-effects.
1948 // To tell these two types of functions apart, we apply a
1949 // Kludge(tm): we look for a magic string within the function body.
1950 // $target variables as rvalues will have this; lvalues won't.
1951 // Also, explicit side-effect-free tapset functions will have this.
1953 if (s
->code
.find ("/* pure */") != string::npos
)
1956 embedded_seen
= true;
1960 // About the same case as above.
1962 varuse_collecting_visitor::visit_embedded_expr (embedded_expr
*e
)
1964 // Don't allow embedded C functions in unprivileged mode unless
1965 // they are tagged with /* unprivileged */
1966 if (! pr_contains (session
.privilege
, pr_stapdev
) &&
1967 e
->code
.find ("/* unprivileged */") == string::npos
&&
1968 e
->code
.find ("/* myproc-unprivileged */") == string::npos
)
1969 throw semantic_error (_F("embedded expression may not be used when --privilege=%s is specified",
1970 pr_name (session
.privilege
)),
1973 // Don't allow /* guru */ functions unless -g is active.
1974 if (!session
.guru_mode
&& e
->code
.find ("/* guru */") != string::npos
)
1975 throw semantic_error (_("embedded expression may not be used unless -g is specified"),
1978 // We want to elide embedded-C functions when possible. For
1979 // example, each $target variable access is expanded to an
1980 // embedded-C function call. Yet, for safety reasons, we should
1981 // presume that embedded-C functions have intentional side-effects.
1983 // To tell these two types of functions apart, we apply a
1984 // Kludge(tm): we look for a magic string within the function body.
1985 // $target variables as rvalues will have this; lvalues won't.
1986 // Also, explicit side-effect-free tapset functions will have this.
1988 if (e
->code
.find ("/* pure */") != string::npos
)
1991 embedded_seen
= true;
1996 varuse_collecting_visitor::visit_target_symbol (target_symbol
*e
)
1998 // Still-unresolved target symbol assignments get treated as
1999 // generating side-effects like embedded-C, to prevent premature
2000 // elision and later error message suppression (PR5516). rvalue use
2001 // of unresolved target symbols is OTOH not considered a side-effect.
2003 if (is_active_lvalue (e
))
2004 embedded_seen
= true;
2006 functioncall_traversing_visitor::visit_target_symbol (e
);
2010 varuse_collecting_visitor::visit_cast_op (cast_op
*e
)
2012 // As with target_symbols, unresolved cast assignments need to preserved
2013 // for later error handling.
2014 if (is_active_lvalue (e
))
2015 embedded_seen
= true;
2017 functioncall_traversing_visitor::visit_cast_op (e
);
2021 varuse_collecting_visitor::visit_defined_op (defined_op
*e
)
2024 functioncall_traversing_visitor::visit_defined_op (e
);
2028 varuse_collecting_visitor::visit_entry_op (entry_op
*e
)
2031 functioncall_traversing_visitor::visit_entry_op (e
);
2036 varuse_collecting_visitor::visit_print_format (print_format
* e
)
2038 // NB: Instead of being top-level statements, "print" and "printf"
2039 // are implemented as statement-expressions containing a
2040 // print_format. They have side-effects, but not via the
2041 // embedded-code detection method above.
2043 // But sprint and sprintf don't have side-effects.
2045 bool last_lvalue_read
= current_lvalue_read
;
2046 current_lvalue_read
= true;
2047 if (e
->print_to_stream
)
2048 embedded_seen
= true; // a proxy for "has unknown side-effects"
2050 functioncall_traversing_visitor::visit_print_format (e
);
2051 current_lvalue_read
= last_lvalue_read
;
2056 varuse_collecting_visitor::visit_assignment (assignment
*e
)
2058 if (e
->op
== "=" || e
->op
== "<<<") // pure writes
2060 expression
* last_lvalue
= current_lvalue
;
2061 bool last_lvalue_read
= current_lvalue_read
;
2062 current_lvalue
= e
->left
; // leave a mark for ::visit_symbol
2063 current_lvalue_read
= true;
2064 functioncall_traversing_visitor::visit_assignment (e
);
2065 current_lvalue
= last_lvalue
;
2066 current_lvalue_read
= last_lvalue_read
;
2068 else // read-modify-writes
2070 expression
* last_lrvalue
= current_lrvalue
;
2071 current_lrvalue
= e
->left
; // leave a mark for ::visit_symbol
2072 functioncall_traversing_visitor::visit_assignment (e
);
2073 current_lrvalue
= last_lrvalue
;
2078 varuse_collecting_visitor::visit_symbol (symbol
*e
)
2080 if (e
->referent
== 0)
2081 throw semantic_error (_("symbol without referent"), e
->tok
);
2083 // We could handle initialized globals by marking them as "written".
2084 // However, this current visitor may be called for a function or
2085 // probe body, from the point of view of which this global is
2086 // already initialized, so not written.
2088 if (e->referent->init)
2089 written.insert (e->referent);
2092 if (current_lvalue
== e
|| current_lrvalue
== e
)
2094 written
.insert (e
->referent
);
2096 if (current_lvalue
!= e
|| current_lrvalue
== e
)
2098 read
.insert (e
->referent
);
2101 if (current_lrvalue
== e
)
2103 if (current_lvalue_read
)
2104 used
.insert (e
->referent
);
2106 else if (current_lvalue
!= e
)
2107 used
.insert (e
->referent
);
2110 // NB: stat_op need not be overridden, since it will get to
2111 // visit_symbol and only as a possible rvalue.
2115 varuse_collecting_visitor::visit_arrayindex (arrayindex
*e
)
2117 // Hooking this callback is necessary because of the hacky
2118 // statistics representation. For the expression "i[4] = 5", the
2119 // incoming lvalue will point to this arrayindex. However, the
2120 // symbol corresponding to the "i[4]" is multiply inherited with
2121 // arrayindex. If the symbol base part of this object is not at
2122 // offset 0, then static_cast<symbol*>(e) may result in a different
2123 // address, and not match lvalue by number when we recurse that way.
2124 // So we explicitly override the incoming lvalue/lrvalue values to
2125 // point at the embedded objects' actual base addresses.
2127 expression
* last_lrvalue
= current_lrvalue
;
2128 expression
* last_lvalue
= current_lvalue
;
2130 symbol
*array
= NULL
;
2131 hist_op
*hist
= NULL
;
2132 classify_indexable(e
->base
, array
, hist
);
2136 if (current_lrvalue
== e
) current_lrvalue
= array
;
2137 if (current_lvalue
== e
) current_lvalue
= array
;
2138 functioncall_traversing_visitor::visit_arrayindex (e
);
2142 if (current_lrvalue
== e
) current_lrvalue
= hist
->stat
;
2143 if (current_lvalue
== e
) current_lvalue
= hist
->stat
;
2144 functioncall_traversing_visitor::visit_arrayindex (e
);
2147 current_lrvalue
= last_lrvalue
;
2148 current_lvalue
= last_lvalue
;
2153 varuse_collecting_visitor::visit_pre_crement (pre_crement
*e
)
2155 expression
* last_lrvalue
= current_lrvalue
;
2156 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2157 functioncall_traversing_visitor::visit_pre_crement (e
);
2158 current_lrvalue
= last_lrvalue
;
2162 varuse_collecting_visitor::visit_post_crement (post_crement
*e
)
2164 expression
* last_lrvalue
= current_lrvalue
;
2165 current_lrvalue
= e
->operand
; // leave a mark for ::visit_symbol
2166 functioncall_traversing_visitor::visit_post_crement (e
);
2167 current_lrvalue
= last_lrvalue
;
2171 varuse_collecting_visitor::visit_foreach_loop (foreach_loop
* s
)
2173 // NB: we duplicate so don't bother call
2174 // functioncall_traversing_visitor::visit_foreach_loop (s);
2176 symbol
*array
= NULL
;
2177 hist_op
*hist
= NULL
;
2178 classify_indexable (s
->base
, array
, hist
);
2184 // If the collection is sorted, imply a "write" access to the
2185 // array in addition to the "read" one already noted above.
2186 if (s
->sort_direction
)
2188 symbol
*array
= NULL
;
2189 hist_op
*hist
= NULL
;
2190 classify_indexable (s
->base
, array
, hist
);
2191 if (array
) this->written
.insert (array
->referent
);
2192 // XXX: Can hist_op iterations be sorted?
2195 // NB: don't forget to visit the index expressions, which are lvalues.
2196 for (unsigned i
=0; i
<s
->indexes
.size(); i
++)
2198 expression
* last_lvalue
= current_lvalue
;
2199 current_lvalue
= s
->indexes
[i
]; // leave a mark for ::visit_symbol
2200 s
->indexes
[i
]->visit (this);
2201 current_lvalue
= last_lvalue
;
2204 // The value is an lvalue too
2207 expression
* last_lvalue
= current_lvalue
;
2208 current_lvalue
= s
->value
; // leave a mark for ::visit_symbol
2209 s
->value
->visit (this);
2210 current_lvalue
= last_lvalue
;
2214 s
->limit
->visit (this);
2216 s
->block
->visit (this);
2221 varuse_collecting_visitor::visit_delete_statement (delete_statement
* s
)
2223 // Ideally, this would be treated like an assignment: a plain write
2224 // to the underlying value ("lvalue"). XXX: However, the
2225 // optimization pass is not smart enough to remove an unneeded
2226 // "delete" yet, so we pose more like a *crement ("lrvalue"). This
2227 // should protect the underlying value from optimizional mischief.
2228 expression
* last_lrvalue
= current_lrvalue
;
2229 bool last_lvalue_read
= current_lvalue_read
;
2230 current_lrvalue
= s
->value
; // leave a mark for ::visit_symbol
2231 current_lvalue_read
= true;
2232 functioncall_traversing_visitor::visit_delete_statement (s
);
2233 current_lrvalue
= last_lrvalue
;
2234 current_lvalue_read
= last_lvalue_read
;
2238 varuse_collecting_visitor::side_effect_free ()
2240 return (written
.empty() && !embedded_seen
);
2245 varuse_collecting_visitor::side_effect_free_wrt (const set
<vardecl
*>& vars
)
2247 // A looser notion of side-effect-freeness with respect to a given
2248 // list of variables.
2250 // That's useful because the written list may consist of local
2251 // variables of called functions. But visible side-effects only
2252 // occur if the client's locals, or any globals are written-to.
2254 set
<vardecl
*> intersection
;
2255 insert_iterator
<set
<vardecl
*> > int_it (intersection
, intersection
.begin());
2256 set_intersection (written
.begin(), written
.end(),
2257 vars
.begin(), vars
.end(),
2260 return (intersection
.empty() && !embedded_seen
);
2266 // ------------------------------------------------------------------------
2269 throwing_visitor::throwing_visitor (const std::string
& m
): msg (m
) {}
2270 throwing_visitor::throwing_visitor (): msg (_("invalid element")) {}
2274 throwing_visitor::throwone (const token
* t
)
2276 throw semantic_error (msg
, t
);
2280 throwing_visitor::visit_block (block
* s
)
2286 throwing_visitor::visit_try_block (try_block
* s
)
2293 throwing_visitor::visit_embeddedcode (embeddedcode
* s
)
2299 throwing_visitor::visit_null_statement (null_statement
* s
)
2305 throwing_visitor::visit_expr_statement (expr_statement
* s
)
2311 throwing_visitor::visit_if_statement (if_statement
* s
)
2317 throwing_visitor::visit_for_loop (for_loop
* s
)
2323 throwing_visitor::visit_foreach_loop (foreach_loop
* s
)
2329 throwing_visitor::visit_return_statement (return_statement
* s
)
2335 throwing_visitor::visit_delete_statement (delete_statement
* s
)
2341 throwing_visitor::visit_next_statement (next_statement
* s
)
2347 throwing_visitor::visit_break_statement (break_statement
* s
)
2353 throwing_visitor::visit_continue_statement (continue_statement
* s
)
2359 throwing_visitor::visit_literal_string (literal_string
* e
)
2365 throwing_visitor::visit_literal_number (literal_number
* e
)
2371 throwing_visitor::visit_embedded_expr (embedded_expr
* e
)
2377 throwing_visitor::visit_binary_expression (binary_expression
* e
)
2383 throwing_visitor::visit_unary_expression (unary_expression
* e
)
2389 throwing_visitor::visit_pre_crement (pre_crement
* e
)
2395 throwing_visitor::visit_post_crement (post_crement
* e
)
2402 throwing_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2408 throwing_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2414 throwing_visitor::visit_array_in (array_in
* e
)
2420 throwing_visitor::visit_comparison (comparison
* e
)
2426 throwing_visitor::visit_concatenation (concatenation
* e
)
2432 throwing_visitor::visit_ternary_expression (ternary_expression
* e
)
2438 throwing_visitor::visit_assignment (assignment
* e
)
2444 throwing_visitor::visit_symbol (symbol
* e
)
2450 throwing_visitor::visit_target_symbol (target_symbol
* e
)
2456 throwing_visitor::visit_cast_op (cast_op
* e
)
2462 throwing_visitor::visit_defined_op (defined_op
* e
)
2468 throwing_visitor::visit_entry_op (entry_op
* e
)
2475 throwing_visitor::visit_arrayindex (arrayindex
* e
)
2481 throwing_visitor::visit_functioncall (functioncall
* e
)
2487 throwing_visitor::visit_print_format (print_format
* e
)
2493 throwing_visitor::visit_stat_op (stat_op
* e
)
2499 throwing_visitor::visit_hist_op (hist_op
* e
)
2505 // ------------------------------------------------------------------------
2509 update_visitor::visit_block (block
* s
)
2511 for (unsigned i
= 0; i
< s
->statements
.size(); ++i
)
2512 replace (s
->statements
[i
]);
2517 update_visitor::visit_try_block (try_block
* s
)
2519 replace (s
->try_block
);
2520 replace (s
->catch_error_var
);
2521 replace (s
->catch_block
);
2526 update_visitor::visit_embeddedcode (embeddedcode
* s
)
2532 update_visitor::visit_null_statement (null_statement
* s
)
2538 update_visitor::visit_expr_statement (expr_statement
* s
)
2545 update_visitor::visit_if_statement (if_statement
* s
)
2547 replace (s
->condition
);
2548 replace (s
->thenblock
);
2549 replace (s
->elseblock
);
2554 update_visitor::visit_for_loop (for_loop
* s
)
2564 update_visitor::visit_foreach_loop (foreach_loop
* s
)
2566 for (unsigned i
= 0; i
< s
->indexes
.size(); ++i
)
2567 replace (s
->indexes
[i
]);
2576 update_visitor::visit_return_statement (return_statement
* s
)
2583 update_visitor::visit_delete_statement (delete_statement
* s
)
2590 update_visitor::visit_next_statement (next_statement
* s
)
2596 update_visitor::visit_break_statement (break_statement
* s
)
2602 update_visitor::visit_continue_statement (continue_statement
* s
)
2608 update_visitor::visit_literal_string (literal_string
* e
)
2614 update_visitor::visit_literal_number (literal_number
* e
)
2620 update_visitor::visit_embedded_expr (embedded_expr
* e
)
2626 update_visitor::visit_binary_expression (binary_expression
* e
)
2634 update_visitor::visit_unary_expression (unary_expression
* e
)
2636 replace (e
->operand
);
2641 update_visitor::visit_pre_crement (pre_crement
* e
)
2643 replace (e
->operand
);
2648 update_visitor::visit_post_crement (post_crement
* e
)
2650 replace (e
->operand
);
2656 update_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2664 update_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2672 update_visitor::visit_array_in (array_in
* e
)
2674 replace (e
->operand
);
2679 update_visitor::visit_comparison (comparison
* e
)
2687 update_visitor::visit_concatenation (concatenation
* e
)
2695 update_visitor::visit_ternary_expression (ternary_expression
* e
)
2698 replace (e
->truevalue
);
2699 replace (e
->falsevalue
);
2704 update_visitor::visit_assignment (assignment
* e
)
2712 update_visitor::visit_symbol (symbol
* e
)
2718 update_visitor::visit_target_symbol (target_symbol
* e
)
2720 e
->visit_components (this);
2725 update_visitor::visit_cast_op (cast_op
* e
)
2727 replace (e
->operand
);
2728 e
->visit_components (this);
2733 update_visitor::visit_defined_op (defined_op
* e
)
2735 replace (e
->operand
);
2740 update_visitor::visit_entry_op (entry_op
* e
)
2742 replace (e
->operand
);
2747 update_visitor::visit_arrayindex (arrayindex
* e
)
2750 for (unsigned i
= 0; i
< e
->indexes
.size(); ++i
)
2751 replace (e
->indexes
[i
]);
2756 update_visitor::visit_functioncall (functioncall
* e
)
2758 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2759 replace (e
->args
[i
]);
2764 update_visitor::visit_print_format (print_format
* e
)
2766 for (unsigned i
= 0; i
< e
->args
.size(); ++i
)
2767 replace (e
->args
[i
]);
2773 update_visitor::visit_stat_op (stat_op
* e
)
2780 update_visitor::visit_hist_op (hist_op
* e
)
2786 template <> indexable
*
2787 update_visitor::require
<indexable
> (indexable
* src
, bool clearok
)
2789 indexable
*dst
= NULL
;
2792 symbol
*array_src
=NULL
;
2793 hist_op
*hist_src
=NULL
;
2795 classify_indexable(src
, array_src
, hist_src
);
2798 dst
= require (array_src
);
2800 dst
= require (hist_src
);
2801 assert(clearok
|| dst
);
2807 // ------------------------------------------------------------------------
2811 deep_copy_visitor::visit_block (block
* s
)
2813 update_visitor::visit_block(new block(*s
));
2817 deep_copy_visitor::visit_try_block (try_block
* s
)
2819 update_visitor::visit_try_block(new try_block(*s
));
2823 deep_copy_visitor::visit_embeddedcode (embeddedcode
* s
)
2825 update_visitor::visit_embeddedcode(new embeddedcode(*s
));
2829 deep_copy_visitor::visit_null_statement (null_statement
* s
)
2831 update_visitor::visit_null_statement(new null_statement(*s
));
2835 deep_copy_visitor::visit_expr_statement (expr_statement
* s
)
2837 update_visitor::visit_expr_statement(new expr_statement(*s
));
2841 deep_copy_visitor::visit_if_statement (if_statement
* s
)
2843 update_visitor::visit_if_statement(new if_statement(*s
));
2847 deep_copy_visitor::visit_for_loop (for_loop
* s
)
2849 update_visitor::visit_for_loop(new for_loop(*s
));
2853 deep_copy_visitor::visit_foreach_loop (foreach_loop
* s
)
2855 update_visitor::visit_foreach_loop(new foreach_loop(*s
));
2859 deep_copy_visitor::visit_return_statement (return_statement
* s
)
2861 update_visitor::visit_return_statement(new return_statement(*s
));
2865 deep_copy_visitor::visit_delete_statement (delete_statement
* s
)
2867 update_visitor::visit_delete_statement(new delete_statement(*s
));
2871 deep_copy_visitor::visit_next_statement (next_statement
* s
)
2873 update_visitor::visit_next_statement(new next_statement(*s
));
2877 deep_copy_visitor::visit_break_statement (break_statement
* s
)
2879 update_visitor::visit_break_statement(new break_statement(*s
));
2883 deep_copy_visitor::visit_continue_statement (continue_statement
* s
)
2885 update_visitor::visit_continue_statement(new continue_statement(*s
));
2889 deep_copy_visitor::visit_literal_string (literal_string
* e
)
2891 update_visitor::visit_literal_string(new literal_string(*e
));
2895 deep_copy_visitor::visit_literal_number (literal_number
* e
)
2897 update_visitor::visit_literal_number(new literal_number(*e
));
2901 deep_copy_visitor::visit_embedded_expr (embedded_expr
* e
)
2903 update_visitor::visit_embedded_expr(new embedded_expr(*e
));
2907 deep_copy_visitor::visit_binary_expression (binary_expression
* e
)
2909 update_visitor::visit_binary_expression(new binary_expression(*e
));
2913 deep_copy_visitor::visit_unary_expression (unary_expression
* e
)
2915 update_visitor::visit_unary_expression(new unary_expression(*e
));
2919 deep_copy_visitor::visit_pre_crement (pre_crement
* e
)
2921 update_visitor::visit_pre_crement(new pre_crement(*e
));
2925 deep_copy_visitor::visit_post_crement (post_crement
* e
)
2927 update_visitor::visit_post_crement(new post_crement(*e
));
2932 deep_copy_visitor::visit_logical_or_expr (logical_or_expr
* e
)
2934 update_visitor::visit_logical_or_expr(new logical_or_expr(*e
));
2938 deep_copy_visitor::visit_logical_and_expr (logical_and_expr
* e
)
2940 update_visitor::visit_logical_and_expr(new logical_and_expr(*e
));
2944 deep_copy_visitor::visit_array_in (array_in
* e
)
2946 update_visitor::visit_array_in(new array_in(*e
));
2950 deep_copy_visitor::visit_comparison (comparison
* e
)
2952 update_visitor::visit_comparison(new comparison(*e
));
2956 deep_copy_visitor::visit_concatenation (concatenation
* e
)
2958 update_visitor::visit_concatenation(new concatenation(*e
));
2962 deep_copy_visitor::visit_ternary_expression (ternary_expression
* e
)
2964 update_visitor::visit_ternary_expression(new ternary_expression(*e
));
2968 deep_copy_visitor::visit_assignment (assignment
* e
)
2970 update_visitor::visit_assignment(new assignment(*e
));
2974 deep_copy_visitor::visit_symbol (symbol
* e
)
2976 symbol
* n
= new symbol(*e
);
2977 n
->referent
= NULL
; // don't copy!
2978 update_visitor::visit_symbol(n
);
2982 deep_copy_visitor::visit_target_symbol (target_symbol
* e
)
2984 target_symbol
* n
= new target_symbol(*e
);
2985 n
->referent
= NULL
; // don't copy!
2986 update_visitor::visit_target_symbol(n
);
2990 deep_copy_visitor::visit_cast_op (cast_op
* e
)
2992 update_visitor::visit_cast_op(new cast_op(*e
));
2996 deep_copy_visitor::visit_defined_op (defined_op
* e
)
2998 update_visitor::visit_defined_op(new defined_op(*e
));
3002 deep_copy_visitor::visit_entry_op (entry_op
* e
)
3004 update_visitor::visit_entry_op(new entry_op(*e
));
3008 deep_copy_visitor::visit_arrayindex (arrayindex
* e
)
3010 update_visitor::visit_arrayindex(new arrayindex(*e
));
3014 deep_copy_visitor::visit_functioncall (functioncall
* e
)
3016 functioncall
* n
= new functioncall(*e
);
3017 n
->referent
= NULL
; // don't copy!
3018 update_visitor::visit_functioncall(n
);
3022 deep_copy_visitor::visit_print_format (print_format
* e
)
3024 update_visitor::visit_print_format(new print_format(*e
));
3028 deep_copy_visitor::visit_stat_op (stat_op
* e
)
3030 update_visitor::visit_stat_op(new stat_op(*e
));
3034 deep_copy_visitor::visit_hist_op (hist_op
* e
)
3036 update_visitor::visit_hist_op(new hist_op(*e
));
3039 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */