]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
add error for function parameters of invalid types
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 28 Oct 2012 14:44:27 +0000 (15:44 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 28 Oct 2012 14:44:27 +0000 (15:44 +0100)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index 51615712592071510753b7337b69562305dff3f9..a0af13022ebd8585252af91e36eca44bd983e793 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -589,6 +589,23 @@ void ast_call_delete(ast_call *self)
     mem_d(self);
 }
 
+bool ast_call_check_types(ast_call *self)
+{
+    size_t i;
+    bool   retval = true;
+    const ast_expression *func = self->func;
+
+    for (i = 0; i < self->params_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));
+            /* we don't immediately return */
+            retval = false;
+        }
+    }
+    return retval;
+}
+
 ast_store* ast_store_new(lex_ctx ctx, int op,
                          ast_expression *dest, ast_expression *source)
 {
diff --git a/ast.h b/ast.h
index 0664f2825895256c520f012f2b0d678597c061ab..272b388a7be9257357a3d3b457c0923888ceb0e9 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -423,6 +423,7 @@ ast_call* ast_call_new(lex_ctx ctx,
                        ast_expression *funcexpr);
 void ast_call_delete(ast_call*);
 bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**);
+bool ast_call_check_types(ast_call*);
 
 MEM_VECTOR_PROTO(ast_call, ast_expression*, params);
 
index 4ef7a07c26e56f198d60b9f18c957c67da4b1d6f..017df19c40c2f626544ecfd4fe5f46a10eac49e2 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -967,6 +967,8 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
             MEM_VECTOR_MOVE(params, exprs, call, params);
             ast_delete(params);
         }
+        if (!ast_call_check_types(call))
+            parser->errors++;
     } else {
         parseerror(parser, "invalid function call");
         return false;