From 478a9249a0da6c1fd66258ac8b13fd0b5a76db86 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sun, 28 Oct 2012 15:44:27 +0100 Subject: [PATCH] add error for function parameters of invalid types --- ast.c | 17 +++++++++++++++++ ast.h | 1 + parser.c | 2 ++ 3 files changed, 20 insertions(+) diff --git a/ast.c b/ast.c index 5161571..a0af130 100644 --- 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 0664f28..272b388 100644 --- 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); diff --git a/parser.c b/parser.c index 4ef7a07..017df19 100644 --- 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; -- 2.39.2