]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Sanity check in ast_generate_accessors
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 2 Dec 2012 17:02:44 +0000 (18:02 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 2 Dec 2012 17:02:44 +0000 (18:02 +0100)
ast.c

diff --git a/ast.c b/ast.c
index 69a16feec91ee57bc0cfe1176715cc980fa475b9..f388eb396924d9201bad77404cdff956c0fa18b8 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1400,23 +1400,40 @@ error: /* clean up */
     return false;
 }
 
-bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir)
+bool ast_generate_accessors(ast_value *self, ir_builder *ir)
 {
-    if (asvalue->setter) {
-        if (!ast_global_codegen  (asvalue->setter, ir, false) ||
-            !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
-            !ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
+    size_t i;
+    if (!self->setter || !self->getter)
+        return true;
+    for (i = 0; i < self->expression.count; ++i) {
+        if (!self->ir_values) {
+            compile_error(ast_ctx(self), "internal error: no array values generated for `%s`", self->name);
+            return false;
+        }
+        if (!self->ir_values[i]) {
+            compile_error(ast_ctx(self), "internal error: not all array values have been generated for `%s`", self->name);
+            return false;
+        }
+        if (self->ir_values[i]->life) {
+            compile_error(ast_ctx(self), "internal error: function containing `%s` already generated", self->name);
+            return false;
+        }
+    }
+    if (self->setter) {
+        if (!ast_global_codegen  (self->setter, ir, false) ||
+            !ast_function_codegen(self->setter->constval.vfunc, ir) ||
+            !ir_function_finalize(self->setter->constval.vfunc->ir_func))
         {
-            compile_error(ast_ctx(asvalue), "internal error: failed to generate setter for `%s`", asvalue->name);
+            compile_error(ast_ctx(self), "internal error: failed to generate setter for `%s`", self->name);
             return false;
         }
     }
-    if (asvalue->getter) {
-        if (!ast_global_codegen  (asvalue->getter, ir, false) ||
-            !ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
-            !ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
+    if (self->getter) {
+        if (!ast_global_codegen  (self->getter, ir, false) ||
+            !ast_function_codegen(self->getter->constval.vfunc, ir) ||
+            !ir_function_finalize(self->getter->constval.vfunc->ir_func))
         {
-            compile_error(ast_ctx(asvalue), "internal error: failed to generate getter for `%s`", asvalue->name);
+            compile_error(ast_ctx(self), "internal error: failed to generate getter for `%s`", self->name);
             return false;
         }
     }