A dynamic tracer for Linux

node.h 1.4KB

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