From fe57dcd231fa872c27a029008c399091a67ec2c3 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 31 May 2013 04:18:00 +0000 Subject: [PATCH] Implemented diagnostic for unexpected identifiers --- diag.c | 13 +++++++++++++ gmqcc.h | 3 ++- parser.c | 2 ++ test.c | 1 - 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/diag.c b/diag.c index 83c2b93..c888991 100644 --- a/diag.c +++ b/diag.c @@ -160,6 +160,15 @@ static void diagnostic_feed(const char *file, size_t line, size_t beg, size_t en space -= beg - end; break; + case DIAGNOSTIC_UNEXPECTED_IDENT: + for (itr = 0; len < vec_size(vec_last(read)->tokens); len++) { + if (vec_last(read)->tokens[len] == TOKEN_IDENT) + break; + space += strlen(vec_last(read)->values[len]); + } + len = 0; + break; + default: break; } @@ -225,6 +234,10 @@ void diagnostic_calculate(const char *file, size_t line, size_t diagnostic) { marker = true; break; + case DIAGNOSTIC_UNEXPECTED_IDENT: + marker = true; + break; + /* Catches the DIAGNOSTIC_NULL and out of range case */ default: return; diff --git a/gmqcc.h b/gmqcc.h index 9a41ae5..84ddc2a 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -1030,7 +1030,8 @@ void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, enum { DIAGNOSTIC_NULL, DIAGNOSTIC_SEMICOLON, - DIAGNOSTIC_EXPRESSION_CASE + DIAGNOSTIC_EXPRESSION_CASE, + DIAGNOSTIC_UNEXPECTED_IDENT }; void diagnostic_destroy(); diff --git a/parser.c b/parser.c index 3397856..063c6d2 100644 --- a/parser.c +++ b/parser.c @@ -1960,11 +1960,13 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) correct_free(&corr); if (correct) { + parser->diagnostic = DIAGNOSTIC_UNEXPECTED_IDENT; parseerror(parser, "unexpected ident: %s (did you mean %s?)", parser_tokval(parser), correct); mem_d(correct); return false; } } + parser->diagnostic = DIAGNOSTIC_UNEXPECTED_IDENT; parseerror(parser, "unexpected ident: %s", parser_tokval(parser)); return false; } diff --git a/test.c b/test.c index 6682983..e693e3e 100644 --- a/test.c +++ b/test.c @@ -678,7 +678,6 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) { abort(); } - /* skip directories */ if (S_ISDIR(directory.st_mode)) continue; -- 2.39.2