]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
field constants - revert globals generated after fields
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 30 Nov 2012 20:11:12 +0000 (21:11 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 30 Nov 2012 20:11:25 +0000 (21:11 +0100)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index d797fc125c97a61436128d4d9d6b47a79a9af27d..5d824d0c44e5cf62651708a6eee6c2a6bcf84fc7 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1264,6 +1264,18 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 /* Cannot generate an IR value for a function,
                  * need a pointer pointing to a function rather.
                  */
+            case TYPE_FIELD:
+                if (!self->constval.vfield) {
+                    compile_error(ast_ctx(self), "field constant without vfield set");
+                    goto error;
+                }
+                if (!self->constval.vfield->ir_v) {
+                    compile_error(ast_ctx(self), "field constant generated before its field");
+                    goto error;
+                }
+                if (!ir_value_set_field(v, self->constval.vfield->ir_v))
+                    goto error;
+                break;
             default:
                 compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
                 break;
diff --git a/ast.h b/ast.h
index a7fd7b8a7f1cf133969de4342de56faf5093c54c..004243fd7717fdf4ceea6343b7fe4ba06ae88200 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -169,6 +169,7 @@ struct ast_value_s
         const char   *vstring;
         int           ventity;
         ast_function *vfunc;
+        ast_value    *vfield;
     } constval;
 
     /* usecount for the parser */
index 87a15141a38fedc1880ce12ff0741265b3db70fd..3e1bad925b4fccc312840d91cd33625fb47ba74b 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4025,6 +4025,8 @@ skipvar:
                     var->hasvalue = true;
                     if (cval->expression.vtype == TYPE_STRING)
                         var->constval.vstring = parser_strdup(cval->constval.vstring);
+                    else if (cval->expression.vtype == TYPE_FIELD)
+                        var->constval.vfield = cval;
                     else
                         memcpy(&var->constval, &cval->constval, sizeof(var->constval));
                     ast_unref(cval);
@@ -4466,14 +4468,11 @@ bool parser_finish(const char *output)
                 return false;
             }
         }
-        for (i = 0; i < vec_size(parser->fields); ++i) {
+        for (i = 0; i < vec_size(parser->globals); ++i) {
             ast_value *asvalue;
-            asvalue = (ast_value*)(parser->fields[i]->expression.next);
-
-            if (!ast_istype((ast_expression*)asvalue, ast_value))
-                continue;
-            if (asvalue->expression.vtype != TYPE_ARRAY)
+            if (!ast_istype(parser->globals[i], ast_value))
                 continue;
+            asvalue = (ast_value*)(parser->globals[i]);
             if (asvalue->setter) {
                 if (!ast_global_codegen(asvalue->setter, ir, false) ||
                     !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
@@ -4495,11 +4494,14 @@ bool parser_finish(const char *output)
                 }
             }
         }
-        for (i = 0; i < vec_size(parser->globals); ++i) {
+        for (i = 0; i < vec_size(parser->fields); ++i) {
             ast_value *asvalue;
-            if (!ast_istype(parser->globals[i], ast_value))
+            asvalue = (ast_value*)(parser->fields[i]->expression.next);
+
+            if (!ast_istype((ast_expression*)asvalue, ast_value))
+                continue;
+            if (asvalue->expression.vtype != TYPE_ARRAY)
                 continue;
-            asvalue = (ast_value*)(parser->globals[i]);
             if (asvalue->setter) {
                 if (!ast_global_codegen(asvalue->setter, ir, false) ||
                     !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||