]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Add some ice
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 4eb250fad19c360756aae26a362d5cc063bdbe3f..13adffa8cc6bb7cdc3e5a5b21ced669782b30659 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -406,13 +406,17 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op,
     else
         self->expression.vtype = left->expression.vtype;
 
+    /* references all */
+    self->refs = AST_REF_ALL;
+
     return self;
 }
 
 void ast_binary_delete(ast_binary *self)
 {
-    ast_unref(self->left);
-    ast_unref(self->right);
+    if (self->refs & AST_REF_LEFT)  ast_unref(self->left);
+    if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
+
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
@@ -1403,7 +1407,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
 
         v = ir_function_create_local(func, self->name, vtype, param);
         if (!v) {
-            compile_error(ast_ctx(self), "ir_function_create_local failed");
+            compile_error(ast_ctx(self), "internal error: ir_function_create_local failed");
             return false;
         }
         v->context = ast_ctx(self);
@@ -1419,7 +1423,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
             snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
             self->ir_values[ai] = ir_function_create_local(func, name, vtype, param);
             if (!self->ir_values[ai]) {
-                compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", name);
+                compile_error(ast_ctx(self), "internal_error: ir_builder_create_global failed on `%s`", name);
                 return false;
             }
             self->ir_values[ai]->context = ast_ctx(self);
@@ -1534,7 +1538,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
 
     irf = self->ir_func;
     if (!irf) {
-        compile_error(ast_ctx(self), "ast_function's related ast_value was not generated yet");
+        compile_error(ast_ctx(self), "internal error: ast_function's related ast_value was not generated yet");
         return false;
     }
 
@@ -2183,9 +2187,11 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
 
     if (!lvalue && self->expression.outr) {
         *out = self->expression.outr;
+        return true;
     }
     if (lvalue && self->expression.outl) {
         *out = self->expression.outl;
+        return true;
     }
 
     if (!ast_istype(self->array, ast_value)) {