A dynamic tracer for Linux

node.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _PLY_NODE_H
  2. #define _PLY_NODE_H
  3. #include <stdint.h>
  4. typedef struct atom atom_t;
  5. typedef struct expr expr_t;
  6. typedef struct node node_t;
  7. typedef enum atype {
  8. A_INVALID,
  9. A_IDENT,
  10. A_NUM,
  11. A_STRING,
  12. } atype_t;
  13. struct atom {
  14. atype_t atype;
  15. union {
  16. char *ident;
  17. int64_t num;
  18. char *string;
  19. };
  20. };
  21. typedef enum etype {
  22. E_INVALID = '\0',
  23. E_AGG = '@',
  24. E_CALL = '(',
  25. E_DEREF = '*',
  26. E_DOT = '.',
  27. E_MAP = 'm',
  28. E_SCOPE = '{',
  29. } etype_t;
  30. struct expr {
  31. etype_t etype;
  32. node_t *arg;
  33. };
  34. typedef enum ntype {
  35. N_INVALID,
  36. N_ATOM,
  37. N_EXPR,
  38. } ntype_t;
  39. struct node {
  40. ntype_t ntype;
  41. node_t *up;
  42. node_t *next;
  43. union {
  44. atom_t atom;
  45. expr_t expr;
  46. };
  47. };
  48. int node_walk(node_t *n,
  49. int (*pre)(node_t *, void *),
  50. int (*post)(node_t *, void *),
  51. void *ctx);
  52. /* node constructors */
  53. node_t *node_ident (char *name);
  54. node_t *node_num (int64_t num);
  55. node_t *node_string(char *string);
  56. node_t *node_expr (etype_t etype, node_t *arg);
  57. node_t *node_cons (node_t *head, node_t *tail);
  58. /* debug */
  59. typedef struct node_dump_info {
  60. FILE *fp;
  61. int indent;
  62. } node_dump_info_t;
  63. void node_dump(node_t *n, node_dump_info_t *info);
  64. #endif /* _PLY_NODE_H */