aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-27 01:41:15 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-06-01 15:06:12 +0200
commit09e75bb48f7eeeac95bb61bbe2b2d0fc1b368067 (patch)
tree47169a079c1eff12f41e7cfc1534ea9d7553987b
parent573953f358dcb77308532d8e2020bf045213acc6 (diff)
downloadsparse-dev-09e75bb48f7eeeac95bb61bbe2b2d0fc1b368067.tar.gz
avoid multiple error message after parsing error
Parsing error triggered by expect() insert bad_token as the current token. This allows to skip other errors with expect(). So far so good but this token is a fake token which has no position set, if another parsing error is detected by something else than expect(), the error message will use the position of this bad token which will be displayed like: builtin:0:0: ... which is confusing. Since the concerned error message are secondary ones, the primary one have been already be repported by expect(), the best is to simply skip all these secondary error messages. Do this by creating a new token type (TOKEN_BAD) and use it for bad_token, then filter error messages based on this token type. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--lib.c9
-rw-r--r--token.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index a05d0474..c451a88c 100644
--- a/lib.c
+++ b/lib.c
@@ -70,7 +70,7 @@ struct token *skip_to(struct token *token, int op)
return token;
}
-static struct token bad_token;
+static struct token bad_token = { .pos.type = TOKEN_BAD };
struct token *expect(struct token *token, int op, const char *where)
{
if (!match_op(token, op)) {
@@ -123,6 +123,10 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_
static char buffer[512];
const char *name;
+ /* Shut up warnings if position is bad_token.pos */
+ if (pos.type == TOKEN_BAD)
+ return;
+
vsprintf(buffer, fmt, args);
name = stream_name(pos.stream);
@@ -150,6 +154,9 @@ static void do_error(struct position pos, const char * fmt, va_list args)
static int errors = 0;
die_if_error = 1;
show_info = 1;
+ /* Shut up warnings if position is bad_token.pos */
+ if (pos.type == TOKEN_BAD)
+ return;
/* Shut up warnings after an error */
has_error |= ERROR_CURR_PHASE;
if (errors > 100) {
diff --git a/token.h b/token.h
index 847fdf4d..292db167 100644
--- a/token.h
+++ b/token.h
@@ -79,6 +79,7 @@ struct ident {
enum token_type {
TOKEN_EOF,
+ TOKEN_BAD,
TOKEN_ERROR,
TOKEN_IDENT,
TOKEN_ZERO_IDENT,