A dynamic tracer for Linux

node.h 1.3KB

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