]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Print a warning if end_sys_fields was declared as a field rather than a global
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 2 Oct 2012 13:59:37 +0000 (15:59 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 2 Oct 2012 13:59:37 +0000 (15:59 +0200)
main.c
parser.c
warns.def

diff --git a/main.c b/main.c
index 785d12e2475126def36c404cf1f40a3d7c58618c..3aa23055ed651e3f84402682b8c074899f7752f4 100644 (file)
--- 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();
index 080bbc2c092963b2248948b9fbf89d8f4081efaf..2d13537fc680010953fae1273a439921cdc01701 100644 (file)
--- 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;
index 1f47fede223b546b721af320c1b5f76a9b6200ae..5e46023faf94bdf777d502e76539264a9e78d3b2 100644 (file)
--- 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)