summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2009-08-03 15:49:40 -0700
committerJosh Stone <jistone@redhat.com>2009-08-03 15:49:40 -0700
commit8b095b454b34e88c04592be6c651153f802eced6 (patch)
tree9dd9080f259427ddad2ae70de7ba908832b4ef07
parent3a4235b9897b75a188753419a29f0616c1686249 (diff)
downloadsystemtap-steved-8b095b454b34e88c04592be6c651153f802eced6.tar.gz
systemtap-steved-8b095b454b34e88c04592be6c651153f802eced6.tar.xz
systemtap-steved-8b095b454b34e88c04592be6c651153f802eced6.zip
Add update_visitor::replace
I noticed that most uses of update_visitor::require() were simply writing the value back to the same place, i.e. foo = require(foo). The new replace() method just encapsulates that paradigm, so we don't have the duplication between the LHS and RHS. * staptree.h (update_visitor::replace): New. * elaborate.cxx, staptree.cxx, tapset-mark.cxx, tapset-perfmon.cxx, tapset-procfs.cxx, tapset-utrace.cxx, tapsets.cxx: Update all require calls that are simply updating the value in-place.
-rw-r--r--elaborate.cxx38
-rw-r--r--staptree.cxx86
-rw-r--r--staptree.h5
-rw-r--r--tapset-mark.cxx2
-rw-r--r--tapset-perfmon.cxx2
-rw-r--r--tapset-procfs.cxx2
-rw-r--r--tapset-utrace.cxx2
-rw-r--r--tapsets.cxx12
8 files changed, 77 insertions, 72 deletions
diff --git a/elaborate.cxx b/elaborate.cxx
index d1ebe326..9271e847 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -1108,7 +1108,7 @@ semantic_pass_symbols (systemtap_session& s)
try
{
for (unsigned j=0; j<s.code_filters.size(); j++)
- fd->body = s.code_filters[j]->require (fd->body);
+ s.code_filters[j]->replace (fd->body);
sym.current_function = fd;
sym.current_probe = 0;
@@ -1143,7 +1143,7 @@ semantic_pass_symbols (systemtap_session& s)
try
{
for (unsigned k=0; k<s.code_filters.size(); k++)
- dp->body = s.code_filters[k]->require (dp->body);
+ s.code_filters[k]->replace (dp->body);
sym.current_function = 0;
sym.current_probe = dp;
@@ -2136,8 +2136,8 @@ struct dead_assignment_remover: public update_visitor
void
dead_assignment_remover::visit_assignment (assignment* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
symbol* left = get_symbol_within_expression (e->left);
vardecl* leftvar = left->referent; // NB: may be 0 for unresolved $target
@@ -2203,10 +2203,10 @@ void semantic_pass_opt3 (systemtap_session& s, bool& relaxed_p)
// This instance may be reused for multiple probe/function body trims.
for (unsigned i=0; i<s.probes.size(); i++)
- s.probes[i]->body = dar.require (s.probes[i]->body);
+ dar.replace (s.probes[i]->body);
for (map<string,functiondecl*>::iterator it = s.functions.begin();
it != s.functions.end(); it++)
- it->second->body = dar.require (it->second->body);
+ dar.replace (it->second->body);
// The rewrite operation is performed within the visitor.
// XXX: we could also zap write-only globals here
@@ -2290,8 +2290,8 @@ dead_stmtexpr_remover::visit_block (block *s)
void
dead_stmtexpr_remover::visit_if_statement (if_statement *s)
{
- s->thenblock = require (s->thenblock, true);
- s->elseblock = require (s->elseblock, true);
+ replace (s->thenblock, true);
+ replace (s->elseblock, true);
if (s->thenblock == 0)
{
@@ -2343,7 +2343,7 @@ dead_stmtexpr_remover::visit_if_statement (if_statement *s)
void
dead_stmtexpr_remover::visit_foreach_loop (foreach_loop *s)
{
- s->block = require(s->block, true);
+ replace (s->block, true);
if (s->block == 0)
{
@@ -2357,7 +2357,7 @@ dead_stmtexpr_remover::visit_foreach_loop (foreach_loop *s)
void
dead_stmtexpr_remover::visit_for_loop (for_loop *s)
{
- s->block = require(s->block, true);
+ replace (s->block, true);
if (s->block == 0)
{
@@ -2446,7 +2446,7 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p)
duv.focal_vars.insert (p->locals.begin(),
p->locals.end());
- p->body = duv.require(p->body, true);
+ duv.replace (p->body, true);
if (p->body == 0)
{
if (! s.suppress_warnings
@@ -2472,7 +2472,7 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p)
duv.focal_vars.insert (s.globals.begin(),
s.globals.end());
- fn->body = duv.require(fn->body, true);
+ duv.replace (fn->body, true);
if (fn->body == 0)
{
if (! s.suppress_warnings)
@@ -2556,7 +2556,7 @@ struct void_statement_reducer: public update_visitor
void
void_statement_reducer::visit_expr_statement (expr_statement* s)
{
- s->value = require (s->value, true);
+ replace (s->value, true);
// if the expression provides 0, that's our signal that a new
// statement has been provided, so we shouldn't provide this one.
@@ -2568,8 +2568,8 @@ void
void_statement_reducer::visit_if_statement (if_statement* s)
{
// s->condition is never void
- s->thenblock = require (s->thenblock);
- s->elseblock = require (s->elseblock);
+ replace (s->thenblock);
+ replace (s->elseblock);
provide (s);
}
@@ -2577,7 +2577,7 @@ void
void_statement_reducer::visit_for_loop (for_loop* s)
{
// s->init/cond/incr are never void
- s->block = require (s->block);
+ replace (s->block);
provide (s);
}
@@ -2585,7 +2585,7 @@ void
void_statement_reducer::visit_foreach_loop (foreach_loop* s)
{
// s->indexes/base/limit are never void
- s->block = require (s->block);
+ replace (s->block);
provide (s);
}
@@ -2884,10 +2884,10 @@ void semantic_pass_opt5 (systemtap_session& s, bool& relaxed_p)
vuv.focal_vars.insert (s.globals.begin(), s.globals.end());
for (unsigned i=0; i<s.probes.size(); i++)
- s.probes[i]->body = vuv.require (s.probes[i]->body);
+ vuv.replace (s.probes[i]->body);
for (map<string,functiondecl*>::iterator it = s.functions.begin();
it != s.functions.end(); it++)
- it->second->body = vuv.require (it->second->body);
+ vuv.replace (it->second->body);
}
diff --git a/staptree.cxx b/staptree.cxx
index 11661442..8a589167 100644
--- a/staptree.cxx
+++ b/staptree.cxx
@@ -1287,7 +1287,7 @@ target_symbol::visit_components (update_visitor* u)
{
for (unsigned i = 0; i < components.size(); ++i)
if (components[i].type == comp_expression_array_index)
- components[i].expr_index = u->require (components[i].expr_index);
+ u->replace (components[i].expr_index);
}
void
@@ -2205,7 +2205,7 @@ void
update_visitor::visit_block (block* s)
{
for (unsigned i = 0; i < s->statements.size(); ++i)
- s->statements[i] = require (s->statements[i]);
+ replace (s->statements[i]);
provide (s);
}
@@ -2224,26 +2224,26 @@ update_visitor::visit_null_statement (null_statement* s)
void
update_visitor::visit_expr_statement (expr_statement* s)
{
- s->value = require (s->value);
+ replace (s->value);
provide (s);
}
void
update_visitor::visit_if_statement (if_statement* s)
{
- s->condition = require (s->condition);
- s->thenblock = require (s->thenblock);
- s->elseblock = require (s->elseblock);
+ replace (s->condition);
+ replace (s->thenblock);
+ replace (s->elseblock);
provide (s);
}
void
update_visitor::visit_for_loop (for_loop* s)
{
- s->init = require (s->init);
- s->cond = require (s->cond);
- s->incr = require (s->incr);
- s->block = require (s->block);
+ replace (s->init);
+ replace (s->cond);
+ replace (s->incr);
+ replace (s->block);
provide (s);
}
@@ -2251,24 +2251,24 @@ void
update_visitor::visit_foreach_loop (foreach_loop* s)
{
for (unsigned i = 0; i < s->indexes.size(); ++i)
- s->indexes[i] = require (s->indexes[i]);
- s->base = require (s->base);
- s->limit = require (s->limit);
- s->block = require (s->block);
+ replace (s->indexes[i]);
+ replace (s->base);
+ replace (s->limit);
+ replace (s->block);
provide (s);
}
void
update_visitor::visit_return_statement (return_statement* s)
{
- s->value = require (s->value);
+ replace (s->value);
provide (s);
}
void
update_visitor::visit_delete_statement (delete_statement* s)
{
- s->value = require (s->value);
+ replace (s->value);
provide (s);
}
@@ -2305,29 +2305,29 @@ update_visitor::visit_literal_number (literal_number* e)
void
update_visitor::visit_binary_expression (binary_expression* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
void
update_visitor::visit_unary_expression (unary_expression* e)
{
- e->operand = require (e->operand);
+ replace (e->operand);
provide (e);
}
void
update_visitor::visit_pre_crement (pre_crement* e)
{
- e->operand = require (e->operand);
+ replace (e->operand);
provide (e);
}
void
update_visitor::visit_post_crement (post_crement* e)
{
- e->operand = require (e->operand);
+ replace (e->operand);
provide (e);
}
@@ -2335,56 +2335,56 @@ update_visitor::visit_post_crement (post_crement* e)
void
update_visitor::visit_logical_or_expr (logical_or_expr* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
void
update_visitor::visit_logical_and_expr (logical_and_expr* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
void
update_visitor::visit_array_in (array_in* e)
{
- e->operand = require (e->operand);
+ replace (e->operand);
provide (e);
}
void
update_visitor::visit_comparison (comparison* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
void
update_visitor::visit_concatenation (concatenation* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
void
update_visitor::visit_ternary_expression (ternary_expression* e)
{
- e->cond = require (e->cond);
- e->truevalue = require (e->truevalue);
- e->falsevalue = require (e->falsevalue);
+ replace (e->cond);
+ replace (e->truevalue);
+ replace (e->falsevalue);
provide (e);
}
void
update_visitor::visit_assignment (assignment* e)
{
- e->left = require (e->left);
- e->right = require (e->right);
+ replace (e->left);
+ replace (e->right);
provide (e);
}
@@ -2404,7 +2404,7 @@ update_visitor::visit_target_symbol (target_symbol* e)
void
update_visitor::visit_cast_op (cast_op* e)
{
- e->operand = require (e->operand);
+ replace (e->operand);
e->visit_components (this);
provide (e);
}
@@ -2412,9 +2412,9 @@ update_visitor::visit_cast_op (cast_op* e)
void
update_visitor::visit_arrayindex (arrayindex* e)
{
- e->base = require (e->base);
+ replace (e->base);
for (unsigned i = 0; i < e->indexes.size(); ++i)
- e->indexes[i] = require (e->indexes[i]);
+ replace (e->indexes[i]);
provide (e);
}
@@ -2422,7 +2422,7 @@ void
update_visitor::visit_functioncall (functioncall* e)
{
for (unsigned i = 0; i < e->args.size(); ++i)
- e->args[i] = require (e->args[i]);
+ replace (e->args[i]);
provide (e);
}
@@ -2430,22 +2430,22 @@ void
update_visitor::visit_print_format (print_format* e)
{
for (unsigned i = 0; i < e->args.size(); ++i)
- e->args[i] = require (e->args[i]);
- e->hist = require (e->hist);
+ replace (e->args[i]);
+ replace (e->hist);
provide (e);
}
void
update_visitor::visit_stat_op (stat_op* e)
{
- e->stat = require (e->stat);
+ replace (e->stat);
provide (e);
}
void
update_visitor::visit_hist_op (hist_op* e)
{
- e->stat = require (e->stat);
+ replace (e->stat);
provide (e);
}
diff --git a/staptree.h b/staptree.h
index bc479559..c9b2bdce 100644
--- a/staptree.h
+++ b/staptree.h
@@ -874,6 +874,11 @@ struct update_visitor: public visitor
targets.push(static_cast<void*>(src));
}
+ template <typename T> void replace (T*& src, bool clearok=false)
+ {
+ src = require(src, clearok);
+ }
+
virtual ~update_visitor() { assert(targets.empty()); }
virtual void visit_block (block *s);
diff --git a/tapset-mark.cxx b/tapset-mark.cxx
index 59334729..6b4f47c5 100644
--- a/tapset-mark.cxx
+++ b/tapset-mark.cxx
@@ -223,7 +223,7 @@ mark_derived_probe::mark_derived_probe (systemtap_session &s,
// Now expand the local variables in the probe body
mark_var_expanding_visitor v (sess, name, mark_args);
- this->body = v.require (this->body);
+ v.replace (this->body);
target_symbol_seen = v.target_symbol_seen;
if (sess.verbose > 2)
diff --git a/tapset-perfmon.cxx b/tapset-perfmon.cxx
index d524aa03..86806d61 100644
--- a/tapset-perfmon.cxx
+++ b/tapset-perfmon.cxx
@@ -153,7 +153,7 @@ perfmon_derived_probe::perfmon_derived_probe (probe* p, probe_point* l,
// Now expand the local variables in the probe body
perfmon_var_expanding_visitor v (sess, probes_allocated-1);
- this->body = v.require (this->body);
+ v.replace (this->body);
if (sess.verbose > 1)
clog << "perfmon-based probe" << endl;
diff --git a/tapset-procfs.cxx b/tapset-procfs.cxx
index 3302057c..527b4486 100644
--- a/tapset-procfs.cxx
+++ b/tapset-procfs.cxx
@@ -94,7 +94,7 @@ procfs_derived_probe::procfs_derived_probe (systemtap_session &s, probe* p,
{
// Expand local variables in the probe body
procfs_var_expanding_visitor v (s, name, path, write);
- this->body = v.require (this->body);
+ v.replace (this->body);
target_symbol_seen = v.target_symbol_seen;
}
diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx
index 87053f7d..a07e08b8 100644
--- a/tapset-utrace.cxx
+++ b/tapset-utrace.cxx
@@ -120,7 +120,7 @@ utrace_derived_probe::utrace_derived_probe (systemtap_session &s,
{
// Expand local variables in the probe body
utrace_var_expanding_visitor v (s, l, name, flags);
- this->body = v.require (this->body);
+ v.replace (this->body);
target_symbol_seen = v.target_symbol_seen;
// If during target-variable-expanding the probe, we added a new block
diff --git a/tapsets.cxx b/tapsets.cxx
index ba344c51..a105526c 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -2089,7 +2089,7 @@ dwarf_var_expanding_visitor::visit_target_symbol_context (target_symbol* e)
// Ignore any variable that isn't accessible.
tsym->saved_conversion_error = 0;
expression *texp = tsym;
- texp = require (texp); // NB: throws nothing ...
+ replace (texp); // NB: throws nothing ...
if (tsym->saved_conversion_error) // ... but this is how we know it happened.
{
@@ -2133,7 +2133,7 @@ dwarf_var_expanding_visitor::visit_target_symbol_context (target_symbol* e)
// Ignore any variable that isn't accessible.
tsym->saved_conversion_error = 0;
expression *texp = tsym;
- texp = require (texp); // NB: throws nothing ...
+ replace (texp); // NB: throws nothing ...
if (tsym->saved_conversion_error) // ... but this is how we know it happened.
{
if (q.sess.verbose>2)
@@ -2664,7 +2664,7 @@ dwarf_derived_probe::dwarf_derived_probe(const string& funcname,
if (!null_die(scope_die))
{
dwarf_var_expanding_visitor v (q, scope_die, dwfl_addr);
- this->body = v.require (this->body);
+ v.replace (this->body);
this->access_vars = v.visited;
// If during target-variable-expanding the probe, we added a new block
@@ -3391,7 +3391,7 @@ sdt_query::handle_query_module()
sdt_var_expanding_visitor svv (module_val, probe_name,
probe_arg, have_reg_args,
probe_type == utrace_type);
- new_base->body = svv.require (new_base->body);
+ svv.replace (new_base->body);
unsigned i = results.size();
@@ -4148,7 +4148,7 @@ uprobe_derived_probe::uprobe_derived_probe (const string& function,
if (!null_die(scope_die))
{
dwarf_var_expanding_visitor v (q, scope_die, dwfl_addr); // XXX: user-space deref's!
- this->body = v.require (this->body);
+ v.replace (this->body);
// If during target-variable-expanding the probe, we added a new block
// of code, add it to the start of the probe.
@@ -5538,7 +5538,7 @@ tracepoint_derived_probe::tracepoint_derived_probe (systemtap_session& s,
// Now expand the local variables in the probe body
tracepoint_var_expanding_visitor v (dw, name, args);
- this->body = v.require (this->body);
+ v.replace (this->body);
if (sess.verbose > 2)
clog << "tracepoint-based " << name << " tracepoint='" << tracepoint_name