From 116562fc3039a55f7296a8e6cd46c5fee57cf087 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 11 Nov 2013 11:34:39 -0500 Subject: [PATCH] new resolved_type struct and mismatch/resolved functions The resolved_type struct holds all the information about a newly resolved decl. The token 'tok' holds where the resolution occurred, and 'index' is the position of the function-argument/array-index of the decl. The vector resolved_types will hold all the decls we resolve. A new resolved() function is introduced which will add elements to the vector, while an analogous mismatch() function will be used to report mismatches between type and resolved decl. --- elaborate.cxx | 40 +++++++++++++++++++++++++++++++++++++++- elaborate.h | 26 ++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index 361ce2b2e..6e4df928c 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -5346,6 +5346,19 @@ typeresolution_info::invalid (const token* tok, exp_type pe) } } +void +typeresolution_info::mismatch (const binary_expression* e) +{ + num_still_unresolved ++; + + if (assert_resolvability) + { + 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)); + } +} /* tok token where mismatch occurred * t1 type we expected (the 'good' type) @@ -5366,11 +5379,36 @@ typeresolution_info::mismatch (const token* tok, exp_type t1, exp_type t2) } } +/* tok token where the mismatch happened + * type type we received (the 'bad' type) + * decl declaration of mismatched symbol + * index if index-based (array index or function arg) + * */ +void +typeresolution_info::mismatch (const token *tok, exp_type type, + const symboldecl* decl, int index) +{ + num_still_unresolved ++; + + if (assert_resolvability) + { + cerr << "A mismatch occurred" << endl; + // TODO: retrieve from resolved_types vector + } +} + +/* tok token where resolution occurred + * type type to which we resolved + * decl declaration of resolved symbol + * index if index-based (array index or function arg) + * */ void -typeresolution_info::resolved (const token*, exp_type) +typeresolution_info::resolved (const token *tok, exp_type type, + const symboldecl* decl, int index) { num_newly_resolved ++; + // TODO: add to resolved_types vector } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ diff --git a/elaborate.h b/elaborate.h index 7624d63d6..54aadfd3c 100644 --- a/elaborate.h +++ b/elaborate.h @@ -74,12 +74,34 @@ struct typeresolution_info: public visitor functiondecl* current_function; derived_probe* current_probe; + // Holds information about a type we resolved (see PR16097) + struct resolved_type + { + const token *tok; + const symboldecl *decl; + int index; + resolved_type(const token *ct, const symboldecl *cdecl, int cindex): + tok(ct), decl(cdecl), index(cindex) {} + }; + + // Holds an element each time we resolve a decl. Unique by decl & index. + // Possible values: + // - resolved function type -> decl = functiondecl, index = -1 + // - resolved function arg type -> decl = vardecl, index = index of arg + // - resolved array/var type -> decl = vardecl, index = -1 + // - resolved array index type -> decl = vardecl, index = index of type + std::vector resolved_types; // see PR16097 + void check_arg_type (exp_type wanted, expression* arg); void check_local (vardecl* v); - void mismatch (const token* tok, exp_type t1, exp_type t2); void unresolved (const token* tok); - void resolved (const token* tok, exp_type t); void invalid (const token* tok, exp_type t); + void mismatch (const binary_expression* e); + void mismatch (const token* tok, exp_type t1, exp_type t2); + void mismatch (const token* tok, exp_type type, + const symboldecl* decl, int index = -1); + void resolved (const token* tok, exp_type type, + const symboldecl* decl = NULL, int index = -1); exp_type t; // implicit parameter for nested visit call; may clobber // Upon entry to one of the visit_* calls, the incoming -- 2.43.5