diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2010-03-03 00:28:22 -0500 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2010-03-03 00:33:43 -0500 |
commit | f4fe2e932cc8f445e9e1bc52863e11b669e3afc9 (patch) | |
tree | ba062952c0a37f02ebcf0eb2f533d44ee41fdb25 /elaborate.cxx | |
parent | d105f6642677bd9ef1b20d1ba180ba0163cb0fa6 (diff) | |
download | systemtap-steved-f4fe2e932cc8f445e9e1bc52863e11b669e3afc9.tar.gz systemtap-steved-f4fe2e932cc8f445e9e1bc52863e11b669e3afc9.tar.xz systemtap-steved-f4fe2e932cc8f445e9e1bc52863e11b669e3afc9.zip |
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.
Diffstat (limited to 'elaborate.cxx')
-rw-r--r-- | elaborate.cxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/elaborate.cxx b/elaborate.cxx index a2ab8522..72f12baf 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -2206,6 +2206,7 @@ struct dead_assignment_remover: public update_visitor session(s), relaxed_p(r), vut(v) {} void visit_assignment (assignment* e); + void visit_try_block (try_block *s); }; @@ -2262,6 +2263,27 @@ dead_assignment_remover::visit_assignment (assignment* e) provide (e); } + +void +dead_assignment_remover::visit_try_block (try_block *s) +{ + replace (s->try_block); + if (s->catch_error_var) + { + vardecl* errvar = s->catch_error_var->referent; + if (vut.read.find(errvar) == vut.read.end()) // never read? + { + if (session.verbose>2) + clog << "Eliding unused error string catcher " << errvar->name + << " at " << *s->tok << endl; + s->catch_error_var = 0; + } + } + replace (s->catch_block); + provide (s); +} + + // Let's remove assignments to variables that are never read. We // rewrite "(foo = expr)" as "(expr)". This makes foo a candidate to // be optimized away as an unused variable, and expr a candidate to be @@ -2301,6 +2323,7 @@ struct dead_stmtexpr_remover: public update_visitor session(s), relaxed_p(r) {} void visit_block (block *s); + void visit_try_block (try_block *s); void visit_null_statement (null_statement *s); void visit_if_statement (if_statement* s); void visit_foreach_loop (foreach_loop *s); @@ -2363,6 +2386,22 @@ dead_stmtexpr_remover::visit_block (block *s) provide (s); } + +void +dead_stmtexpr_remover::visit_try_block (try_block *s) +{ + replace (s->try_block, true); + replace (s->catch_block, true); // null catch{} is ok and useful + if (s->try_block == 0) + { + if (session.verbose>2) + clog << "Eliding empty try {} block " << *s->tok << endl; + s = 0; + } + provide (s); +} + + void dead_stmtexpr_remover::visit_if_statement (if_statement *s) { @@ -4262,6 +4301,21 @@ typeresolution_info::visit_block (block* e) void +typeresolution_info::visit_try_block (try_block* e) +{ + if (e->try_block) + e->try_block->visit (this); + if (e->catch_error_var) + { + t = pe_string; + e->catch_error_var->visit (this); + } + if (e->catch_block) + e->catch_block->visit (this); +} + + +void typeresolution_info::visit_embeddedcode (embeddedcode*) { } |