asdl.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef Py_ASDL_H
  2. #define Py_ASDL_H
  3. typedef PyObject * identifier;
  4. typedef PyObject * string;
  5. typedef PyObject * bytes;
  6. typedef PyObject * object;
  7. typedef PyObject * singleton;
  8. typedef PyObject * constant;
  9. /* It would be nice if the code generated by asdl_c.py was completely
  10. independent of Python, but it is a goal the requires too much work
  11. at this stage. So, for example, I'll represent identifiers as
  12. interned Python strings.
  13. */
  14. /* XXX A sequence should be typed so that its use can be typechecked. */
  15. typedef struct {
  16. Py_ssize_t size;
  17. void *elements[1];
  18. } asdl_seq;
  19. typedef struct {
  20. Py_ssize_t size;
  21. int elements[1];
  22. } asdl_int_seq;
  23. asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena);
  24. asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
  25. #define asdl_seq_GET(S, I) (S)->elements[(I)]
  26. #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
  27. #ifdef Py_DEBUG
  28. #define asdl_seq_SET(S, I, V) \
  29. do { \
  30. Py_ssize_t _asdl_i = (I); \
  31. assert((S) != NULL); \
  32. assert(0 <= _asdl_i && _asdl_i < (S)->size); \
  33. (S)->elements[_asdl_i] = (V); \
  34. } while (0)
  35. #else
  36. #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
  37. #endif
  38. #endif /* !Py_ASDL_H */