add error for function parameters of invalid types

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-10-28 15:44:27 +01:00
parent 201bfb9803
commit 478a9249a0
3 changed files with 20 additions and 0 deletions

17
ast.c
View file

@ -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)
{

1
ast.h
View file

@ -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);

View file

@ -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;