A dynamic tracer for Linux

node.h 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef _PLY_NODE_H
  2. #define _PLY_NODE_H
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include "sym.h"
  6. #include "type.h"
  7. typedef struct node node_t;
  8. typedef enum keyword {
  9. KW_SUBSCRIPT = '[',
  10. KW_ASSIGN = '=',
  11. KW_ADD = '+',
  12. KW_SUB = '-',
  13. KW_MUL = '*',
  14. KW_DIV = '/',
  15. } keyword_t;
  16. typedef enum ntype {
  17. N_LIST,
  18. N_KEYWORD,
  19. N_IDENT,
  20. N_NUM,
  21. N_STRING,
  22. } ntype_t;
  23. struct node {
  24. node_t *next, *prev, *up;
  25. ntype_t ntype;
  26. union {
  27. node_t *list;
  28. keyword_t keyword;
  29. char *ident;
  30. int64_t num;
  31. char *string;
  32. };
  33. type_t *type;
  34. sym_t *sym;
  35. };
  36. /* debug */
  37. void node_print(node_t *n, FILE *fp);
  38. void node_dump (node_t *n, FILE *fp);
  39. typedef int (*walk_fn)(node_t *, void *);
  40. int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
  41. /* constructors */
  42. node_t *node_list (node_t *head);
  43. node_t *node_vlist (node_t *head, ...);
  44. node_t *node_keyword(keyword_t keyword);
  45. node_t *node_ident (char *name);
  46. node_t *node_num (int64_t num);
  47. node_t *node_string (char *string);
  48. static inline node_t *node_head(node_t *n)
  49. {
  50. if (!n)
  51. return NULL;
  52. for (; n->prev; n = n->prev);
  53. return n;
  54. }
  55. static inline node_t *node_prev(node_t *n)
  56. {
  57. return n ? n->prev : NULL;
  58. }
  59. static inline node_t *node_next(node_t *n)
  60. {
  61. return n ? n->next : NULL;
  62. }
  63. static inline node_t *node_up(node_t *n)
  64. {
  65. return n ? n->up : NULL;
  66. }
  67. #endif /* _PLY_NODE_H */