-Wframe-macros, warn about duplicate frame macro definitions, on by default

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-23 19:16:26 +02:00
parent 19391bb190
commit 9f2e8b9bfe
3 changed files with 17 additions and 3 deletions

18
lexer.c
View file

@ -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;

1
main.c
View file

@ -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();

View file

@ -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)