From 09b39813844e77acf42de48102ed173e8652adb9 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 31 May 2013 06:24:50 +0000 Subject: [PATCH] Add option to turn on and off the diagnostic system, and added a TODO. --- diag.c | 9 +++++++++ main.c | 1 + opts.def | 1 + parser.c | 6 ++++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/diag.c b/diag.c index 73807f2..83b8f99 100644 --- a/diag.c +++ b/diag.c @@ -170,6 +170,15 @@ static void diagnostic_feed(const char *file, size_t line, size_t column, size_t break; case DIAGNOSTIC_UNEXPECTED_IDENT: + /* + * TODO: better way to determine the identifier. So far we + * "assume" it's the first one in the token stream, the issue + * with this, is it'ss possible that it isn't the first ident + * in the stream. In all likely hood, the parser itself should + * carry a "current token in line" count so we can simply use + * it as a index into vec_last(read)->tokens. This will also + * allow for other diagnostics involving unexpected tokens. + */ for (itr = 0; len < vec_size(vec_last(read)->tokens); len++) { if (vec_last(read)->tokens[len] == TOKEN_IDENT) break; diff --git a/main.c b/main.c index 10db6d3..e23f3b5 100644 --- a/main.c +++ b/main.c @@ -173,6 +173,7 @@ static bool options_parse(int argc, char **argv) { OPTS_OPTION_U32(OPTION_STANDARD) = COMPILER_GMQCC; + OPTS_OPTION_BOOL(OPTION_DIAGNOSTICS) = true; } else if (!strcmp(argarg, "qcc")) { diff --git a/opts.def b/opts.def index 520f9b9..5863840 100644 --- a/opts.def +++ b/opts.def @@ -121,6 +121,7 @@ GMQCC_DEFINE_FLAG(MAX_ARRAY_SIZE) GMQCC_DEFINE_FLAG(ADD_INFO) GMQCC_DEFINE_FLAG(CORRECTION) + GMQCC_DEFINE_FLAG(DIAGNOSTICS) #endif /* some cleanup so we don't have to */ diff --git a/parser.c b/parser.c index 2d6cd1d..5deef69 100644 --- a/parser.c +++ b/parser.c @@ -139,7 +139,8 @@ static void parseerror(parser_t *parser, const char *fmt, ...) vcompile_error(parser->lex->tok.ctx, fmt, ap); va_end(ap); - diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic); + if (OPTS_OPTION_BOOL(OPTION_DIAGNOSTICS)) + diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic); } /* returns true if it counts as an error */ @@ -151,7 +152,8 @@ static bool GMQCC_WARN parsewarning(parser_t *parser, int warntype, const char * r = vcompile_warning(parser->lex->tok.ctx, warntype, fmt, ap); va_end(ap); - diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic); + if (OPTS_OPTION_BOOL(OPTION_DIAGNOSTICS)) + diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic); return r; } -- 2.39.2