]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Fix array-index codegen conditions
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 18:02:50 +0000 (19:02 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 18:02:50 +0000 (19:02 +0100)
ast.c

diff --git a/ast.c b/ast.c
index 4de54439a95d2af9eaeab43937d3d11072e10ec7..ac204d31808841135b060a23650ed4b4b77c50c9 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1537,47 +1537,42 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
         return false;
     }
 
-    if (!ast_istype(self->index, ast_value)) {
+    arr = (ast_value*)self->array;
+    idx = (ast_value*)self->index;
+
+    if (!ast_istype(self->index, ast_value) || !idx->isconst) {
+        /* Time to use accessor functions */
+        ast_expression_codegen *cgen;
+        ir_value               *iridx, *funval;
+        ir_instr               *call;
+
         if (lvalue) {
-            asterror(ast_ctx(self), "array indexing here needs a compile-time constant");
+            asterror(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
             return false;
-        } else {
-            /* Time to use accessor functions */
-            ast_expression_codegen *cgen;
-            ir_value               *iridx, *funval;
-            ir_instr               *call;
-
-            if (!arr->getter) {
-                asterror(ast_ctx(self), "value has no getter, don't know how to index it");
-                return false;
-            }
-
-            cgen = self->index->expression.codegen;
-            if (!(*cgen)((ast_expression*)(self->index), func, true, &iridx))
-                return false;
+        }
 
-            cgen = arr->getter->expression.codegen;
-            if (!(*cgen)((ast_expression*)(arr->getter), func, true, &funval))
-                return false;
+        if (!arr->getter) {
+            asterror(ast_ctx(self), "value has no getter, don't know how to index it");
+            return false;
+        }
 
-            call = ir_block_create_call(func->curblock, ast_function_label(func, "fetch"), funval);
-            if (!call)
-                return false;
-            if (!ir_call_param(call, iridx))
-                return false;
+        cgen = self->index->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->index), func, true, &iridx))
+            return false;
 
-            *out = ir_call_value(call);
-            self->expression.outr = *out;
-            return true;
-        }
-    }
+        cgen = arr->getter->expression.codegen;
+        if (!(*cgen)((ast_expression*)(arr->getter), func, true, &funval))
+            return false;
 
-    arr = (ast_value*)self->array;
-    idx = (ast_value*)self->index;
+        call = ir_block_create_call(func->curblock, ast_function_label(func, "fetch"), funval);
+        if (!call)
+            return false;
+        if (!ir_call_param(call, iridx))
+            return false;
 
-    if (!idx->isconst) {
-        asterror(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
-        return false;
+        *out = ir_call_value(call);
+        self->expression.outr = *out;
+        return true;
     }
 
     if (idx->expression.vtype == TYPE_FLOAT)