From cbfbbf6996cbe3b9fe57ac2014aa7262bb6890d6 Mon Sep 17 00:00:00 2001 From: fche Date: Tue, 24 Jan 2006 17:58:02 +0000 Subject: 2006-01-24 Frank Ch. Eigler PR 2060 etc. * tapsets.cxx (visit_target_symbol): Tolerate failed resolution by letting target_symbol instance pass through to optimizer and type checker. * elaborate.cxx (semantic_pass_optimize): New family of functions and associated visitor classes. (visit_for_loop): Tolerate absent init/incr clauses. (semantic_pass): Invoke unless unoptimized (-u) option given. * main.cxx, session.h: Add support for flag. * staptree.cxx (visit_for_loop): Tolerate absent init/incr clauses. (traversing_visitor::visit_arrayindex): Visit the index expressions. (functioncall_traversing_visitor): New class. (varuse_tracking_visitor): New class. * staptree.h: Corresponding changes. * parse.cxx (parse_for_loop): Represent absent init/incr expressions with null statement pointer instead of optimized-out dummy numbers. * stap.1.in: Document optimization. * testsuite/{semko,transko}/*.stp: Added "-u" or other code to many tests to check bad code without optimizer elision. * testsuite/semok/optimize.stp: New test. * elaborate.cxx (unresolved, invalid, mismatch): Standardize error message wording. * stapfuncs.5.in: Tweak print/printf docs. * tapset/logging.stp: Remove redundant "print" auxiliary function, since it's a translator built-in. * testsuite/transok/five.stp: Extend test. * translate.cxx (emit_symbol_data): Put symbol table into a separate temporary header file, to make "-p3" output easier on the eyes. * buildrun.cxx (compile_pass): Eliminate test-mode support throughout. * main.cxx, session.h, translate.cxx: Ditto. * main.cxx (main): For last-pass=2 runs, print post-optimization ASTs. --- tapsets.cxx | 83 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 7d10ddf3..89201cb2 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -1868,46 +1868,48 @@ target_variable_flavour_calculating_visitor::visit_target_symbol (target_symbol { assert(e->base_name.size() > 0 && e->base_name[0] == '$'); - try + // NB: if for whatever reason this variable does not resolve, + // or is illegally used (write in non-guru mode for instance), + // just pretend that it's OK anyway. var_expanding_copy_visitor + // will take care of throwing the appropriate exception. + + bool lvalue = is_active_lvalue(e); + flavour += lvalue ? 'w' : 'r'; + exp_type ty; + string expr; + try { - bool lvalue = is_active_lvalue(e); - if (lvalue && !q.sess.guru_mode) - throw semantic_error("Writing to target variable outside of guru mode", e->tok); - - flavour += lvalue ? 'w' : 'r'; - exp_type ty; - string expr = q.dw.literal_stmt_for_local(scope_die, - addr, - e->base_name.substr(1), - e->components, - lvalue, - ty); - switch (ty) - { - case pe_unknown: - flavour += 'U'; - break; - case pe_long: - flavour += 'L'; - break; - case pe_string: - flavour += 'S'; - break; - case pe_stats: - flavour += 'T'; - break; - } - flavour += lex_cast(expr.size()); - flavour += '{'; - flavour += expr; - flavour += '}'; + expr = q.dw.literal_stmt_for_local(scope_die, + addr, + e->base_name.substr(1), + e->components, + lvalue, + ty); } - catch (const semantic_error& er) + catch (const semantic_error& e) { - semantic_error er2 (er); - er2.tok1 = e->tok; - q.sess.print_error (er2); + ty = pe_unknown; } + + switch (ty) + { + case pe_unknown: + flavour += 'U'; + break; + case pe_long: + flavour += 'L'; + break; + case pe_string: + flavour += 'S'; + break; + case pe_stats: + flavour += 'T'; + break; + } + flavour += lex_cast(expr.size()); + flavour += '{'; + flavour += expr; + flavour += '}'; } @@ -2636,9 +2638,12 @@ var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) } catch (const semantic_error& er) { - // No need to be verbose: the flavour-gathering visitor - // already printed a message for this exact case. - throw semantic_error ("due to failed target variable resolution"); + // We suppress this error message, and pass the unresolved + // 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 (this, e); + return; } fdecl->name = fname; -- cgit