diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | staptree.cxx | 217 | ||||
-rw-r--r-- | staptree.h | 54 | ||||
-rw-r--r-- | tapsets.cxx | 52 |
4 files changed, 144 insertions, 186 deletions
@@ -1,3 +1,10 @@ +2009-02-05 Josh Stone <jistone@redhat.com> + + * staptree.h (require, provide): Simplify stack operations with less + pointer magic, and move to be deep_copy_visitor members. + * staptree.h (deep_copy_visitor::deep_copy): Templatize + * staptree.cxx, tapsets.cxx: Refactor require/provide callers + 2009-02-04 Mark Wielaard <mjw@redhat.com> * NEWS: process().mark(), sys/sdt.h and dtrace compatibility script. diff --git a/staptree.cxx b/staptree.cxx index cc618111..869af80a 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -2103,12 +2103,8 @@ deep_copy_visitor::visit_block (block* s) block* n = new block; n->tok = s->tok; for (unsigned i = 0; i < s->statements.size(); ++i) - { - statement* ns; - require <statement*> (this, &ns, s->statements[i]); - n->statements.push_back(ns); - } - provide <block*> (this, n); + n->statements.push_back(require (s->statements[i])); + provide (n); } void @@ -2117,7 +2113,7 @@ deep_copy_visitor::visit_embeddedcode (embeddedcode* s) embeddedcode* n = new embeddedcode; n->tok = s->tok; n->code = s->code; - provide <embeddedcode*> (this, n); + provide (n); } void @@ -2125,7 +2121,7 @@ deep_copy_visitor::visit_null_statement (null_statement* s) { null_statement* n = new null_statement; n->tok = s->tok; - provide <null_statement*> (this, n); + provide (n); } void @@ -2133,8 +2129,8 @@ deep_copy_visitor::visit_expr_statement (expr_statement* s) { expr_statement* n = new expr_statement; n->tok = s->tok; - require <expression*> (this, &(n->value), s->value); - provide <expr_statement*> (this, n); + n->value = require (s->value); + provide (n); } void @@ -2142,10 +2138,10 @@ deep_copy_visitor::visit_if_statement (if_statement* s) { if_statement* n = new if_statement; n->tok = s->tok; - require <expression*> (this, &(n->condition), s->condition); - require <statement*> (this, &(n->thenblock), s->thenblock); - require <statement*> (this, &(n->elseblock), s->elseblock); - provide <if_statement*> (this, n); + n->condition = require (s->condition); + n->thenblock = require (s->thenblock); + n->elseblock = require (s->elseblock); + provide (n); } void @@ -2153,11 +2149,11 @@ deep_copy_visitor::visit_for_loop (for_loop* s) { for_loop* n = new for_loop; n->tok = s->tok; - require <expr_statement*> (this, &(n->init), s->init); - require <expression*> (this, &(n->cond), s->cond); - require <expr_statement*> (this, &(n->incr), s->incr); - require <statement*> (this, &(n->block), s->block); - provide <for_loop*> (this, n); + n->init = require (s->init); + n->cond = require (s->cond); + n->incr = require (s->incr); + n->block = require (s->block); + provide (n); } void @@ -2166,20 +2162,16 @@ deep_copy_visitor::visit_foreach_loop (foreach_loop* s) foreach_loop* n = new foreach_loop; n->tok = s->tok; for (unsigned i = 0; i < s->indexes.size(); ++i) - { - symbol* sym; - require <symbol*> (this, &sym, s->indexes[i]); - n->indexes.push_back(sym); - } + n->indexes.push_back(require (s->indexes[i])); - require <indexable*> (this, &(n->base), s->base); + n->base = require (s->base); n->sort_direction = s->sort_direction; n->sort_column = s->sort_column; - require <expression*> (this, &(n->limit), s->limit); + n->limit = require (s->limit); - require <statement*> (this, &(n->block), s->block); - provide <foreach_loop*> (this, n); + n->block = require (s->block); + provide (n); } void @@ -2187,8 +2179,8 @@ deep_copy_visitor::visit_return_statement (return_statement* s) { return_statement* n = new return_statement; n->tok = s->tok; - require <expression*> (this, &(n->value), s->value); - provide <return_statement*> (this, n); + n->value = require (s->value); + provide (n); } void @@ -2196,8 +2188,8 @@ deep_copy_visitor::visit_delete_statement (delete_statement* s) { delete_statement* n = new delete_statement; n->tok = s->tok; - require <expression*> (this, &(n->value), s->value); - provide <delete_statement*> (this, n); + n->value = require (s->value); + provide (n); } void @@ -2205,7 +2197,7 @@ deep_copy_visitor::visit_next_statement (next_statement* s) { next_statement* n = new next_statement; n->tok = s->tok; - provide <next_statement*> (this, n); + provide (n); } void @@ -2213,7 +2205,7 @@ deep_copy_visitor::visit_break_statement (break_statement* s) { break_statement* n = new break_statement; n->tok = s->tok; - provide <break_statement*> (this, n); + provide (n); } void @@ -2221,7 +2213,7 @@ deep_copy_visitor::visit_continue_statement (continue_statement* s) { continue_statement* n = new continue_statement; n->tok = s->tok; - provide <continue_statement*> (this, n); + provide (n); } void @@ -2229,7 +2221,7 @@ deep_copy_visitor::visit_literal_string (literal_string* e) { literal_string* n = new literal_string(e->value); n->tok = e->tok; - provide <literal_string*> (this, n); + provide (n); } void @@ -2237,7 +2229,7 @@ deep_copy_visitor::visit_literal_number (literal_number* e) { literal_number* n = new literal_number(e->value); n->tok = e->tok; - provide <literal_number*> (this, n); + provide (n); } void @@ -2246,9 +2238,9 @@ deep_copy_visitor::visit_binary_expression (binary_expression* e) binary_expression* n = new binary_expression; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <binary_expression*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2257,8 +2249,8 @@ deep_copy_visitor::visit_unary_expression (unary_expression* e) unary_expression* n = new unary_expression; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->operand), e->operand); - provide <unary_expression*> (this, n); + n->operand = require (e->operand); + provide (n); } void @@ -2267,8 +2259,8 @@ deep_copy_visitor::visit_pre_crement (pre_crement* e) pre_crement* n = new pre_crement; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->operand), e->operand); - provide <pre_crement*> (this, n); + n->operand = require (e->operand); + provide (n); } void @@ -2277,8 +2269,8 @@ deep_copy_visitor::visit_post_crement (post_crement* e) post_crement* n = new post_crement; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->operand), e->operand); - provide <post_crement*> (this, n); + n->operand = require (e->operand); + provide (n); } @@ -2288,9 +2280,9 @@ deep_copy_visitor::visit_logical_or_expr (logical_or_expr* e) logical_or_expr* n = new logical_or_expr; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <logical_or_expr*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2299,9 +2291,9 @@ deep_copy_visitor::visit_logical_and_expr (logical_and_expr* e) logical_and_expr* n = new logical_and_expr; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <logical_and_expr*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2309,8 +2301,8 @@ deep_copy_visitor::visit_array_in (array_in* e) { array_in* n = new array_in; n->tok = e->tok; - require <arrayindex*> (this, &(n->operand), e->operand); - provide <array_in*> (this, n); + n->operand = require (e->operand); + provide (n); } void @@ -2319,9 +2311,9 @@ deep_copy_visitor::visit_comparison (comparison* e) comparison* n = new comparison; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <comparison*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2330,9 +2322,9 @@ deep_copy_visitor::visit_concatenation (concatenation* e) concatenation* n = new concatenation; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <concatenation*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2340,10 +2332,10 @@ deep_copy_visitor::visit_ternary_expression (ternary_expression* e) { ternary_expression* n = new ternary_expression; n->tok = e->tok; - require <expression*> (this, &(n->cond), e->cond); - require <expression*> (this, &(n->truevalue), e->truevalue); - require <expression*> (this, &(n->falsevalue), e->falsevalue); - provide <ternary_expression*> (this, n); + n->cond = require (e->cond); + n->truevalue = require (e->truevalue); + n->falsevalue = require (e->falsevalue); + provide (n); } void @@ -2352,9 +2344,9 @@ deep_copy_visitor::visit_assignment (assignment* e) assignment* n = new assignment; n->op = e->op; n->tok = e->tok; - require <expression*> (this, &(n->left), e->left); - require <expression*> (this, &(n->right), e->right); - provide <assignment*> (this, n); + n->left = require (e->left); + n->right = require (e->right); + provide (n); } void @@ -2364,7 +2356,7 @@ deep_copy_visitor::visit_symbol (symbol* e) n->tok = e->tok; n->name = e->name; n->referent = NULL; - provide <symbol*> (this, n); + provide (n); } void @@ -2374,7 +2366,7 @@ deep_copy_visitor::visit_target_symbol (target_symbol* e) n->tok = e->tok; n->base_name = e->base_name; n->components = e->components; - provide <target_symbol*> (this, n); + provide (n); } void @@ -2383,15 +2375,11 @@ deep_copy_visitor::visit_arrayindex (arrayindex* e) arrayindex* n = new arrayindex; n->tok = e->tok; - require <indexable*> (this, &(n->base), e->base); + n->base = require (e->base); for (unsigned i = 0; i < e->indexes.size(); ++i) - { - expression* ne; - require <expression*> (this, &ne, e->indexes[i]); - n->indexes.push_back(ne); - } - provide <arrayindex*> (this, n); + n->indexes.push_back(require (e->indexes[i])); + provide (n); } void @@ -2402,12 +2390,8 @@ deep_copy_visitor::visit_functioncall (functioncall* e) n->function = e->function; n->referent = NULL; for (unsigned i = 0; i < e->args.size(); ++i) - { - expression* na; - require <expression*> (this, &na, e->args[i]); - n->args.push_back(na); - } - provide <functioncall*> (this, n); + n->args.push_back(require (e->args[i])); + provide (n); } void @@ -2424,14 +2408,10 @@ deep_copy_visitor::visit_print_format (print_format* e) n->components = e->components; n->delimiter = e->delimiter; for (unsigned i = 0; i < e->args.size(); ++i) - { - expression* na; - require <expression*> (this, &na, e->args[i]); - n->args.push_back(na); - } + n->args.push_back(require (e->args[i])); if (e->hist) - require <hist_op*> (this, &n->hist, e->hist); - provide <print_format*> (this, n); + n->hist = require (e->hist); + provide (n); } void @@ -2440,8 +2420,8 @@ deep_copy_visitor::visit_stat_op (stat_op* e) stat_op* n = new stat_op; n->tok = e->tok; n->ctype = e->ctype; - require <expression*> (this, &(n->stat), e->stat); - provide <stat_op*> (this, n); + n->stat = require (e->stat); + provide (n); } void @@ -2451,61 +2431,28 @@ deep_copy_visitor::visit_hist_op (hist_op* e) n->tok = e->tok; n->htype = e->htype; n->params = e->params; - require <expression*> (this, &(n->stat), e->stat); - provide <hist_op*> (this, n); -} - -block* -deep_copy_visitor::deep_copy (block* b) -{ - block* n; - deep_copy_visitor v; - require <block*> (&v, &n, b); - return n; -} - -statement* -deep_copy_visitor::deep_copy (statement* s) -{ - statement* n; - deep_copy_visitor v; - require <statement*> (&v, &n, s); - return n; -} - -expression* -deep_copy_visitor::deep_copy (expression* s) -{ - expression* n; - deep_copy_visitor v; - require <expression*> (&v, &n, s); - return n; + n->stat = require (e->stat); + provide (n); } -template <> void -require <indexable *> (deep_copy_visitor* v, indexable** dst, indexable* src) +template <> indexable* +deep_copy_visitor::require <indexable*> (indexable* src) { + indexable *dst = NULL; if (src != NULL) { - symbol *array_src=NULL, *array_dst=NULL; - hist_op *hist_src=NULL, *hist_dst=NULL; + symbol *array_src=NULL; + hist_op *hist_src=NULL; classify_indexable(src, array_src, hist_src); - *dst = NULL; - if (array_src) - { - require <symbol*> (v, &array_dst, array_src); - *dst = array_dst; - } + dst = require (array_src); else - { - require <hist_op*> (v, &hist_dst, hist_src); - *dst = hist_dst; - } - assert (*dst); + dst = require (hist_src); + assert (dst); } + return dst; } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ @@ -818,11 +818,30 @@ struct throwing_visitor: public visitor struct deep_copy_visitor: public visitor { - std::stack<void *> targets; + template <typename T> T require (T src) + { + T dst = NULL; + if (src != NULL) + { + src->visit(this); + assert(!targets.empty()); + dst = static_cast<T>(targets.top()); + targets.pop(); + assert(dst); + } + return dst; + } + + template <typename T> void provide (T src) + { + targets.push(static_cast<void*>(src)); + } - static expression *deep_copy (expression *s); - static statement *deep_copy (statement *s); - static block *deep_copy (block *s); + template <typename T> static T deep_copy (T e) + { + deep_copy_visitor v; + return v.require (e); + } virtual void visit_block (block *s); virtual void visit_embeddedcode (embeddedcode *s); @@ -856,30 +875,13 @@ struct deep_copy_visitor: public visitor virtual void visit_print_format (print_format* e); virtual void visit_stat_op (stat_op* e); virtual void visit_hist_op (hist_op* e); -}; -template <typename T> void -require (deep_copy_visitor* v, T* dst, T src) -{ - *dst = NULL; - if (src != NULL) - { - v->targets.push(static_cast<void* >(dst)); - src->visit(v); - v->targets.pop(); - assert(*dst); - } -} - -template <> void -require <indexable *> (deep_copy_visitor* v, indexable** dst, indexable* src); +private: + std::stack<void *> targets; +}; -template <typename T> void -provide (deep_copy_visitor* v, T src) -{ - assert(!v->targets.empty()); - *(static_cast<T*>(v->targets.top())) = src; -} +template <> indexable* +deep_copy_visitor::require <indexable*> (indexable* src); #endif // STAPTREE_H diff --git a/tapsets.cxx b/tapsets.cxx index c8742fbd..90b5c24f 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -4253,9 +4253,9 @@ var_expanding_copy_visitor::visit_assignment (assignment* e) expression *new_left, *new_right; target_symbol_setter_functioncalls.push (&fcall); - require<expression*> (this, &new_left, e->left); + new_left = require (e->left); target_symbol_setter_functioncalls.pop (); - require<expression*> (this, &new_right, e->right); + new_right = require (e->right); if (fcall != NULL) { @@ -4274,7 +4274,7 @@ var_expanding_copy_visitor::visit_assignment (assignment* e) assert (new_left == fcall); fcall->args.push_back (new_right); - provide <expression*> (this, fcall); + provide (fcall); } else { @@ -4283,7 +4283,7 @@ var_expanding_copy_visitor::visit_assignment (assignment* e) n->tok = e->tok; n->left = new_left; n->right = new_right; - provide <assignment*> (this, n); + provide (n); } } @@ -4318,7 +4318,7 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) map<string, symbol *>::iterator i = return_ts_map.find(ts_name); if (i != return_ts_map.end()) { - provide <symbol*> (this, i->second); + provide (i->second); return; } @@ -4576,7 +4576,7 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) // (4) Provide the '_dwarf_tvar_{name}_{num}_tmp' variable to // our parent so it can be used as a substitute for the target // symbol. - provide <symbol*> (this, tmpsym); + provide (tmpsym); // (5) Remember this replacement since we might be able to reuse // it later if the same return probe references this target @@ -4622,7 +4622,8 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) // Ignore any variable that isn't accessible. tsym->saved_conversion_error = 0; - this->visit_target_symbol(tsym); // NB: throws nothing ... + expression *texp = tsym; + texp = require (texp); // NB: throws nothing ... if (tsym->saved_conversion_error) // ... but this is how we know it happened. { @@ -4631,7 +4632,7 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) { pf->raw_components += "return"; pf->raw_components += "=%#x "; - pf->args.push_back(*(expression**)this->targets.top()); + pf->args.push_back(texp); } } else @@ -4665,7 +4666,8 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) // Ignore any variable that isn't accessible. tsym->saved_conversion_error = 0; - this->visit_target_symbol(tsym); // NB: throws nothing ... + expression *texp = tsym; + texp = require (texp); // NB: throws nothing ... if (tsym->saved_conversion_error) // ... but this is how we know it happened. { if (q.sess.verbose>2) @@ -4684,14 +4686,14 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) { pf->raw_components += diename; pf->raw_components += "=%#x "; - pf->args.push_back(*(expression**)this->targets.top()); + pf->args.push_back(texp); } } while (dwarf_siblingof (&result, &result) == 0); } pf->components = print_format::string_to_components(pf->raw_components); - provide <print_format*> (this, pf); + provide (pf); return; } @@ -4735,7 +4737,7 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) // target_symbol to the next pass. We hope that this value ends // up not being referenced after all, so it can be optimized out // quietly. - provide <target_symbol*> (this, e); + provide (e); semantic_error* saveme = new semantic_error (er); // copy it saveme->tok1 = e->tok; // XXX: token not passed to q.dw code generation routines // NB: we can have multiple errors, since a $target variable @@ -4783,7 +4785,7 @@ dwarf_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) *(target_symbol_setter_functioncalls.top()) = n; } - provide <functioncall*> (this, n); + provide (n); } @@ -4856,7 +4858,7 @@ dwarf_derived_probe::dwarf_derived_probe(const string& funcname, if (!null_die(scope_die)) { dwarf_var_expanding_copy_visitor v (q, scope_die, dwfl_addr); - require <statement*> (&v, &(this->body), this->body); + this->body = v.require (this->body); this->access_vars = v.visited; // If during target-variable-expanding the probe, we added a new block @@ -6268,7 +6270,7 @@ utrace_derived_probe::utrace_derived_probe (systemtap_session &s, { // Make a local-variable-expanded copy of the probe body utrace_var_expanding_copy_visitor v (s, name, flags); - require <statement*> (&v, &(this->body), base->body); + this->body = v.require (base->body); target_symbol_seen = v.target_symbol_seen; // Reset the sole element of the "locations" vector as a @@ -6379,7 +6381,7 @@ utrace_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) num->tok = e->tok; n->args.push_back(num); - provide <functioncall*> (this, n); + provide (n); } void @@ -6430,7 +6432,7 @@ utrace_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session - provide <functioncall*> (this, n); + provide (n); } void @@ -6998,7 +7000,7 @@ uprobe_derived_probe::uprobe_derived_probe (const string& function, if (!null_die(scope_die)) { dwarf_var_expanding_copy_visitor v (q, scope_die, dwfl_addr); // XXX: user-space deref's! - require <statement*> (&v, &(this->body), this->body); + this->body = v.require (this->body); // If during target-variable-expanding the probe, we added a new block // of code, add it to the start of the probe. @@ -7802,7 +7804,7 @@ procfs_derived_probe::procfs_derived_probe (systemtap_session &s, probe* p, { // Make a local-variable-expanded copy of the probe body procfs_var_expanding_copy_visitor v (s, name, path, write); - require <statement*> (&v, &(this->body), base->body); + this->body = v.require (base->body); target_symbol_seen = v.target_symbol_seen; } @@ -8136,7 +8138,7 @@ procfs_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) *(target_symbol_setter_functioncalls.top()) = n; } - provide <functioncall*> (this, n); + provide (n); } @@ -8371,7 +8373,7 @@ mark_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) n->tok = e->tok; n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session - provide <functioncall*> (this, n); + provide (n); } @@ -8413,7 +8415,7 @@ mark_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e) n->tok = e->tok; n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session - provide <functioncall*> (this, n); + provide (n); } void @@ -8452,7 +8454,7 @@ mark_derived_probe::mark_derived_probe (systemtap_session &s, // Now make a local-variable-expanded copy of the probe body mark_var_expanding_copy_visitor v (sess, name, mark_args); - require <statement*> (&v, &(this->body), base->body); + this->body = v.require (base->body); target_symbol_seen = v.target_symbol_seen; if (sess.verbose > 2) @@ -9285,7 +9287,7 @@ perfmon_var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session - provide <functioncall*> (this, n); + provide (n); } @@ -9355,7 +9357,7 @@ perfmon_derived_probe::perfmon_derived_probe (probe* p, probe_point* l, // Now make a local-variable-expanded copy of the probe body perfmon_var_expanding_copy_visitor v (sess, probes_allocated-1); - require <statement*> (&v, &(this->body), base->body); + this->body = v.require (base->body); if (sess.verbose > 1) clog << "perfmon-based probe" << endl; |