From 51d852140f469fa62026570764d9a5bd10f425b2 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 31 May 2013 03:56:12 +0000 Subject: [PATCH] Added diagnostic for case expressions --- diag.c | 6 ++++++ gmqcc.h | 3 ++- parser.c | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/diag.c b/diag.c index 13d276f..009df34 100644 --- a/diag.c +++ b/diag.c @@ -156,6 +156,7 @@ static void diagnostic_feed(const char *file, size_t line, size_t beg, size_t en } switch (diagnostic) { + case DIAGNOSTIC_EXPRESSION_CASE: case DIAGNOSTIC_SEMICOLON: for (; len < vec_size(vec_last(read)->values); len++) space += strlen(vec_last(read)->values[len]); @@ -223,6 +224,11 @@ void diagnostic_calculate(const char *file, size_t line, size_t diagnostic) { linebeg++; marker = true; break; + + case DIAGNOSTIC_EXPRESSION_CASE: + linebeg++; + marker = true; + break; /* Catches the DIAGNOSTIC_NULL and out of range case */ default: diff --git a/gmqcc.h b/gmqcc.h index 1beaf4d..9a41ae5 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -1029,7 +1029,8 @@ void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, /*===================================================================*/ enum { DIAGNOSTIC_NULL, - DIAGNOSTIC_SEMICOLON + DIAGNOSTIC_SEMICOLON, + DIAGNOSTIC_EXPRESSION_CASE }; void diagnostic_destroy(); diff --git a/parser.c b/parser.c index 907f6a6..3397856 100644 --- a/parser.c +++ b/parser.c @@ -3371,12 +3371,14 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression * if (!strcmp(parser_tokval(parser), "case")) { if (!parser_next(parser)) { ast_delete(switchnode); + parser->diagnostic = DIAGNOSTIC_EXPRESSION_CASE; parseerror(parser, "expected expression for case"); return false; } swcase.value = parse_expression_leave(parser, false, false, false); if (!swcase.value) { ast_delete(switchnode); + parser->diagnostic = DIAGNOSTIC_EXPRESSION_CASE; parseerror(parser, "expected expression for case"); return false; } -- 2.39.2