]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Removing unused _tokennames from lexer.h
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 3bfb9182754c03cc3cae59fb7cda4900649bcaaf..069151283bbde3ff0cc86058954a8cd1a0d10822 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -651,7 +651,11 @@ ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *
     self->cond     = cond;
     self->on_true  = ontrue;
     self->on_false = onfalse;
-    self->phi_out  = NULL;
+
+    if (!ast_type_adopt(self, ontrue)) {
+        ast_ternary_delete(self);
+        return NULL;
+    }
 
     return self;
 }
@@ -784,8 +788,12 @@ bool ast_call_check_types(ast_call *self)
 
     for (i = 0; i < count; ++i) {
         if (!ast_compare_type(self->params[i], (ast_expression*)(func->expression.params[i]))) {
-            asterror(ast_ctx(self), "invalid type for parameter %u in function call",
-                     (unsigned int)(i+1));
+            char texp[1024];
+            char tgot[1024];
+            ast_type_to_string(self->params[i], tgot, sizeof(tgot));
+            ast_type_to_string((ast_expression*)func->expression.params[i], texp, sizeof(texp));
+            asterror(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
+                     (unsigned int)(i+1), texp, tgot);
             /* we don't immediately return */
             retval = false;
         }
@@ -932,7 +940,7 @@ const char* ast_function_label(ast_function *self, const char *prefix)
     size_t len;
     char  *from;
 
-    if (!opts_dump)
+    if (!opts_dump && !opts_dumpfin)
         return NULL;
 
     id  = (self->labelcount++);
@@ -1918,10 +1926,11 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     self->expression.outr = (ir_value*)1;
 
     /* generate the condition */
-    func->curblock = cond;
     cgen = self->cond->expression.codegen;
     if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
         return false;
+    /* update the block which will get the jump - because short-logic or ternaries may have changed this */
+    cond = func->curblock;
 
     /* on-true path */
 
@@ -1968,7 +1977,6 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     merge = ir_function_create_block(func->ir_func, ast_function_label(func, "endif"));
     if (!merge)
         return false;
-
     /* add jumps ot the merge block */
     if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, merge))
         return false;
@@ -2012,8 +2020,8 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
      * may still happen, thus we remember a created ir_value and simply return one
      * if it already exists.
      */
-    if (self->phi_out) {
-        *out = self->phi_out;
+    if (self->expression.outr) {
+        *out = self->expression.outr;
         return true;
     }
 
@@ -2087,8 +2095,8 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
     ir_phi_add(phi, ontrue,  trueval);
     ir_phi_add(phi, onfalse, falseval);
 
-    self->phi_out = ir_phi_value(phi);
-    *out = self->phi_out;
+    self->expression.outr = ir_phi_value(phi);
+    *out = self->expression.outr;
 
     return true;
 }