From 73267b89ea6ede28b1a0a10667774bca6eb2b37e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 28 Jan 2009 17:01:20 -0800 Subject: Add Vim modelines for GNU style in stap --- staptree.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index fafefc4e..cc618111 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -2508,3 +2508,4 @@ require (deep_copy_visitor* v, indexable** dst, indexable* src) } } +/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit From 4ed05b152284d9d4b8545f6e70c57ebdcd993f46 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 5 Feb 2009 13:08:44 -0800 Subject: Simplify require() and provide() * 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 --- staptree.cxx | 217 ++++++++++++++++++++++------------------------------------- 1 file changed, 82 insertions(+), 135 deletions(-) (limited to 'staptree.cxx') 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 (this, &ns, s->statements[i]); - n->statements.push_back(ns); - } - provide (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 (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 (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 (this, &(n->value), s->value); - provide (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 (this, &(n->condition), s->condition); - require (this, &(n->thenblock), s->thenblock); - require (this, &(n->elseblock), s->elseblock); - provide (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 (this, &(n->init), s->init); - require (this, &(n->cond), s->cond); - require (this, &(n->incr), s->incr); - require (this, &(n->block), s->block); - provide (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 (this, &sym, s->indexes[i]); - n->indexes.push_back(sym); - } + n->indexes.push_back(require (s->indexes[i])); - require (this, &(n->base), s->base); + n->base = require (s->base); n->sort_direction = s->sort_direction; n->sort_column = s->sort_column; - require (this, &(n->limit), s->limit); + n->limit = require (s->limit); - require (this, &(n->block), s->block); - provide (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 (this, &(n->value), s->value); - provide (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 (this, &(n->value), s->value); - provide (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 (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 (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 (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 (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 (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (this, &(n->operand), e->operand); - provide (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 (this, &(n->operand), e->operand); - provide (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 (this, &(n->operand), e->operand); - provide (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (this, &(n->operand), e->operand); - provide (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (this, &(n->cond), e->cond); - require (this, &(n->truevalue), e->truevalue); - require (this, &(n->falsevalue), e->falsevalue); - provide (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 (this, &(n->left), e->left); - require (this, &(n->right), e->right); - provide (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 (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 (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 (this, &(n->base), e->base); + n->base = require (e->base); for (unsigned i = 0; i < e->indexes.size(); ++i) - { - expression* ne; - require (this, &ne, e->indexes[i]); - n->indexes.push_back(ne); - } - provide (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 (this, &na, e->args[i]); - n->args.push_back(na); - } - provide (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 (this, &na, e->args[i]); - n->args.push_back(na); - } + n->args.push_back(require (e->args[i])); if (e->hist) - require (this, &n->hist, e->hist); - provide (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 (this, &(n->stat), e->stat); - provide (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 (this, &(n->stat), e->stat); - provide (this, n); -} - -block* -deep_copy_visitor::deep_copy (block* b) -{ - block* n; - deep_copy_visitor v; - require (&v, &n, b); - return n; -} - -statement* -deep_copy_visitor::deep_copy (statement* s) -{ - statement* n; - deep_copy_visitor v; - require (&v, &n, s); - return n; -} - -expression* -deep_copy_visitor::deep_copy (expression* s) -{ - expression* n; - deep_copy_visitor v; - require (&v, &n, s); - return n; + n->stat = require (e->stat); + provide (n); } -template <> void -require (deep_copy_visitor* v, indexable** dst, indexable* src) +template <> indexable* +deep_copy_visitor::require (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 (v, &array_dst, array_src); - *dst = array_dst; - } + dst = require (array_src); else - { - require (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 : */ -- cgit From 4b6455e82679becf3ad12e4f12abb70de1ee271d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 5 Feb 2009 20:02:35 -0800 Subject: Create update_visitor for modifying trees * staptree.h (update_visitor): A new visitor to make it easier to rewrite parts of a probe or function without making a full copy. * staptree.cxx (update_visitor::*): Each child is recursed with a require() call, and then the parent returns itself with provide(). * staptree.h (deep_copy_visitor): Inherit from update_visitor to get the recursive descent while updating nodes. * staptree.cxx (deep_copy_visitor::*): Use the implicit copy constructors to copy all fields, then defer to update_visitor for the recursion. Referents are still cleared from the copies of symbols and function calls. --- staptree.cxx | 498 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 301 insertions(+), 197 deletions(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 869af80a..2b963bc3 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -2098,361 +2098,465 @@ throwing_visitor::visit_hist_op (hist_op* e) void -deep_copy_visitor::visit_block (block* s) +update_visitor::visit_block (block* s) { - block* n = new block; - n->tok = s->tok; for (unsigned i = 0; i < s->statements.size(); ++i) - n->statements.push_back(require (s->statements[i])); - provide (n); + s->statements[i] = require (s->statements[i]); + provide (s); +} + +void +update_visitor::visit_embeddedcode (embeddedcode* s) +{ + provide (s); +} + +void +update_visitor::visit_null_statement (null_statement* s) +{ + provide (s); +} + +void +update_visitor::visit_expr_statement (expr_statement* s) +{ + s->value = require (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); + 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); + provide (s); +} + +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); + provide (s); +} + +void +update_visitor::visit_return_statement (return_statement* s) +{ + s->value = require (s->value); + provide (s); +} + +void +update_visitor::visit_delete_statement (delete_statement* s) +{ + s->value = require (s->value); + provide (s); +} + +void +update_visitor::visit_next_statement (next_statement* s) +{ + provide (s); +} + +void +update_visitor::visit_break_statement (break_statement* s) +{ + provide (s); +} + +void +update_visitor::visit_continue_statement (continue_statement* s) +{ + provide (s); +} + +void +update_visitor::visit_literal_string (literal_string* e) +{ + provide (e); +} + +void +update_visitor::visit_literal_number (literal_number* e) +{ + provide (e); +} + +void +update_visitor::visit_binary_expression (binary_expression* e) +{ + e->left = require (e->left); + e->right = require (e->right); + provide (e); +} + +void +update_visitor::visit_unary_expression (unary_expression* e) +{ + e->operand = require (e->operand); + provide (e); +} + +void +update_visitor::visit_pre_crement (pre_crement* e) +{ + e->operand = require (e->operand); + provide (e); +} + +void +update_visitor::visit_post_crement (post_crement* e) +{ + e->operand = require (e->operand); + provide (e); +} + + +void +update_visitor::visit_logical_or_expr (logical_or_expr* e) +{ + e->left = require (e->left); + e->right = require (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); + provide (e); +} + +void +update_visitor::visit_array_in (array_in* e) +{ + e->operand = require (e->operand); + provide (e); +} + +void +update_visitor::visit_comparison (comparison* e) +{ + e->left = require (e->left); + e->right = require (e->right); + provide (e); +} + +void +update_visitor::visit_concatenation (concatenation* e) +{ + e->left = require (e->left); + e->right = require (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); + provide (e); +} + +void +update_visitor::visit_assignment (assignment* e) +{ + e->left = require (e->left); + e->right = require (e->right); + provide (e); +} + +void +update_visitor::visit_symbol (symbol* e) +{ + provide (e); +} + +void +update_visitor::visit_target_symbol (target_symbol* e) +{ + provide (e); +} + +void +update_visitor::visit_arrayindex (arrayindex* e) +{ + e->base = require (e->base); + for (unsigned i = 0; i < e->indexes.size(); ++i) + e->indexes[i] = require (e->indexes[i]); + provide (e); +} + +void +update_visitor::visit_functioncall (functioncall* e) +{ + for (unsigned i = 0; i < e->args.size(); ++i) + e->args[i] = require (e->args[i]); + provide (e); +} + +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); + provide (e); +} + +void +update_visitor::visit_stat_op (stat_op* e) +{ + e->stat = require (e->stat); + provide (e); +} + +void +update_visitor::visit_hist_op (hist_op* e) +{ + e->stat = require (e->stat); + provide (e); +} + +template <> indexable* +update_visitor::require (indexable* src) +{ + indexable *dst = NULL; + if (src != NULL) + { + symbol *array_src=NULL; + hist_op *hist_src=NULL; + + classify_indexable(src, array_src, hist_src); + + if (array_src) + dst = require (array_src); + else + dst = require (hist_src); + assert (dst); + } + return dst; +} + + +// ------------------------------------------------------------------------ + + +void +deep_copy_visitor::visit_block (block* s) +{ + update_visitor::visit_block(new block(*s)); } void deep_copy_visitor::visit_embeddedcode (embeddedcode* s) { - embeddedcode* n = new embeddedcode; - n->tok = s->tok; - n->code = s->code; - provide (n); + update_visitor::visit_embeddedcode(new embeddedcode(*s)); } void deep_copy_visitor::visit_null_statement (null_statement* s) { - null_statement* n = new null_statement; - n->tok = s->tok; - provide (n); + update_visitor::visit_null_statement(new null_statement(*s)); } void deep_copy_visitor::visit_expr_statement (expr_statement* s) { - expr_statement* n = new expr_statement; - n->tok = s->tok; - n->value = require (s->value); - provide (n); + update_visitor::visit_expr_statement(new expr_statement(*s)); } void deep_copy_visitor::visit_if_statement (if_statement* s) { - if_statement* n = new if_statement; - n->tok = s->tok; - n->condition = require (s->condition); - n->thenblock = require (s->thenblock); - n->elseblock = require (s->elseblock); - provide (n); + update_visitor::visit_if_statement(new if_statement(*s)); } void deep_copy_visitor::visit_for_loop (for_loop* s) { - for_loop* n = new for_loop; - n->tok = s->tok; - n->init = require (s->init); - n->cond = require (s->cond); - n->incr = require (s->incr); - n->block = require (s->block); - provide (n); + update_visitor::visit_for_loop(new for_loop(*s)); } void 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) - n->indexes.push_back(require (s->indexes[i])); - - n->base = require (s->base); - - n->sort_direction = s->sort_direction; - n->sort_column = s->sort_column; - n->limit = require (s->limit); - - n->block = require (s->block); - provide (n); + update_visitor::visit_foreach_loop(new foreach_loop(*s)); } void deep_copy_visitor::visit_return_statement (return_statement* s) { - return_statement* n = new return_statement; - n->tok = s->tok; - n->value = require (s->value); - provide (n); + update_visitor::visit_return_statement(new return_statement(*s)); } void deep_copy_visitor::visit_delete_statement (delete_statement* s) { - delete_statement* n = new delete_statement; - n->tok = s->tok; - n->value = require (s->value); - provide (n); + update_visitor::visit_delete_statement(new delete_statement(*s)); } void deep_copy_visitor::visit_next_statement (next_statement* s) { - next_statement* n = new next_statement; - n->tok = s->tok; - provide (n); + update_visitor::visit_next_statement(new next_statement(*s)); } void deep_copy_visitor::visit_break_statement (break_statement* s) { - break_statement* n = new break_statement; - n->tok = s->tok; - provide (n); + update_visitor::visit_break_statement(new break_statement(*s)); } void deep_copy_visitor::visit_continue_statement (continue_statement* s) { - continue_statement* n = new continue_statement; - n->tok = s->tok; - provide (n); + update_visitor::visit_continue_statement(new continue_statement(*s)); } void deep_copy_visitor::visit_literal_string (literal_string* e) { - literal_string* n = new literal_string(e->value); - n->tok = e->tok; - provide (n); + update_visitor::visit_literal_string(new literal_string(*e)); } void deep_copy_visitor::visit_literal_number (literal_number* e) { - literal_number* n = new literal_number(e->value); - n->tok = e->tok; - provide (n); + update_visitor::visit_literal_number(new literal_number(*e)); } void deep_copy_visitor::visit_binary_expression (binary_expression* e) { - binary_expression* n = new binary_expression; - n->op = e->op; - n->tok = e->tok; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_binary_expression(new binary_expression(*e)); } void deep_copy_visitor::visit_unary_expression (unary_expression* e) { - unary_expression* n = new unary_expression; - n->op = e->op; - n->tok = e->tok; - n->operand = require (e->operand); - provide (n); + update_visitor::visit_unary_expression(new unary_expression(*e)); } void deep_copy_visitor::visit_pre_crement (pre_crement* e) { - pre_crement* n = new pre_crement; - n->op = e->op; - n->tok = e->tok; - n->operand = require (e->operand); - provide (n); + update_visitor::visit_pre_crement(new pre_crement(*e)); } void deep_copy_visitor::visit_post_crement (post_crement* e) { - post_crement* n = new post_crement; - n->op = e->op; - n->tok = e->tok; - n->operand = require (e->operand); - provide (n); + update_visitor::visit_post_crement(new post_crement(*e)); } void 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; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_logical_or_expr(new logical_or_expr(*e)); } void 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; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_logical_and_expr(new logical_and_expr(*e)); } void deep_copy_visitor::visit_array_in (array_in* e) { - array_in* n = new array_in; - n->tok = e->tok; - n->operand = require (e->operand); - provide (n); + update_visitor::visit_array_in(new array_in(*e)); } void deep_copy_visitor::visit_comparison (comparison* e) { - comparison* n = new comparison; - n->op = e->op; - n->tok = e->tok; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_comparison(new comparison(*e)); } void deep_copy_visitor::visit_concatenation (concatenation* e) { - concatenation* n = new concatenation; - n->op = e->op; - n->tok = e->tok; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_concatenation(new concatenation(*e)); } void deep_copy_visitor::visit_ternary_expression (ternary_expression* e) { - ternary_expression* n = new ternary_expression; - n->tok = e->tok; - n->cond = require (e->cond); - n->truevalue = require (e->truevalue); - n->falsevalue = require (e->falsevalue); - provide (n); + update_visitor::visit_ternary_expression(new ternary_expression(*e)); } void deep_copy_visitor::visit_assignment (assignment* e) { - assignment* n = new assignment; - n->op = e->op; - n->tok = e->tok; - n->left = require (e->left); - n->right = require (e->right); - provide (n); + update_visitor::visit_assignment(new assignment(*e)); } void deep_copy_visitor::visit_symbol (symbol* e) { - symbol* n = new symbol; - n->tok = e->tok; - n->name = e->name; - n->referent = NULL; - provide (n); + symbol* n = new symbol(*e); + n->referent = NULL; // don't copy! + update_visitor::visit_symbol(n); } void deep_copy_visitor::visit_target_symbol (target_symbol* e) { - target_symbol* n = new target_symbol; - n->tok = e->tok; - n->base_name = e->base_name; - n->components = e->components; - provide (n); + target_symbol* n = new target_symbol(*e); + n->referent = NULL; // don't copy! + update_visitor::visit_target_symbol(n); } void deep_copy_visitor::visit_arrayindex (arrayindex* e) { - arrayindex* n = new arrayindex; - n->tok = e->tok; - - n->base = require (e->base); - - for (unsigned i = 0; i < e->indexes.size(); ++i) - n->indexes.push_back(require (e->indexes[i])); - provide (n); + update_visitor::visit_arrayindex(new arrayindex(*e)); } void deep_copy_visitor::visit_functioncall (functioncall* e) { - functioncall* n = new functioncall; - n->tok = e->tok; - n->function = e->function; - n->referent = NULL; - for (unsigned i = 0; i < e->args.size(); ++i) - n->args.push_back(require (e->args[i])); - provide (n); + functioncall* n = new functioncall(*e); + n->referent = NULL; // don't copy! + update_visitor::visit_functioncall(n); } void deep_copy_visitor::visit_print_format (print_format* e) { - print_format* n = new print_format; - n->tok = e->tok; - n->print_to_stream = e->print_to_stream; - n->print_with_format = e->print_with_format; - n->print_with_delim = e->print_with_delim; - n->print_with_newline = e->print_with_newline; - n->print_char = e->print_char; - n->raw_components = e->raw_components; - n->components = e->components; - n->delimiter = e->delimiter; - for (unsigned i = 0; i < e->args.size(); ++i) - n->args.push_back(require (e->args[i])); - if (e->hist) - n->hist = require (e->hist); - provide (n); + update_visitor::visit_print_format(new print_format(*e)); } void deep_copy_visitor::visit_stat_op (stat_op* e) { - stat_op* n = new stat_op; - n->tok = e->tok; - n->ctype = e->ctype; - n->stat = require (e->stat); - provide (n); + update_visitor::visit_stat_op(new stat_op(*e)); } void deep_copy_visitor::visit_hist_op (hist_op* e) { - hist_op* n = new hist_op; - n->tok = e->tok; - n->htype = e->htype; - n->params = e->params; - n->stat = require (e->stat); - provide (n); -} - -template <> indexable* -deep_copy_visitor::require (indexable* src) -{ - indexable *dst = NULL; - if (src != NULL) - { - symbol *array_src=NULL; - hist_op *hist_src=NULL; - - classify_indexable(src, array_src, hist_src); - - if (array_src) - dst = require (array_src); - else - dst = require (hist_src); - assert (dst); - } - return dst; + update_visitor::visit_hist_op(new hist_op(*e)); } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit From 1cd151d5b9e1fd46590d5e4c3473a86ea9bbe043 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 10 Feb 2009 18:29:55 -0800 Subject: Simplify dead_stmtexpr_remover * staptree.h (update_visitor::require): Add a clearok parameter for optimizing traversers to signal that they're ready for NULL back. * elaborate.cxx (dead_stmtexpr_remover): Convert to an update_visitor. --- staptree.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 2b963bc3..9ffbaf09 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -2337,7 +2337,7 @@ update_visitor::visit_hist_op (hist_op* e) } template <> indexable* -update_visitor::require (indexable* src) +update_visitor::require (indexable* src, bool clearok) { indexable *dst = NULL; if (src != NULL) @@ -2351,7 +2351,7 @@ update_visitor::require (indexable* src) dst = require (array_src); else dst = require (hist_src); - assert (dst); + assert(clearok || dst); } return dst; } -- cgit From 9b5af2958a35174a67076c0f27cff0ed5950736d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 11 Feb 2009 14:34:32 -0800 Subject: Add high-level support for @cast()ing This handles all of the parsing, traversal, and optimization. It doesn't actually resolve the cast yet though. * staptree.h (struct cast_op, visitor::visit_cast_op): New. * staptree.cxx (cast_op::print/visit, various visitor::visit_cast_op's): Incorporate cast_op into the basic tree operations. * parse.cxx (parser::parse_symbol): Parse @cast operator with an expression operand, type string, and optional module string. * translate.cxx (c_unparser::visit_cast_op): Error out if a @cast survives to translation. * elaborate.cxx (typeresolution_info::visit_cast_op): Error out if a @cast survives to type resolution. (symbol_fetcher::visit_cast_op): treat @casts as a symbol target (void_statement_reducer::visit_cast_op): unused @casts can be discarded, but the operand should still be evaluated. --- staptree.cxx | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 9ffbaf09..d6586d86 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -277,6 +277,28 @@ void target_symbol::print (std::ostream& o) const } +void cast_op::print (std::ostream& o) const +{ + o << base_name << '(' << *operand; + o << ", " << lex_cast_qstring (type); + if (module.length() > 0) + o << ", " << lex_cast_qstring (module); + o << ')'; + for (unsigned i = 0; i < components.size(); ++i) + { + switch (components[i].first) + { + case comp_literal_array_index: + o << '[' << components[i].second << ']'; + break; + case comp_struct_member: + o << "->" << components[i].second; + break; + } + } +} + + void vardecl::print (ostream& o) const { o << name; @@ -1219,6 +1241,12 @@ target_symbol::visit (visitor* u) u->visit_target_symbol(this); } +void +cast_op::visit (visitor* u) +{ + u->visit_cast_op(this); +} + void arrayindex::visit (visitor* u) { @@ -1585,6 +1613,12 @@ traversing_visitor::visit_target_symbol (target_symbol*) { } +void +traversing_visitor::visit_cast_op (cast_op* e) +{ + e->operand->visit (this); +} + void traversing_visitor::visit_arrayindex (arrayindex* e) { @@ -1679,6 +1713,17 @@ varuse_collecting_visitor::visit_target_symbol (target_symbol *e) embedded_seen = true; } +void +varuse_collecting_visitor::visit_cast_op (cast_op *e) +{ + // As with target_symbols, unresolved cast assignments need to preserved + // for later error handling. + if (is_active_lvalue (e)) + embedded_seen = true; + + functioncall_traversing_visitor::visit_cast_op (e); +} + void varuse_collecting_visitor::visit_print_format (print_format* e) { @@ -2063,6 +2108,12 @@ throwing_visitor::visit_target_symbol (target_symbol* e) throwone (e->tok); } +void +throwing_visitor::visit_cast_op (cast_op* e) +{ + throwone (e->tok); +} + void throwing_visitor::visit_arrayindex (arrayindex* e) { @@ -2296,6 +2347,13 @@ update_visitor::visit_target_symbol (target_symbol* e) provide (e); } +void +update_visitor::visit_cast_op (cast_op* e) +{ + e->operand = require (e->operand); + provide (e); +} + void update_visitor::visit_arrayindex (arrayindex* e) { @@ -2527,6 +2585,12 @@ deep_copy_visitor::visit_target_symbol (target_symbol* e) update_visitor::visit_target_symbol(n); } +void +deep_copy_visitor::visit_cast_op (cast_op* e) +{ + update_visitor::visit_cast_op(new cast_op(*e)); +} + void deep_copy_visitor::visit_arrayindex (arrayindex* e) { -- cgit From 482fe2af17347b472232c5d7c4b26e53606e395e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 17 Feb 2009 19:19:48 -0800 Subject: Bump copyright years to 2009 --- staptree.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index d6586d86..8d251731 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1,5 +1,5 @@ // parse tree functions -// Copyright (C) 2005-2008 Red Hat Inc. +// Copyright (C) 2005-2009 Red Hat Inc. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General -- cgit