blob: 12417ce805464b9f6ffa11a84ec125ae529b58e4 [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 */
Martin v. Löwis95292d62002-12-11 14:04:59 +000012PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
Eric Snow6b4be192017-05-22 21:36:03 -070013/* XXX (ncoghlan): Unprefixed type name in a public API! */
14
15#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
16 CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
17 CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
Guido van Rossum95e4d582018-01-26 08:20:18 -080018 CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
Eric Snow6b4be192017-05-22 21:36:03 -070019#define PyCF_MASK_OBSOLETE (CO_NESTED)
Batuhan Taşkaya44540572020-04-22 19:09:03 +030020
21/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
22 PyCF_ constants can use bits from 0x0100 to 0x10000.
23 CO_FUTURE_ constants use bits starting at 0x20000. */
Eric Snow6b4be192017-05-22 21:36:03 -070024#define PyCF_SOURCE_IS_UTF8 0x0100
25#define PyCF_DONT_IMPLY_DEDENT 0x0200
26#define PyCF_ONLY_AST 0x0400
27#define PyCF_IGNORE_COOKIE 0x0800
Guido van Rossumdcfcd142019-01-31 03:40:27 -080028#define PyCF_TYPE_COMMENTS 0x1000
Matthias Bussonnier565b4f12019-05-21 13:12:03 -070029#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
Batuhan Taşkaya44540572020-04-22 19:09:03 +030030#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
31 PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
Eric Snow6b4be192017-05-22 21:36:03 -070032
33#ifndef Py_LIMITED_API
34typedef struct {
35 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
Guido van Rossum495da292019-03-07 12:38:08 -080036 int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
Eric Snow6b4be192017-05-22 21:36:03 -070037} PyCompilerFlags;
Victor Stinner37d66d72019-06-13 02:16:41 +020038
39#define _PyCompilerFlags_INIT \
40 (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
Eric Snow6b4be192017-05-22 21:36:03 -070041#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000042
Jeremy Hylton4db62b12001-02-27 19:07:02 +000043/* Future feature support */
44
45typedef struct {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000046 int ff_features; /* flags set by future statements */
47 int ff_lineno; /* line number of last future statement */
Jeremy Hylton4db62b12001-02-27 19:07:02 +000048} PyFutureFeatures;
49
Jeremy Hylton4db62b12001-02-27 19:07:02 +000050#define FUTURE_NESTED_SCOPES "nested_scopes"
Guido van Rossumb09f7ed2001-07-15 21:08:29 +000051#define FUTURE_GENERATORS "generators"
Guido van Rossum4668b002001-08-08 05:00:18 +000052#define FUTURE_DIVISION "division"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000053#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
Thomas Wouters34aa7ba2006-02-28 19:02:24 +000054#define FUTURE_WITH_STATEMENT "with_statement"
Eric Smith87824082008-03-20 23:02:08 +000055#define FUTURE_PRINT_FUNCTION "print_function"
Christian Heimes4d6ec852008-03-26 22:34:47 +000056#define FUTURE_UNICODE_LITERALS "unicode_literals"
Brett Cannone3944a52009-04-01 05:08:41 +000057#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
Yury Selivanov8170e8c2015-05-09 11:44:30 -040058#define FUTURE_GENERATOR_STOP "generator_stop"
Guido van Rossum95e4d582018-01-26 08:20:18 -080059#define FUTURE_ANNOTATIONS "annotations"
Guido van Rossum4668b002001-08-08 05:00:18 +000060
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000061struct _mod; /* Declare the existence of this type */
Georg Brandl8334fd92010-12-04 10:26:46 +000062#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
Victor Stinner00676d12010-12-27 01:49:31 +000063PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
Victor Stinner0d711162010-12-27 02:39:20 +000064 struct _mod *mod,
Victor Stinner00676d12010-12-27 01:49:31 +000065 const char *filename, /* decoded from the filesystem encoding */
66 PyCompilerFlags *flags,
67 int optimize,
68 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020069PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
70 struct _mod *mod,
71 PyObject *filename,
72 PyCompilerFlags *flags,
73 int optimize,
74 PyArena *arena);
75PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
76 struct _mod * mod,
77 const char *filename /* decoded from the filesystem encoding */
78 );
79PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
80 struct _mod * mod,
81 PyObject *filename
82 );
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000083
Victor Stinner2bdc7f52011-09-29 01:04:08 +020084/* _Py_Mangle is defined in compile.c */
85PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000086
Larry Hastings3a907972013-11-23 14:49:22 -080087#define PY_INVALID_STACK_EFFECT INT_MAX
88PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
Serhiy Storchaka7bdf2822018-09-18 09:54:26 +030089PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
Larry Hastings3a907972013-11-23 14:49:22 -080090
Pablo Galindod112c602020-03-18 23:02:09 +000091typedef struct {
92 int optimize;
93 int ff_features;
94} _PyASTOptimizeState;
95
96PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);
INADA Naoki7ea143a2017-12-14 16:47:20 +090097
Guido van Rossuma3309961993-07-28 09:05:47 +000098#ifdef __cplusplus
99}
100#endif
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200101
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000102#endif /* !Py_LIMITED_API */
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200103
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800104/* These definitions must match corresponding definitions in graminit.h. */
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200105#define Py_single_input 256
106#define Py_file_input 257
107#define Py_eval_input 258
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800108#define Py_func_type_input 345
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200109
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100110/* This doesn't need to match anything */
111#define Py_fstring_input 800
112
Victor Stinner2bdc7f52011-09-29 01:04:08 +0200113#endif /* !Py_COMPILE_H */