node.h 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. } node;
  15. PyAPI_FUNC(node *) PyNode_New(int type);
  16. PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
  17. char *str, int lineno, int col_offset);
  18. PyAPI_FUNC(void) PyNode_Free(node *n);
  19. PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);
  20. /* Node access functions */
  21. #define NCH(n) ((n)->n_nchildren)
  22. #define CHILD(n, i) (&(n)->n_child[i])
  23. #define RCHILD(n, i) (CHILD(n, NCH(n) + i))
  24. #define TYPE(n) ((n)->n_type)
  25. #define STR(n) ((n)->n_str)
  26. /* Assert that the type of a node is what we expect */
  27. #define REQ(n, type) assert(TYPE(n) == (type))
  28. PyAPI_FUNC(void) PyNode_ListTree(node *);
  29. #ifdef __cplusplus
  30. }
  31. #endif
  32. #endif /* !Py_NODE_H */