asdl.h 1.2 KB

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