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