From: Wolfgang (Blub) Bumiller Date: Tue, 2 Oct 2012 13:59:37 +0000 (+0200) Subject: Print a warning if end_sys_fields was declared as a field rather than a global X-Git-Tag: 0.1-rc1~30 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9d70c3a56ec32f0d561ff13172a82ed42fc7a521;p=xonotic%2Fgmqcc.git Print a warning if end_sys_fields was declared as a field rather than a global --- diff --git a/main.c b/main.c index 785d12e..3aa2305 100644 --- a/main.c +++ b/main.c @@ -416,6 +416,7 @@ int main(int argc, char **argv) { options_set(opts_warn, WARN_FRAME_MACROS, true); options_set(opts_warn, WARN_UNUSED_VARIABLE, true); options_set(opts_warn, WARN_EFFECTLESS_STATEMENT, true); + options_set(opts_warn, WARN_END_SYS_FIELDS, true); if (!options_parse(argc, argv)) { return usage(); diff --git a/parser.c b/parser.c index 080bbc2..2d13537 100644 --- a/parser.c +++ b/parser.c @@ -23,6 +23,9 @@ typedef struct { ast_value *imm_float_zero; ast_value *imm_vector_zero; + size_t crc_globals; + size_t crc_fields; + ast_function *function; MEM_VECTOR_MAKE(varentry_t, locals); size_t blocklocal; @@ -2284,6 +2287,13 @@ static bool parse_variable(parser_t *parser, ast_block *localblock) goto cleanup; } + if (!localblock) { + if (!strcmp(parser_tokval(parser), "end_sys_globals")) + parser->crc_globals = parser->globals_count; + else if (!strcmp(parser_tokval(parser), "end_sys_fields")) + parser->crc_fields = parser->fields_count; + } + if (!isfunc) { if (!localblock && (olddecl = parser_find_global(parser, parser_tokval(parser)))) { parseerror(parser, "global `%s` already declared here: %s:%i", @@ -2710,6 +2720,13 @@ static bool parser_global_statement(parser_t *parser) var = fval; } + if (!strcmp(parser_tokval(parser), "end_sys_fields")) { + if (parsewarning(parser, WARN_END_SYS_FIELDS, "by convention end_sys_fields should be declared as global, rather than a field")) { + ast_value_delete(var); + return false; + } + } + /* turn it into a field */ fld = ast_value_new(ctx, parser_tokval(parser), TYPE_FIELD); fld->expression.next = (ast_expression*)var; diff --git a/warns.def b/warns.def index 1f47fed..5e46023 100644 --- a/warns.def +++ b/warns.def @@ -17,3 +17,4 @@ GMQCC_DEFINE_FLAG(IMPLICIT_FUNCTION_POINTER) GMQCC_DEFINE_FLAG(VARIADIC_FUNCTION) GMQCC_DEFINE_FLAG(FRAME_MACROS) GMQCC_DEFINE_FLAG(EFFECTLESS_STATEMENT) +GMQCC_DEFINE_FLAG(END_SYS_FIELDS)