#include #include "func.h" #include "node.h" #include "sym.h" #include "type.h" int func_validate_expr(const struct func *func, struct node *n, int strict) { struct tfield *f; struct node *arg; int nargs = 0; for (f = func->type->func.args, arg = n->expr.args; f && arg; f++, arg = arg->next, nargs++) { if ((!strict && (arg->sym->type->ttype == T_VOID)) || (f->type->ttype == T_VOID) || type_compatible(arg->sym->type, f->type) ) continue; node_error(n, stderr, "type mismatch for argument %d, expected %T, got %T", nargs, f->type, arg->sym->type); } return 0; } int func_static_validate(const struct func *func, struct node *n) { if ((n->ntype == N_NUM) || (n->ntype == N_STRING)) { } switch (n->ntype) { case N_EXPR: if (func->type->ttype != T_FUNC) { node_error(n, stderr, "'%s' is not callable", n->expr.func); return -EINVAL; } return func_validate_expr(func, n, 0); case N_IDENT: if (func->type->ttype == T_FUNC) { node_error(n, stderr, "'%s' is a function", n->ident.name); return -EINVAL; } /* fall-through */ case N_NUM: case N_STRING: /* ident, num, str. nothing to validate. just copy * type info to the symbol if statically known */ n->sym->type = func->type; break; } return 0; }