]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Error when the assignop for an assignment is invalid, eg. when trying to assign arrays
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 5a65a49f82dbc19000e8e92aee45abb770ecce37..46f05392501e6d73888dcac66fa83089a05b5225 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -73,6 +73,7 @@ static void ast_expression_init(ast_expression *self,
     self->expression.outr     = NULL;
     self->expression.variadic = false;
     self->expression.params   = NULL;
+    self->expression.count    = 0;
 }
 
 static void ast_expression_delete(ast_expression *self)
@@ -1040,7 +1041,7 @@ const char* ast_function_label(ast_function *self, const char *prefix)
     size_t len;
     char  *from;
 
-    if (!opts_dump && !opts_dumpfin)
+    if (!opts.dump && !opts.dumpfin)
         return NULL;
 
     id  = (self->labelcount++);
@@ -1137,7 +1138,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
             }
 
             /* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
-            if (!array->expression.count || array->expression.count > opts_max_array_size)
+            if (!array->expression.count || array->expression.count > opts.max_array_size)
                 compile_error(ast_ctx(self), "Invalid array of size %lu", (unsigned long)array->expression.count);
 
             elemtype = &array->expression.next->expression;
@@ -1149,6 +1150,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 return false;
             }
             v->context = ast_ctx(self);
+            v->unique_life = true;
             array->ir_v = self->ir_v = v;
 
             namelen = strlen(self->name);
@@ -1166,6 +1168,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                     return false;
                 }
                 array->ir_values[ai]->context = ast_ctx(self);
+                array->ir_values[ai]->unique_life = true;
             }
             mem_d(name);
         }
@@ -1189,7 +1192,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
         int vtype = elemtype->vtype;
 
         /* same as with field arrays */
-        if (!self->expression.count || self->expression.count > opts_max_array_size)
+        if (!self->expression.count || self->expression.count > opts.max_array_size)
             compile_error(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
 
         v = ir_builder_create_global(ir, self->name, vtype);
@@ -1198,6 +1201,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
             return false;
         }
         v->context = ast_ctx(self);
+        v->unique_life = true;
 
         namelen = strlen(self->name);
         name    = (char*)mem_a(namelen + 16);
@@ -1214,6 +1218,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 return false;
             }
             self->ir_values[ai]->context = ast_ctx(self);
+            self->ir_values[ai]->unique_life = true;
         }
         mem_d(name);
     }
@@ -1308,7 +1313,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
         }
 
         /* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
-        if (!self->expression.count || self->expression.count > opts_max_array_size) {
+        if (!self->expression.count || self->expression.count > opts.max_array_size) {
             compile_error(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
         }
 
@@ -1324,6 +1329,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
             return false;
         }
         v->context = ast_ctx(self);
+        v->unique_life = true;
 
         namelen = strlen(self->name);
         name    = (char*)mem_a(namelen + 16);
@@ -1338,6 +1344,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
                 return false;
             }
             self->ir_values[ai]->context = ast_ctx(self);
+            self->ir_values[ai]->unique_life = true;
         }
     }
     else
@@ -1407,14 +1414,14 @@ bool ast_generate_accessors(ast_value *self, ir_builder *ir)
         }
     }
 
-    options_set(opts_warn, WARN_USED_UNINITIALIZED, false);
+    options_set(opts.warn, WARN_USED_UNINITIALIZED, 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(self), "internal error: failed to generate setter for `%s`", self->name);
-            options_set(opts_warn, WARN_USED_UNINITIALIZED, warn);
+            options_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
             return false;
         }
     }
@@ -1424,14 +1431,14 @@ bool ast_generate_accessors(ast_value *self, ir_builder *ir)
             !ir_function_finalize(self->getter->constval.vfunc->ir_func))
         {
             compile_error(ast_ctx(self), "internal error: failed to generate getter for `%s`", self->name);
-            options_set(opts_warn, WARN_USED_UNINITIALIZED, warn);
+            options_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
             return false;
         }
     }
     for (i = 0; i < self->expression.count; ++i) {
         vec_free(self->ir_values[i]->life);
     }
-    options_set(opts_warn, WARN_USED_UNINITIALIZED, warn);
+    options_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
     return true;
 }
 
@@ -1545,7 +1552,7 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
     for (i = 0; i < vec_size(self->locals); ++i)
     {
         if (!ast_local_codegen(self->locals[i], func->ir_func, false)) {
-            if (opts_debug)
+            if (opts.debug)
                 compile_error(ast_ctx(self), "failed to generate local `%s`", self->locals[i]->name);
             return false;
         }
@@ -1996,7 +2003,9 @@ bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, i
     } else {
         *out = ir_block_create_load_from_ent(func->curblock, ast_ctx(self), ast_function_label(func, "efv"),
                                              ent, field, self->expression.vtype);
+        /* Done AFTER error checking: 
         codegen_output_type(self, *out);
+        */
     }
     if (!*out) {
         compile_error(ast_ctx(self), "failed to create %s instruction (output type %s)",
@@ -2004,6 +2013,8 @@ bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, i
                  type_name[self->expression.vtype]);
         return false;
     }
+    if (!lvalue)
+        codegen_output_type(self, *out);
 
     if (lvalue)
         self->expression.outl = *out;