A dynamic tracer for Linux

func.c 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <errno.h>
  2. #include "func.h"
  3. #include "node.h"
  4. #include "ply.h"
  5. #include "sym.h"
  6. #include "type.h"
  7. int func_validate_expr(const struct func *func, struct node *n, int strict)
  8. {
  9. struct tfield *f;
  10. struct node *arg;
  11. int nargs = 0;
  12. for (f = func->type->func.args, arg = n->expr.args;
  13. f && arg; f++, arg = arg->next, nargs++) {
  14. if ((!strict && (arg->sym->type->ttype == T_VOID))
  15. || (f->type->ttype == T_VOID)
  16. || type_compatible(arg->sym->type, f->type) )
  17. continue;
  18. _e("%#N: %O argument is of type '%T', expected '%T'.\n",
  19. n, nargs, arg->sym->type, f->type);
  20. }
  21. return 0;
  22. }
  23. int func_static_validate(const struct func *func, struct node *n)
  24. {
  25. if ((n->ntype == N_NUM) || (n->ntype == N_STRING)) {
  26. }
  27. switch (n->ntype) {
  28. case N_EXPR:
  29. if (func->type->ttype != T_FUNC) {
  30. _e("%#N: %N is not callable.\n", n, n);
  31. return -EINVAL;
  32. }
  33. return func_validate_expr(func, n, 0);
  34. case N_IDENT:
  35. if (func->type->ttype == T_FUNC) {
  36. _e("%#N: %N is a function.\n", n, n);
  37. return -EINVAL;
  38. }
  39. /* fall-through */
  40. case N_NUM:
  41. case N_STRING:
  42. /* ident, num, str. nothing to validate. just copy
  43. * type info to the symbol if statically known */
  44. n->sym->type = func->type;
  45. break;
  46. }
  47. return 0;
  48. }