From ab6eaa20da7b44493ee326560196b31e50976f74 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 23 Dec 2010 15:32:27 +0100 Subject: [PATCH] isl_stream_next_token: keep track of string representation of keywords This allows us to print a more meaningful error message when a keyword is used in an unexpected place. Signed-off-by: Sven Verdoolaege --- include/isl/stream.h | 1 + isl_stream.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/isl/stream.h b/include/isl/stream.h index 12e17f59..695aeedc 100644 --- a/include/isl/stream.h +++ b/include/isl/stream.h @@ -35,6 +35,7 @@ struct isl_token { enum isl_token_type type; unsigned int on_new_line : 1; + unsigned is_keyword : 1; int line; int col; diff --git a/isl_stream.c b/isl_stream.c index e114900f..d25ff030 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -73,6 +73,7 @@ static struct isl_token *isl_token_new(struct isl_ctx *ctx, tok->line = line; tok->col = col; tok->on_new_line = on_new_line; + tok->is_keyword = 0; return tok; } @@ -97,6 +98,8 @@ void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg) fprintf(stderr, "got '%c'\n", tok->type); else if (tok->type == ISL_TOKEN_IDENT) fprintf(stderr, "got ident '%s'\n", tok->u.s); + else if (tok->is_keyword) + fprintf(stderr, "got keyword '%s'\n", tok->u.s); else fprintf(stderr, "got token type %d\n", tok->type); } @@ -356,8 +359,11 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) isl_stream_ungetc(s, c); isl_stream_push_char(s, '\0'); tok->type = check_keywords(s); - if (tok->type == ISL_TOKEN_IDENT) - tok->u.s = strdup(s->buffer); + if (tok->type != ISL_TOKEN_IDENT) + tok->is_keyword = 1; + tok->u.s = strdup(s->buffer); + if (!tok->u.s) + goto error; return tok; } if (c == '"') { -- 2.11.4.GIT