From: Wolfgang (Blub) Bumiller Date: Thu, 23 Aug 2012 17:16:26 +0000 (+0200) Subject: -Wframe-macros, warn about duplicate frame macro definitions, on by default X-Git-Tag: 0.1-rc1~67 X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=9f2e8b9bfe17346703d1453777dac0676d119918;p=xonotic%2Fgmqcc.git -Wframe-macros, warn about duplicate frame macro definitions, on by default --- diff --git a/lexer.c b/lexer.c index 2798737..3d217ab 100644 --- a/lexer.c +++ b/lexer.c @@ -27,12 +27,12 @@ void lexerror(lex_file *lex, const char *fmt, ...) printf("\n"); } -void lexwarn(lex_file *lex, int warn, const char *fmt, ...) +bool lexwarn(lex_file *lex, int warn, const char *fmt, ...) { va_list ap; if (!OPTS_WARN(warn)) - return; + return false; if (lex) printf("warning %s:%lu: ", lex->name, (unsigned long)lex->sline); @@ -44,6 +44,8 @@ void lexwarn(lex_file *lex, int warn, const char *fmt, ...) va_end(ap); printf("\n"); + + return opts_werror; } token* token_new() @@ -398,7 +400,8 @@ static int lex_parse_frame(lex_file *lex) static bool lex_finish_frames(lex_file *lex) { do { - int rc; + size_t i; + int rc; frame_macro m; rc = lex_parse_frame(lex); @@ -407,6 +410,15 @@ static bool lex_finish_frames(lex_file *lex) if (rc < 0) /* error */ return false; + for (i = 0; i < lex->frames_count; ++i) { + if (!strcmp(lex->tok->value, lex->frames[i].name)) { + lex->frames[i].value = lex->framevalue++; + if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok->value)) + return false; + continue; + } + } + m.value = lex->framevalue++; m.name = lex->tok->value; lex->tok->value = NULL; diff --git a/main.c b/main.c index 5445303..23f4de8 100644 --- a/main.c +++ b/main.c @@ -400,6 +400,7 @@ int main(int argc, char **argv) { options_set(opts_warn, WARN_VOID_VARIABLES, true); options_set(opts_warn, WARN_IMPLICIT_FUNCTION_POINTER, true); options_set(opts_warn, WARN_VARIADIC_FUNCTION, true); + options_set(opts_warn, WARN_FRAME_MACROS, true); if (!options_parse(argc, argv)) { return usage(); diff --git a/warns.def b/warns.def index 3b63b36..b3abd78 100644 --- a/warns.def +++ b/warns.def @@ -15,3 +15,4 @@ GMQCC_DEFINE_FLAG(LOCAL_CONSTANTS) GMQCC_DEFINE_FLAG(VOID_VARIABLES) GMQCC_DEFINE_FLAG(IMPLICIT_FUNCTION_POINTER) GMQCC_DEFINE_FLAG(VARIADIC_FUNCTION) +GMQCC_DEFINE_FLAG(FRAME_MACROS)