From c74ddc54952c1fcd73cdacacff3bfe95dbabfdcc Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 11 Nov 2013 12:19:35 -0500 Subject: [PATCH] add mismatch_complexity The mismatch_complexity variable allows us to only print out the most complex kind of mismatch, and skip over simpler mismatches, in order to keep the mismatch reporting as simple to understand as possible. When assert_resolvability is false, mismatch_complexity simply remembers the most complex mismatch we've met so far during each pass (e.g. unresolved() is 0, mismatch(e) is 1, mismatch(tok, t1, t2) is 2, and mismatch(tok, t, decl, index) is 3). Once we turn on assert_resolvability, we check mismatch_complexity in mismatch() and unresolved() to determine whether to print out an error or not. If mismatch_complexity is higher than our own complexity, then we don't print anything since we know that there is a better-suited mismatch coming up. --- elaborate.cxx | 26 +++++++++++++++++++------- elaborate.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index 24a25e169..9b860d947 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -4220,13 +4220,19 @@ semantic_pass_types (systemtap_session& s) if (ti.num_still_unresolved == 0) break; // successfully else if (! ti.assert_resolvability) - ti.assert_resolvability = true; // last pass, with error msgs + { + ti.assert_resolvability = true; // last pass, with error msgs + if (s.verbose > 0) + ti.mismatch_complexity = 0; // print every kind of mismatch + } else { // unsuccessful conclusion rc ++; break; } } + else + ti.mismatch_complexity = 0; // reset for next pass } return rc + s.num_errors(); @@ -4236,8 +4242,8 @@ semantic_pass_types (systemtap_session& s) typeresolution_info::typeresolution_info (systemtap_session& s): session(s), num_newly_resolved(0), num_still_unresolved(0), - assert_resolvability(false), current_function(0), current_probe(0), - t(pe_unknown) + assert_resolvability(false), mismatch_complexity(0), + current_function(0), current_probe(0), t(pe_unknown) { } @@ -5318,7 +5324,7 @@ typeresolution_info::unresolved (const token* tok) { num_still_unresolved ++; - if (assert_resolvability) + if (assert_resolvability && mismatch_complexity <= 0) { stringstream msg; msg << _("unresolved type "); @@ -5348,13 +5354,15 @@ typeresolution_info::mismatch (const binary_expression* e) { num_still_unresolved ++; - if (assert_resolvability) + if (assert_resolvability && mismatch_complexity <= 1) { stringstream msg; msg << _F("type mismatch: left and right sides don't agree (%s vs %s)", lex_cast(e->left->type).c_str(), lex_cast(e->right->type).c_str()); session.print_error (SEMANTIC_ERROR (msg.str(), e->tok)); } + else if (!assert_resolvability) + mismatch_complexity = max(1, mismatch_complexity); } /* tok token where mismatch occurred @@ -5366,7 +5374,7 @@ typeresolution_info::mismatch (const token* tok, exp_type t1, exp_type t2) { num_still_unresolved ++; - if (assert_resolvability) + if (assert_resolvability && mismatch_complexity <= 2) { stringstream msg; msg << _F("type mismatch: expected %s", lex_cast(t1).c_str()); @@ -5374,6 +5382,8 @@ typeresolution_info::mismatch (const token* tok, exp_type t1, exp_type t2) msg << _F(" but found %s", lex_cast(t2).c_str()); session.print_error (SEMANTIC_ERROR (msg.str(), tok)); } + else if (!assert_resolvability) + mismatch_complexity = max(2, mismatch_complexity); } /* tok token where the mismatch happened @@ -5387,7 +5397,7 @@ typeresolution_info::mismatch (const token *tok, exp_type type, { num_still_unresolved ++; - if (assert_resolvability) + if (assert_resolvability && mismatch_complexity <= 3) { assert(decl != NULL); @@ -5444,6 +5454,8 @@ typeresolution_info::mismatch (const token *tok, exp_type type, session.print_error (err); if (err.chain) delete err.chain; } + else if (!assert_resolvability) + mismatch_complexity = max(3, mismatch_complexity); } diff --git a/elaborate.h b/elaborate.h index 54aadfd3c..3e30da079 100644 --- a/elaborate.h +++ b/elaborate.h @@ -71,6 +71,7 @@ struct typeresolution_info: public visitor unsigned num_newly_resolved; unsigned num_still_unresolved; bool assert_resolvability; + int mismatch_complexity; functiondecl* current_function; derived_probe* current_probe; -- 2.43.5