node.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Parse tree node interface */
  2. #ifndef Py_NODE_H
  3. #define Py_NODE_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct _node {
  8. short n_type;
  9. char *n_str;
  10. int n_lineno;
  11. int n_col_offset;
  12. int n_nchildren;
  13. struct _node *n_child;
  14. int n_end_lineno;
  15. int n_end_col_offset;
  16. } node;
  17. PyAPI_FUNC(node *) PyNode_New(int type);
  18. PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
  19. char *str, int lineno, int col_offset,
  20. int end_lineno, int end_col_offset);
  21. PyAPI_FUNC(void) PyNode_Free(node *n);
  22. #ifndef Py_LIMITED_API
  23. PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);
  24. #endif
  25. /* Node access functions */
  26. #define NCH(n) ((n)->n_nchildren)
  27. #define CHILD(n, i) (&(n)->n_child[i])
  28. #define RCHILD(n, i) (CHILD(n, NCH(n) + i))
  29. #define TYPE(n) ((n)->n_type)
  30. #define STR(n) ((n)->n_str)
  31. #define LINENO(n) ((n)->n_lineno)
  32. /* Assert that the type of a node is what we expect */
  33. #define REQ(n, type) assert(TYPE(n) == (type))
  34. PyAPI_FUNC(void) PyNode_ListTree(node *);
  35. void _PyNode_FinalizeEndPos(node *n); // helper also used in parsetok.c
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39. #endif /* !Py_NODE_H */