blob: 47073e49e1c0d3b16b92777745b34673c26b61ae [file] [log] [blame]
Hai Shi56f031e2021-03-22 16:32:11 +08001#ifndef Py_CPYTHON_COMPILE_H
2# error "this header file must not be included directly"
3#endif
4
5/* Public interface */
6#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
7 CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
8 CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
9 CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
10#define PyCF_MASK_OBSOLETE (CO_NESTED)
11
12/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
13 PyCF_ constants can use bits from 0x0100 to 0x10000.
14 CO_FUTURE_ constants use bits starting at 0x20000. */
15#define PyCF_SOURCE_IS_UTF8 0x0100
16#define PyCF_DONT_IMPLY_DEDENT 0x0200
17#define PyCF_ONLY_AST 0x0400
18#define PyCF_IGNORE_COOKIE 0x0800
19#define PyCF_TYPE_COMMENTS 0x1000
20#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
21#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
22 PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
23
24typedef struct {
25 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
26 int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
27} PyCompilerFlags;
28
29#define _PyCompilerFlags_INIT \
30 (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
31
32/* Future feature support */
33
34typedef struct {
35 int ff_features; /* flags set by future statements */
36 int ff_lineno; /* line number of last future statement */
37} PyFutureFeatures;
38
39#define FUTURE_NESTED_SCOPES "nested_scopes"
40#define FUTURE_GENERATORS "generators"
41#define FUTURE_DIVISION "division"
42#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
43#define FUTURE_WITH_STATEMENT "with_statement"
44#define FUTURE_PRINT_FUNCTION "print_function"
45#define FUTURE_UNICODE_LITERALS "unicode_literals"
46#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
47#define FUTURE_GENERATOR_STOP "generator_stop"
48#define FUTURE_ANNOTATIONS "annotations"
49
50struct _mod; /* Declare the existence of this type */
51#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
52PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
53 struct _mod *mod,
54 const char *filename, /* decoded from the filesystem encoding */
55 PyCompilerFlags *flags,
56 int optimize,
57 PyArena *arena);
58PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
59 struct _mod *mod,
60 PyObject *filename,
61 PyCompilerFlags *flags,
62 int optimize,
63 PyArena *arena);
64PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
65 struct _mod * mod,
66 const char *filename /* decoded from the filesystem encoding */
67 );
68PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
69 struct _mod * mod,
70 PyObject *filename
71 );
72
73/* _Py_Mangle is defined in compile.c */
74PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
75
76#define PY_INVALID_STACK_EFFECT INT_MAX
77PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
78PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
79
80typedef struct {
81 int optimize;
82 int ff_features;
83} _PyASTOptimizeState;
84
85PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);