| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include <errno.h>
- #include "func.h"
- #include "node.h"
- #include "ply.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;
- _e("%#N: %O argument is of type '%T', expected '%T'.\n",
- n, nargs, arg->sym->type, f->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) {
- _e("%#N: %N is not callable.\n", n, n);
- return -EINVAL;
- }
- return func_validate_expr(func, n, 0);
- case N_IDENT:
- if (func->type->ttype == T_FUNC) {
- _e("%#N: %N is a function.\n", n, n);
- 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;
- }
|