diff options
author | Rajan Arora <rarora@redhat.com> | 2009-02-18 20:16:03 -0500 |
---|---|---|
committer | Rajan Arora <rarora@redhat.com> | 2009-02-18 20:16:03 -0500 |
commit | d5f0c423890f54b7f12da85fbcfc61879efc368e (patch) | |
tree | 03c1e4a89d3472980e0c6b966580662d5485aabb | |
parent | 8aaa6e11f666ad372107299b5b17602011125c7d (diff) | |
download | systemtap-steved-d5f0c423890f54b7f12da85fbcfc61879efc368e.tar.gz systemtap-steved-d5f0c423890f54b7f12da85fbcfc61879efc368e.tar.xz systemtap-steved-d5f0c423890f54b7f12da85fbcfc61879efc368e.zip |
BZ 9719: Improve type mismatch messages
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | elaborate.cxx | 59 | ||||
-rw-r--r-- | elaborate.h | 2 |
3 files changed, 62 insertions, 6 deletions
@@ -1,3 +1,10 @@ +2009-02-18 Rajan Arora <rarora@redhat.com> + + * elaborate.cxx (typeresolution_info::mismatch): Generate semantic + error for the token where type was resolved and add to chain + * elaborate.h (struct typeresolution_info: public visitor): New + members 'resolved_toks' and 'printed_toks' + 2009-02-18 Stan Cox <scox@redhat.com> * tapsets.cxx (dwarf_builder::build): If not found in .probes, use .label diff --git a/elaborate.cxx b/elaborate.cxx index 02229fbe..25c52c33 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -3987,23 +3987,70 @@ typeresolution_info::invalid (const token* tok, exp_type pe) void typeresolution_info::mismatch (const token* tok, exp_type t1, exp_type t2) { + bool tok_resolved; + size_t i; + semantic_error* err1 = 0; num_still_unresolved ++; + //BZ 9719: for improving type mismatch messages, a semantic error is + //generated with the token where type was first resolved. All such + //resolved tokens, stored in a vector, are matched against their + //content. If an error for the matching token hasn't been printed out + //already, it is and the token pushed in another printed_toks vector + if (assert_resolvability) { stringstream msg; - string nm = (current_function ? current_function->name : - current_probe ? current_probe->name : - "probe condition"); - msg << nm + " with type mismatch (" << t1 << " vs. " << t2 << ")"; - session.print_error (semantic_error (msg.str(), tok)); + for (i=0; i<resolved_toks.size(); i++) + { + if (resolved_toks[i]->content == tok->content) + { + tok_resolved = true; + break; + } + } + if (!tok_resolved) + { + string nm = (current_function ? current_function->name : + current_probe ? current_probe->name : + "probe condition"); + msg << nm + " with type mismatch (" << t1 << " vs. " << t2 << ")"; + } + else + { + bool tok_printed; + for (size_t j=0; j<printed_toks.size(); j++) + { + if (printed_toks[j] == resolved_toks[i]) + { + tok_printed = true; + break; + } + } + string nm = (current_function ? current_function->name : + current_probe ? current_probe->name : + "probe condition"); + msg << nm + " with type mismatch (" << t1 << " vs. " << t2 << ")"; + if (!tok_printed) + { + //error for possible mismatch in the earlier resolved token + printed_toks.push_back (resolved_toks[i]); + stringstream type_msg; + type_msg << nm + " type first inferred here (" << t2 << ")"; + err1 = new semantic_error (type_msg.str(), resolved_toks[i]); + } + } + semantic_error err (msg.str(), tok); + err.chain = err1; + session.print_error (err); } } void -typeresolution_info::resolved (const token*, exp_type) +typeresolution_info::resolved (const token* tok, exp_type) { + resolved_toks.push_back (tok); num_newly_resolved ++; } diff --git a/elaborate.h b/elaborate.h index 715a37df..1e05444f 100644 --- a/elaborate.h +++ b/elaborate.h @@ -54,6 +54,8 @@ struct typeresolution_info: public visitor bool assert_resolvability; functiondecl* current_function; derived_probe* current_probe; + std::vector <const token*> resolved_toks; // account for type mis- + std::vector <const token*> printed_toks; // matches (BZ 9719) void check_arg_type (exp_type wanted, expression* arg); void mismatch (const token* tok, exp_type t1, exp_type t2); |