A dynamic tracer for Linux

node.h 921B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ntype {
  8. N_LIST,
  9. N_IDENT,
  10. N_NUM,
  11. N_STRING,
  12. } ntype_t;
  13. struct node {
  14. node_t *next, *prev;
  15. ntype_t ntype;
  16. union {
  17. node_t *list;
  18. char *ident;
  19. int64_t num;
  20. char *string;
  21. };
  22. type_t *type;
  23. };
  24. /* debug */
  25. void node_dump(node_t *n, FILE *fp);
  26. typedef int (*walk_fn)(node_t *, void *);
  27. int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
  28. /* constructors */
  29. node_t *node_list (node_t *head);
  30. node_t *node_vlist (node_t *head, ...);
  31. node_t *node_ident (char *name);
  32. node_t *node_num (int64_t num);
  33. node_t *node_string(char *string);
  34. static inline node_t *node_head(node_t *n)
  35. {
  36. if (!n)
  37. return NULL;
  38. for (; n->prev; n = n->prev);
  39. return n;
  40. }
  41. static inline node_t *node_prev(node_t *n)
  42. {
  43. return n ? n->prev : NULL;
  44. }
  45. #endif /* _PLY_NODE_H */