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.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 12d84698..8c37776f 100644 --- a/staptree.h +++ b/staptree.h @@ -882,3 +882,5 @@ provide (deep_copy_visitor* v, T src) } #endif // STAPTREE_H + +/* 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.h | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 8c37776f..29196828 100644 --- a/staptree.h +++ b/staptree.h @@ -818,11 +818,30 @@ struct throwing_visitor: public visitor struct deep_copy_visitor: public visitor { - std::stack targets; + template T require (T src) + { + T dst = NULL; + if (src != NULL) + { + src->visit(this); + assert(!targets.empty()); + dst = static_cast(targets.top()); + targets.pop(); + assert(dst); + } + return dst; + } + + template void provide (T src) + { + targets.push(static_cast(src)); + } - static expression *deep_copy (expression *s); - static statement *deep_copy (statement *s); - static block *deep_copy (block *s); + template 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 void -require (deep_copy_visitor* v, T* dst, T src) -{ - *dst = NULL; - if (src != NULL) - { - v->targets.push(static_cast(dst)); - src->visit(v); - v->targets.pop(); - assert(*dst); - } -} - -template <> void -require (deep_copy_visitor* v, indexable** dst, indexable* src); +private: + std::stack targets; +}; -template void -provide (deep_copy_visitor* v, T src) -{ - assert(!v->targets.empty()); - *(static_cast(v->targets.top())) = src; -} +template <> indexable* +deep_copy_visitor::require (indexable* src); #endif // STAPTREE_H -- 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.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 29196828..00809ed0 100644 --- a/staptree.h +++ b/staptree.h @@ -810,13 +810,10 @@ struct throwing_visitor: public visitor void visit_hist_op (hist_op* e); }; -// A visitor which performs a deep copy of the root node it's applied -// to. NB: It does not copy any of the variable or function -// declarations; those fields are set to NULL, assuming you want to -// re-infer the declarations in a new context (the one you're copying -// to). +// A visitor similar to a traversing_visitor, but with the ability to rewrite +// parts of the tree through require/provide. -struct deep_copy_visitor: public visitor +struct update_visitor: public visitor { template T require (T src) { @@ -837,11 +834,7 @@ struct deep_copy_visitor: public visitor targets.push(static_cast(src)); } - template static T deep_copy (T e) - { - deep_copy_visitor v; - return v.require (e); - } + virtual ~update_visitor() { assert(targets.empty()); } virtual void visit_block (block *s); virtual void visit_embeddedcode (embeddedcode *s); @@ -881,7 +874,55 @@ private: }; template <> indexable* -deep_copy_visitor::require (indexable* src); +update_visitor::require (indexable* src); + +// A visitor which performs a deep copy of the root node it's applied +// to. NB: It does not copy any of the variable or function +// declarations; those fields are set to NULL, assuming you want to +// re-infer the declarations in a new context (the one you're copying +// to). + +struct deep_copy_visitor: public update_visitor +{ + template 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); + virtual void visit_null_statement (null_statement *s); + virtual void visit_expr_statement (expr_statement *s); + virtual void visit_if_statement (if_statement* s); + virtual void visit_for_loop (for_loop* s); + virtual void visit_foreach_loop (foreach_loop* s); + virtual void visit_return_statement (return_statement* s); + virtual void visit_delete_statement (delete_statement* s); + virtual void visit_next_statement (next_statement* s); + virtual void visit_break_statement (break_statement* s); + virtual void visit_continue_statement (continue_statement* s); + virtual void visit_literal_string (literal_string* e); + virtual void visit_literal_number (literal_number* e); + virtual void visit_binary_expression (binary_expression* e); + virtual void visit_unary_expression (unary_expression* e); + virtual void visit_pre_crement (pre_crement* e); + virtual void visit_post_crement (post_crement* e); + virtual void visit_logical_or_expr (logical_or_expr* e); + virtual void visit_logical_and_expr (logical_and_expr* e); + virtual void visit_array_in (array_in* e); + virtual void visit_comparison (comparison* e); + virtual void visit_concatenation (concatenation* e); + virtual void visit_ternary_expression (ternary_expression* e); + virtual void visit_assignment (assignment* e); + virtual void visit_symbol (symbol* e); + virtual void visit_target_symbol (target_symbol* e); + virtual void visit_arrayindex (arrayindex* e); + virtual void visit_functioncall (functioncall* e); + virtual void visit_print_format (print_format* e); + virtual void visit_stat_op (stat_op* e); + virtual void visit_hist_op (hist_op* e); +}; #endif // STAPTREE_H -- 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.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 00809ed0..0cd0ee0d 100644 --- a/staptree.h +++ b/staptree.h @@ -815,7 +815,7 @@ struct throwing_visitor: public visitor struct update_visitor: public visitor { - template T require (T src) + template T require (T src, bool clearok=false) { T dst = NULL; if (src != NULL) @@ -824,7 +824,7 @@ struct update_visitor: public visitor assert(!targets.empty()); dst = static_cast(targets.top()); targets.pop(); - assert(dst); + assert(clearok || dst); } return dst; } @@ -874,7 +874,7 @@ private: }; template <> indexable* -update_visitor::require (indexable* src); +update_visitor::require (indexable* src, bool clearok); // A visitor which performs a deep copy of the root node it's applied // to. NB: It does not copy any of the variable or function -- 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.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 0cd0ee0d..7092f980 100644 --- a/staptree.h +++ b/staptree.h @@ -238,6 +238,15 @@ struct target_symbol: public symbol }; +struct cast_op: public target_symbol +{ + expression *operand; + std::string type, module; + void print (std::ostream& o) const; + void visit (visitor* u); +}; + + struct arrayindex: public expression { std::vector indexes; @@ -680,6 +689,7 @@ struct visitor virtual void visit_print_format (print_format* e) = 0; virtual void visit_stat_op (stat_op* e) = 0; virtual void visit_hist_op (hist_op* e) = 0; + virtual void visit_cast_op (cast_op* e) = 0; }; @@ -720,6 +730,7 @@ struct traversing_visitor: public visitor void visit_print_format (print_format* e); void visit_stat_op (stat_op* e); void visit_hist_op (hist_op* e); + void visit_cast_op (cast_op* e); }; @@ -759,6 +770,7 @@ struct varuse_collecting_visitor: public functioncall_traversing_visitor void visit_pre_crement (pre_crement *e); void visit_post_crement (post_crement *e); void visit_foreach_loop (foreach_loop *s); + void visit_cast_op (cast_op* e); bool side_effect_free (); bool side_effect_free_wrt (const std::set& vars); @@ -808,6 +820,7 @@ struct throwing_visitor: public visitor void visit_print_format (print_format* e); void visit_stat_op (stat_op* e); void visit_hist_op (hist_op* e); + void visit_cast_op (cast_op* e); }; // A visitor similar to a traversing_visitor, but with the ability to rewrite @@ -868,6 +881,7 @@ struct update_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); + virtual void visit_cast_op (cast_op* e); private: std::stack targets; @@ -922,6 +936,7 @@ struct deep_copy_visitor: public update_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); + virtual void visit_cast_op (cast_op* e); }; #endif // STAPTREE_H -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'staptree.h') diff --git a/staptree.h b/staptree.h index 7092f980..5125cd85 100644 --- a/staptree.h +++ b/staptree.h @@ -1,5 +1,5 @@ // -*- C++ -*- -// Copyright (C) 2005-2008 Red Hat Inc. +// Copyright (C) 2005-2009 Red Hat Inc. // Copyright (C) 2006 Intel Corporation. // // This file is part of systemtap, and is free software. You can -- cgit