compile.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef Py_CPYTHON_COMPILE_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. /* Public interface */
  5. #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
  6. CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
  7. CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
  8. CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
  9. #define PyCF_MASK_OBSOLETE (CO_NESTED)
  10. /* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
  11. PyCF_ constants can use bits from 0x0100 to 0x10000.
  12. CO_FUTURE_ constants use bits starting at 0x20000. */
  13. #define PyCF_SOURCE_IS_UTF8 0x0100
  14. #define PyCF_DONT_IMPLY_DEDENT 0x0200
  15. #define PyCF_ONLY_AST 0x0400
  16. #define PyCF_IGNORE_COOKIE 0x0800
  17. #define PyCF_TYPE_COMMENTS 0x1000
  18. #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
  19. #define PyCF_ALLOW_INCOMPLETE_INPUT 0x4000
  20. #define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
  21. PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT | \
  22. PyCF_ALLOW_INCOMPLETE_INPUT)
  23. typedef struct {
  24. int cf_flags; /* bitmask of CO_xxx flags relevant to future */
  25. int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
  26. } PyCompilerFlags;
  27. #define _PyCompilerFlags_INIT \
  28. (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
  29. /* source location information */
  30. typedef struct {
  31. int lineno;
  32. int end_lineno;
  33. int col_offset;
  34. int end_col_offset;
  35. } _PyCompilerSrcLocation;
  36. #define SRC_LOCATION_FROM_AST(n) \
  37. (_PyCompilerSrcLocation){ \
  38. .lineno = (n)->lineno, \
  39. .end_lineno = (n)->end_lineno, \
  40. .col_offset = (n)->col_offset, \
  41. .end_col_offset = (n)->end_col_offset }
  42. /* Future feature support */
  43. typedef struct {
  44. int ff_features; /* flags set by future statements */
  45. _PyCompilerSrcLocation ff_location; /* location of last future statement */
  46. } PyFutureFeatures;
  47. #define FUTURE_NESTED_SCOPES "nested_scopes"
  48. #define FUTURE_GENERATORS "generators"
  49. #define FUTURE_DIVISION "division"
  50. #define FUTURE_ABSOLUTE_IMPORT "absolute_import"
  51. #define FUTURE_WITH_STATEMENT "with_statement"
  52. #define FUTURE_PRINT_FUNCTION "print_function"
  53. #define FUTURE_UNICODE_LITERALS "unicode_literals"
  54. #define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
  55. #define FUTURE_GENERATOR_STOP "generator_stop"
  56. #define FUTURE_ANNOTATIONS "annotations"
  57. #define PY_INVALID_STACK_EFFECT INT_MAX
  58. PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
  59. PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);