diff options
author | Josh Stone <jistone@redhat.com> | 2009-07-31 17:24:13 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2009-07-31 17:34:42 -0700 |
commit | dc5a09fc9a61c8b33078164b6855dea54a33627c (patch) | |
tree | a1877ba1c9b69a0cb189ce97092888c84ca6e0ab | |
parent | c67847a0d05f8c7207513e79378fc8d84563e109 (diff) | |
download | systemtap-steved-dc5a09fc9a61c8b33078164b6855dea54a33627c.tar.gz systemtap-steved-dc5a09fc9a61c8b33078164b6855dea54a33627c.tar.xz systemtap-steved-dc5a09fc9a61c8b33078164b6855dea54a33627c.zip |
Unify no-component assertions on target variables
There are several tapsets that can't deal with component dereferences on
their target variables, and they all check-and-throw in the same way.
This refactors the checks into a target_symbol member.
* staptree.cxx (target_symbol::assert_no_components): New.
* tapsets.cxx (tracepoint_var_expanding_visitor::visit_target_symbol_arg,
tracepoint_var_expanding_visitor::visit_target_symbol_context): Use
the new assertion function to check for no components.
* tapset-mark.cxx (mark_var_expanding_visitor::visit_target_symbol_arg,
mark_var_expanding_visitor::visit_target_symbol_context): Ditto.
* tapset-perfmon.cxx (perfmon_var_expanding_visitor::visit_target_symbol): Ditto.
* tapset-procfs.cxx (procfs_var_expanding_visitor::visit_target_symbol): Ditto.
* tapset-utrace.cxx (utrace_var_expanding_visitor::visit_target_symbol_arg,
utrace_var_expanding_visitor::visit_target_symbol_context): Ditto.
-rw-r--r-- | staptree.cxx | 24 | ||||
-rw-r--r-- | staptree.h | 1 | ||||
-rw-r--r-- | tapset-mark.cxx | 36 | ||||
-rw-r--r-- | tapset-perfmon.cxx | 19 | ||||
-rw-r--r-- | tapset-procfs.cxx | 19 | ||||
-rw-r--r-- | tapset-utrace.cxx | 38 | ||||
-rw-r--r-- | tapsets.cxx | 28 |
7 files changed, 34 insertions, 131 deletions
diff --git a/staptree.cxx b/staptree.cxx index 1231f74d..321650eb 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -186,6 +186,30 @@ operator << (ostream& o, const exp_type& e) } +void +target_symbol::assert_no_components(const std::string& tapset) +{ + if (components.empty()) + return; + + switch (components[0].type) + { + case target_symbol::comp_literal_array_index: + throw semantic_error(tapset + " variable '" + base_name + + "' may not be used as array", + components[0].tok); + case target_symbol::comp_struct_member: + throw semantic_error(tapset + " variable '" + base_name + + "' may not be used as a structure", + components[0].tok); + default: + throw semantic_error ("invalid use of " + tapset + + " variable '" + base_name + "'", + components[0].tok); + } +} + + // ------------------------------------------------------------------------ // parse tree printing @@ -252,6 +252,7 @@ struct target_symbol: public symbol target_symbol(): addressof(false), saved_conversion_error (0) {} void print (std::ostream& o) const; void visit (visitor* u); + void assert_no_components(const std::string& tapset); }; std::ostream& operator << (std::ostream& o, const target_symbol::component& c); diff --git a/tapset-mark.cxx b/tapset-mark.cxx index fcde9ed5..59334729 100644 --- a/tapset-mark.cxx +++ b/tapset-mark.cxx @@ -103,23 +103,7 @@ mark_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e) if (is_active_lvalue (e)) throw semantic_error("write to marker parameter not permitted", e->tok); - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("marker argument may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("marker argument may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid marker argument use", e->tok); - break; - } - } + e->assert_no_components("marker"); // Remember that we've seen a target variable. target_symbol_seen = true; @@ -138,23 +122,7 @@ mark_var_expanding_visitor::visit_target_symbol_context (target_symbol* e) if (is_active_lvalue (e)) throw semantic_error("write to marker '" + sname + "' not permitted", e->tok); - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("marker '" + sname + "' may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("marker '" + sname + "' may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid marker '" + sname + "' use", e->tok); - break; - } - } + e->assert_no_components("marker"); if (e->base_name == "$format" || e->base_name == "$name") { string fname; diff --git a/tapset-perfmon.cxx b/tapset-perfmon.cxx index dfdc55e6..d524aa03 100644 --- a/tapset-perfmon.cxx +++ b/tapset-perfmon.cxx @@ -67,24 +67,7 @@ perfmon_var_expanding_visitor::visit_target_symbol (target_symbol *e) if (e->addressof) throw semantic_error("cannot take address of perfmon variable", e->tok); - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("perfmon probe '$counter' variable may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("perfmon probe '$counter' variable may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid use of perfmon probe '$counter' variable", - e->tok); - break; - } - } + e->assert_no_components("perfmon"); ec->code = "THIS->__retvalue = _pfm_pmd_x[" + lex_cast<string>(counter_number) + "].reg_num;"; diff --git a/tapset-procfs.cxx b/tapset-procfs.cxx index 58bb0f0d..3302057c 100644 --- a/tapset-procfs.cxx +++ b/tapset-procfs.cxx @@ -358,24 +358,7 @@ procfs_var_expanding_visitor::visit_target_symbol (target_symbol* e) throw semantic_error ("invalid target symbol for procfs probe, $value expected", e->tok); - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("procfs target variable '$value' may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("procfs target variable '$value' may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid use of procfs target variable '$value'", - e->tok); - break; - } - } + e->assert_no_components("procfs"); bool lvalue = is_active_lvalue(e); if (write_probe && lvalue) diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx index 3befcbd5..87053f7d 100644 --- a/tapset-utrace.cxx +++ b/tapset-utrace.cxx @@ -455,24 +455,7 @@ utrace_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e) string argnum_s = e->base_name.substr(4,e->base_name.length()-4); int argnum = lex_cast<int>(argnum_s); - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("utrace target variable '$argN' may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("utrace target variable '$argN' may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid use of utrace target variable '$argN'", - e->tok); - break; - } - } + e->assert_no_components("utrace"); // FIXME: max argnument number should not be hardcoded. if (argnum < 1 || argnum > 6) @@ -505,24 +488,7 @@ utrace_var_expanding_visitor::visit_target_symbol_context (target_symbol* e) { string sname = e->base_name; - if (e->components.size() > 0) - { - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("utrace target variable '" + sname + "' may not be used as array", - e->tok); - break; - case target_symbol::comp_struct_member: - throw semantic_error("utrace target variable '" + sname + "' may not be used as a structure", - e->tok); - break; - default: - throw semantic_error ("invalid use of utrace target variable '" + sname + "'", - e->tok); - break; - } - } + e->assert_no_components("utrace"); bool lvalue = is_active_lvalue(e); if (lvalue) diff --git a/tapsets.cxx b/tapsets.cxx index 70edc7d8..537c33e7 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -5261,19 +5261,8 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e) } // make sure we're not dereferencing base types - if (!e->components.empty() && !arg->isptr) - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("tracepoint variable '" + e->base_name - + "' may not be used as array", e->tok); - case target_symbol::comp_struct_member: - throw semantic_error("tracepoint variable '" + e->base_name - + "' may not be used as a structure", e->tok); - default: - throw semantic_error("invalid use of tracepoint variable '" - + e->base_name + "'", e->tok); - } + if (!arg->isptr) + e->assert_no_components("tracepoint"); // we can only write to dereferenced fields, and only if guru mode is on bool lvalue = is_active_lvalue(e); @@ -5393,18 +5382,7 @@ tracepoint_var_expanding_visitor::visit_target_symbol_context (target_symbol* e) if (is_active_lvalue (e)) throw semantic_error("write to tracepoint '" + e->base_name + "' not permitted", e->tok); - if (!e->components.empty()) - switch (e->components[0].type) - { - case target_symbol::comp_literal_array_index: - throw semantic_error("tracepoint '" + e->base_name + "' may not be used as array", - e->tok); - case target_symbol::comp_struct_member: - throw semantic_error("tracepoint '" + e->base_name + "' may not be used as a structure", - e->tok); - default: - throw semantic_error("invalid tracepoint '" + e->base_name + "' use", e->tok); - } + e->assert_no_components("tracepoint"); if (e->base_name == "$$name") { |