blob: edb961f4d72042fb177d84effb0d94c5bfb33304 [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#include "code.h"
6
Fred Drakeea9cb5a2000-07-09 00:20:36 +00007#ifdef __cplusplus
8extern "C" {
9#endif
10
Guido van Rossum3f5da241990-12-20 15:06:42 +000011/* Public interface */
Guido van Rossume543a941991-04-03 19:00:55 +000012struct _node; /* Declare the existence of this type */
Martin v. Löwis95292d62002-12-11 14:04:59 +000013PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
Eric Snow6b4be192017-05-22 21:36:03 -070014/* XXX (ncoghlan): Unprefixed type name in a public API! */
15
16#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
17 CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
18 CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
Guido van Rossum95e4d582018-01-26 08:20:18 -080019 CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
Eric Snow6b4be192017-05-22 21:36:03 -070020#define PyCF_MASK_OBSOLETE (CO_NESTED)
21#define PyCF_SOURCE_IS_UTF8 0x0100
22#define PyCF_DONT_IMPLY_DEDENT 0x0200
23#define PyCF_ONLY_AST 0x0400
24#define PyCF_IGNORE_COOKIE 0x0800
25
26#ifndef Py_LIMITED_API
27typedef struct {
28 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
29} PyCompilerFlags;
30#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000031
Jeremy Hylton4db62b12001-02-27 19:07:02 +000032/* Future feature support */
33
34typedef struct {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000035 int ff_features; /* flags set by future statements */
36 int ff_lineno; /* line number of last future statement */
Jeremy Hylton4db62b12001-02-27 19:07:02 +000037} PyFutureFeatures;
38
Jeremy Hylton4db62b12001-02-27 19:07:02 +000039#define FUTURE_NESTED_SCOPES "nested_scopes"
Guido van Rossumb09f7ed2001-07-15 21:08:29 +000040#define FUTURE_GENERATORS "generators"
Guido van Rossum4668b002001-08-08 05:00:18 +000041#define FUTURE_DIVISION "division"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000042#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
Thomas Wouters34aa7ba2006-02-28 19:02:24 +000043#define FUTURE_WITH_STATEMENT "with_statement"
Eric Smith87824082008-03-20 23:02:08 +000044#define FUTURE_PRINT_FUNCTION "print_function"
Christian Heimes4d6ec852008-03-26 22:34:47 +000045#define FUTURE_UNICODE_LITERALS "unicode_literals"
Brett Cannone3944a52009-04-01 05:08:41 +000046#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
Yury Selivanov8170e8c2015-05-09 11:44:30 -040047#define FUTURE_GENERATOR_STOP "generator_stop"
Guido van Rossum95e4d582018-01-26 08:20:18 -080048#define FUTURE_ANNOTATIONS "annotations"
Guido van Rossum4668b002001-08-08 05:00:18 +000049
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000050struct _mod; /* Declare the existence of this type */
Georg Brandl8334fd92010-12-04 10:26:46 +000051#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
Victor Stinner00676d12010-12-27 01:49:31 +000052PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
Victor Stinner0d711162010-12-27 02:39:20 +000053 struct _mod *mod,
Victor Stinner00676d12010-12-27 01:49:31 +000054 const char *filename, /* decoded from the filesystem encoding */
55 PyCompilerFlags *flags,
56 int optimize,
57 PyArena *arena);
Victor Stinner14e461d2013-08-26 22:28:21 +020058PyAPI_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 );
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000072
Victor Stinner2bdc7f52011-09-29 01:04:08 +020073/* _Py_Mangle is defined in compile.c */
74PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000075
Larry Hastings3a907972013-11-23 14:49:22 -080076#define PY_INVALID_STACK_EFFECT INT_MAX
77PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
78
Serhiy Storchaka3dfbaf52017-12-25 12:47:50 +020079PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, int optimize);
INADA Naoki7ea143a2017-12-14 16:47:20 +090080
Guido van Rossuma3309961993-07-28 09:05:47 +000081#ifdef __cplusplus
82}
83#endif
Victor Stinner2bdc7f52011-09-29 01:04:08 +020084
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000085#endif /* !Py_LIMITED_API */
Victor Stinner2bdc7f52011-09-29 01:04:08 +020086
87/* These definitions must match corresponding definitions in graminit.h.
88 There's code in compile.c that checks that they are the same. */
89#define Py_single_input 256
90#define Py_file_input 257
91#define Py_eval_input 258
92
93#endif /* !Py_COMPILE_H */