blob: 98adee3d19120407ab43e1c3b7f4249c9bcb0cd1 [file] [log] [blame]
Fred Drakeea9cb5a2000-07-09 00:20:36 +00001#ifndef Py_COMPILE_H
2#define Py_COMPILE_H
Thomas Woutersca82a8b2006-02-28 23:09:08 +00003
Victor Stinner2bdc7f52011-09-29 01:04:08 +02004#ifndef Py_LIMITED_API
Thomas Woutersca82a8b2006-02-28 23:09:08 +00005
Fred Drakeea9cb5a2000-07-09 00:20:36 +00006#ifdef __cplusplus
7extern "C" {
8#endif
9
Guido van Rossum3f5da241990-12-20 15:06:42 +000010/* Public interface */
Guido van Rossume543a941991-04-03 19:00:55 +000011struct _node; /* Declare the existence of this type */
Lysandros Nikolaou8ae5e8e2020-06-22 03:07:39 +030012#ifndef Py_BUILD_CORE
13Py_DEPRECATED(3.9)
14#endif
Martin v. Löwis95292d62002-12-11 14:04:59 +000015PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
Eric Snow6b4be192017-05-22 21:36:03 -070016/* 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 | \
Guido van Rossum95e4d582018-01-26 08:20:18 -080021 CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
Eric Snow6b4be192017-05-22 21:36:03 -070022#define PyCF_MASK_OBSOLETE (CO_NESTED)
Batuhan Taşkaya44540572020-04-22 19:09:03 +030023
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. */
Eric Snow6b4be192017-05-22 21:36:03 -070027#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
Guido van Rossumdcfcd142019-01-31 03:40:27 -080031#define PyCF_TYPE_COMMENTS 0x1000
Matthias Bussonnier565b4f12019-05-21 13:12:03 -070032#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
Batuhan Taşkaya44540572020-04-22 19:09:03 +030033#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
34 PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
Eric Snow6b4be192017-05-22 21:36:03 -070035
36#ifndef Py_LIMITED_API
37typedef struct {
38 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Guido van Rossum495da292019-03-07 12:38:08 -080039 int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
Eric Snow6b4be192017-05-22 21:36:03 -070040} PyCompilerFlags;
Victor Stinner37d66d72019-06-13 02:16:41 +020041
42#define _PyCompilerFlags_INIT \
43 (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
Eric Snow6b4be192017-05-22 21:36:03 -070044#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000045
Jeremy Hylton4db62b12001-02-27 19:07:02 +000046/* Future feature support */
47
48typedef struct {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000049 int ff_features; /* flags set by future statements */
50 int ff_lineno; /* line number of last future statement */
Jeremy Hylton4db62b12001-02-27 19:07:02 +000051} PyFutureFeatures;
52
Jeremy Hylton4db62b12001-02-27 19:07:02 +000053#define FUTURE_NESTED_SCOPES "nested_scopes"
Guido van Rossumb09f7ed2001-07-15 21:08:29 +000054#define FUTURE_GENERATORS "generators"
Guido van Rossum4668b002001-08-08 05:00:18 +000055#define FUTURE_DIVISION "division"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000056#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
Thomas Wouters34aa7ba2006-02-28 19:02:24 +000057#define FUTURE_WITH_STATEMENT "with_statement"
Eric Smith87824082008-03-20 23:02:08 +000058#define FUTURE_PRINT_FUNCTION "print_function"
Christian Heimes4d6ec852008-03-26 22:34:47 +000059#define FUTURE_UNICODE_LITERALS "unicode_literals"
Brett Cannone3944a52009-04-01 05:08:41 +000060#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
Yury Selivanov8170e8c2015-05-09 11:44:30 -040061#define FUTURE_GENERATOR_STOP "generator_stop"
Guido van Rossum95e4d582018-01-26 08:20:18 -080062#define FUTURE_ANNOTATIONS "annotations"
Guido van Rossum4668b002001-08-08 05:00:18 +000063
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000064struct _mod; /* Declare the existence of this type */
Georg Brandl8334fd92010-12-04 10:26:46 +000065#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
Victor Stinner00676d12010-12-27 01:49:31 +000066PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
Victor Stinner0d711162010-12-27 02:39:20 +000067 struct _mod *mod,
Victor Stinner00676d12010-12-27 01:49:31 +000068 const char *filename, /* decoded from the filesystem encoding */
69 PyCompilerFlags *flags,
70 int optimize,
71 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020072PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
73 struct _mod *mod,
74 PyObject *filename,
75 PyCompilerFlags *flags,
76 int optimize,
77 PyArena *arena);
78PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
79 struct _mod * mod,
80 const char *filename /* decoded from the filesystem encoding */
81 );
82PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
83 struct _mod * mod,
84 PyObject *filename
85 );
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000086
Victor Stinner2bdc7f52011-09-29 01:04:08 +020087/* _Py_Mangle is defined in compile.c */
88PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000089
Larry Hastings3a907972013-11-23 14:49:22 -080090#define PY_INVALID_STACK_EFFECT INT_MAX
91PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
Serhiy Storchaka7bdf2822018-09-18 09:54:26 +030092PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
Larry Hastings3a907972013-11-23 14:49:22 -080093
Pablo Galindod112c602020-03-18 23:02:09 +000094typedef struct {
95 int optimize;
96 int ff_features;
97} _PyASTOptimizeState;
98
99PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);
INADA Naoki7ea143a2017-12-14 16:47:20 +0900100
Guido van Rossuma3309961993-07-28 09:05:47 +0000101#ifdef __cplusplus
102}
103#endif
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200104
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000105#endif /* !Py_LIMITED_API */
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200106
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800107/* These definitions must match corresponding definitions in graminit.h. */
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200108#define Py_single_input 256
109#define Py_file_input 257
110#define Py_eval_input 258
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800111#define Py_func_type_input 345
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200112
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100113/* This doesn't need to match anything */
114#define Py_fstring_input 800
115
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200116#endif /* !Py_COMPILE_H */