A dynamic tracer for Linux

node.h 1.2KB

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