From f4fe2e932cc8f445e9e1bc52863e11b669e3afc9 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 3 Mar 2010 00:28:22 -0500 Subject: PR11004: try / catch error-handling script syntax * parse.h (try_block): New class. Update basic visitors. * staptree.cxx: Implement basic visitors. * parse.cxx (expect_kw): Fix to actually look for keywords. (parse_try_block): New function. (lexer ctor): Designate 'try' and 'catch' as keywords. * elaborate.cxx (dead_assignment_remover, dead_statmtexpr_remover): Optimize. (other visitors): Implement. * translate.cxx (c_unparser): Implement via super-handy __local__ labels. (emit_probe, emit_function): Make outer out: label also __local__. * testsuite/buildok/fortyone.stp, semko/fortynine.stp, systemtap.base/trycatch.exp: Test it. * NEWS, doc/langref.txt, stap.1.in: Document it. --- staptree.cxx | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 9276586b..cca79981 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1,5 +1,5 @@ // parse tree functions -// Copyright (C) 2005-2009 Red Hat Inc. +// Copyright (C) 2005-2010 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 @@ -903,6 +903,18 @@ block::block (statement* car, statement* cdr) +void try_block::print (ostream& o) const +{ + o << "try {" << endl; + if (try_block) o << *try_block << endl; + o << "} catch "; + if (catch_error_var) o << "(" << *catch_error_var << ") "; + o << "{" << endl; + if (catch_block) o << *catch_block << endl; + o << "}" << endl; +} + + void for_loop::print (ostream& o) const { o << "for ("; @@ -1139,6 +1151,13 @@ block::visit (visitor* u) } +void +try_block::visit (visitor* u) +{ + u->visit_try_block (this); +} + + void embeddedcode::visit (visitor* u) { @@ -1524,6 +1543,17 @@ traversing_visitor::visit_block (block* s) s->statements[i]->visit (this); } +void +traversing_visitor::visit_try_block (try_block* s) +{ + if (s->try_block) + s->try_block->visit (this); + if (s->catch_error_var) + s->catch_error_var->visit (this); + if (s->catch_block) + s->catch_block->visit (this); +} + void traversing_visitor::visit_embeddedcode (embeddedcode*) { @@ -1777,6 +1807,21 @@ functioncall_traversing_visitor::visit_functioncall (functioncall* e) } +void +varuse_collecting_visitor::visit_try_block (try_block *s) +{ + if (s->try_block) + s->try_block->visit (this); + if (s->catch_error_var) + written.insert (s->catch_error_var->referent); + if (s->catch_block) + s->catch_block->visit (this); + + // NB: don't functioncall_traversing_visitor::visit_try_block (s); + // since that would count s->catch_error_var as a read also. +} + + void varuse_collecting_visitor::visit_embeddedcode (embeddedcode *s) { @@ -2066,6 +2111,13 @@ throwing_visitor::visit_block (block* s) throwone (s->tok); } +void +throwing_visitor::visit_try_block (try_block* s) +{ + throwone (s->tok); +} + + void throwing_visitor::visit_embeddedcode (embeddedcode* s) { @@ -2278,6 +2330,15 @@ update_visitor::visit_block (block* s) provide (s); } +void +update_visitor::visit_try_block (try_block* s) +{ + replace (s->try_block); + replace (s->catch_error_var); + replace (s->catch_block); + provide (s); +} + void update_visitor::visit_embeddedcode (embeddedcode* s) { @@ -2555,6 +2616,12 @@ deep_copy_visitor::visit_block (block* s) update_visitor::visit_block(new block(*s)); } +void +deep_copy_visitor::visit_try_block (try_block* s) +{ + update_visitor::visit_try_block(new try_block(*s)); +} + void deep_copy_visitor::visit_embeddedcode (embeddedcode* s) { -- cgit