]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
Starting to add error messages for when using array types in expressions
[xonotic/gmqcc.git] / parser.c
index f1466a1b3a4abfce274150812f3c0b1249e1b0c3..1b2b691f67f595309cd31ef7a9a0308ca6fa06e2 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -387,6 +387,9 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
     size_t i, assignop;
     qcint  generated_op = 0;
 
+    char ty1[1024];
+    char ty2[1024];
+
     if (!sy->ops_count) {
         parseerror(parser, "internal error: missing operator");
         return false;
@@ -759,8 +762,6 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                 else
                     assignop = type_storep_instr[exprs[0]->expression.vtype];
                 if (!ast_compare_type(field->expression.next, exprs[1])) {
-                    char ty1[1024];
-                    char ty2[1024];
                     ast_type_to_string(field->expression.next, ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
                     if (opts_standard == COMPILER_QCC &&
@@ -785,11 +786,16 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                 {
                     assignop = type_store_instr[TYPE_VECTOR];
                 }
-                else
+                else {
                     assignop = type_store_instr[exprs[0]->expression.vtype];
-                if (!ast_compare_type(exprs[0], exprs[1])) {
-                    char ty1[1024];
-                    char ty2[1024];
+                }
+
+                if (assignop == AINSTR_END) {
+                    ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                    ast_type_to_string(exprs[1], ty2, sizeof(ty2));
+                    parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
+                }
+                else if (!ast_compare_type(exprs[0], exprs[1])) {
                     ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
                     if (opts_standard == COMPILER_QCC &&
@@ -2284,7 +2290,7 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
 
     if (!cexp || !ast_istype(cexp, ast_value)) {
         if (cexp)
-            ast_delete(cexp);
+            ast_unref(cexp);
         ast_delete(var);
         parseerror(parser, "expected array-size as constant positive integer");
         return NULL;
@@ -2300,12 +2306,12 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
     else if (cval->expression.vtype == TYPE_FLOAT)
         tmp->expression.count = cval->constval.vfloat;
     else {
-        ast_delete(cexp);
+        ast_unref(cexp);
         ast_delete(var);
         parseerror(parser, "array-size must be a positive integer constant");
         return NULL;
     }
-    ast_delete(cexp);
+    ast_unref(cexp);
 
     if (parser->tok != ']') {
         ast_delete(var);