compile.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef Py_COMPILE_H
  2. #define Py_COMPILE_H
  3. #ifndef Py_LIMITED_API
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* Public interface */
  8. struct _node; /* Declare the existence of this type */
  9. #ifndef Py_BUILD_CORE
  10. Py_DEPRECATED(3.9)
  11. #endif
  12. PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
  13. /* XXX (ncoghlan): Unprefixed type name in a public API! */
  14. #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
  15. CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
  16. CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
  17. CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
  18. #define PyCF_MASK_OBSOLETE (CO_NESTED)
  19. /* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
  20. PyCF_ constants can use bits from 0x0100 to 0x10000.
  21. CO_FUTURE_ constants use bits starting at 0x20000. */
  22. #define PyCF_SOURCE_IS_UTF8 0x0100
  23. #define PyCF_DONT_IMPLY_DEDENT 0x0200
  24. #define PyCF_ONLY_AST 0x0400
  25. #define PyCF_IGNORE_COOKIE 0x0800
  26. #define PyCF_TYPE_COMMENTS 0x1000
  27. #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
  28. #define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
  29. PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
  30. #ifndef Py_LIMITED_API
  31. typedef struct {
  32. int cf_flags; /* bitmask of CO_xxx flags relevant to future */
  33. int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
  34. } PyCompilerFlags;
  35. #define _PyCompilerFlags_INIT \
  36. (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
  37. #endif
  38. /* Future feature support */
  39. typedef struct {
  40. int ff_features; /* flags set by future statements */
  41. int ff_lineno; /* line number of last future statement */
  42. } PyFutureFeatures;
  43. #define FUTURE_NESTED_SCOPES "nested_scopes"
  44. #define FUTURE_GENERATORS "generators"
  45. #define FUTURE_DIVISION "division"
  46. #define FUTURE_ABSOLUTE_IMPORT "absolute_import"
  47. #define FUTURE_WITH_STATEMENT "with_statement"
  48. #define FUTURE_PRINT_FUNCTION "print_function"
  49. #define FUTURE_UNICODE_LITERALS "unicode_literals"
  50. #define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
  51. #define FUTURE_GENERATOR_STOP "generator_stop"
  52. #define FUTURE_ANNOTATIONS "annotations"
  53. struct _mod; /* Declare the existence of this type */
  54. #define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
  55. PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
  56. struct _mod *mod,
  57. const char *filename, /* decoded from the filesystem encoding */
  58. PyCompilerFlags *flags,
  59. int optimize,
  60. PyArena *arena);
  61. PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
  62. struct _mod *mod,
  63. PyObject *filename,
  64. PyCompilerFlags *flags,
  65. int optimize,
  66. PyArena *arena);
  67. PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
  68. struct _mod * mod,
  69. const char *filename /* decoded from the filesystem encoding */
  70. );
  71. PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
  72. struct _mod * mod,
  73. PyObject *filename
  74. );
  75. /* _Py_Mangle is defined in compile.c */
  76. PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
  77. #define PY_INVALID_STACK_EFFECT INT_MAX
  78. PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
  79. PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
  80. typedef struct {
  81. int optimize;
  82. int ff_features;
  83. } _PyASTOptimizeState;
  84. PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* !Py_LIMITED_API */
  89. /* These definitions must match corresponding definitions in graminit.h. */
  90. #define Py_single_input 256
  91. #define Py_file_input 257
  92. #define Py_eval_input 258
  93. #define Py_func_type_input 345
  94. /* This doesn't need to match anything */
  95. #define Py_fstring_input 800
  96. #endif /* !Py_COMPILE_H */