Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 1 | #ifndef Py_COMPILE_H |
| 2 | #define Py_COMPILE_H |
Thomas Wouters | ca82a8b | 2006-02-28 23:09:08 +0000 | [diff] [blame] | 3 | |
Victor Stinner | 2bdc7f5 | 2011-09-29 01:04:08 +0200 | [diff] [blame] | 4 | #ifndef Py_LIMITED_API |
Thomas Wouters | ca82a8b | 2006-02-28 23:09:08 +0000 | [diff] [blame] | 5 | #include "code.h" |
| 6 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 11 | /* Public interface */ |
Guido van Rossum | e543a94 | 1991-04-03 19:00:55 +0000 | [diff] [blame] | 12 | struct _node; /* Declare the existence of this type */ |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 13 | PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *); |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 14 | /* 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 Rossum | 95e4d58 | 2018-01-26 08:20:18 -0800 | [diff] [blame] | 19 | CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS) |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 20 | #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 |
| 27 | typedef struct { |
| 28 | int cf_flags; /* bitmask of CO_xxx flags relevant to future */ |
| 29 | } PyCompilerFlags; |
| 30 | #endif |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 31 | |
Jeremy Hylton | 4db62b1 | 2001-02-27 19:07:02 +0000 | [diff] [blame] | 32 | /* Future feature support */ |
| 33 | |
| 34 | typedef struct { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 35 | int ff_features; /* flags set by future statements */ |
| 36 | int ff_lineno; /* line number of last future statement */ |
Jeremy Hylton | 4db62b1 | 2001-02-27 19:07:02 +0000 | [diff] [blame] | 37 | } PyFutureFeatures; |
| 38 | |
Jeremy Hylton | 4db62b1 | 2001-02-27 19:07:02 +0000 | [diff] [blame] | 39 | #define FUTURE_NESTED_SCOPES "nested_scopes" |
Guido van Rossum | b09f7ed | 2001-07-15 21:08:29 +0000 | [diff] [blame] | 40 | #define FUTURE_GENERATORS "generators" |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 41 | #define FUTURE_DIVISION "division" |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 42 | #define FUTURE_ABSOLUTE_IMPORT "absolute_import" |
Thomas Wouters | 34aa7ba | 2006-02-28 19:02:24 +0000 | [diff] [blame] | 43 | #define FUTURE_WITH_STATEMENT "with_statement" |
Eric Smith | 8782408 | 2008-03-20 23:02:08 +0000 | [diff] [blame] | 44 | #define FUTURE_PRINT_FUNCTION "print_function" |
Christian Heimes | 4d6ec85 | 2008-03-26 22:34:47 +0000 | [diff] [blame] | 45 | #define FUTURE_UNICODE_LITERALS "unicode_literals" |
Brett Cannon | e3944a5 | 2009-04-01 05:08:41 +0000 | [diff] [blame] | 46 | #define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL" |
Yury Selivanov | 8170e8c | 2015-05-09 11:44:30 -0400 | [diff] [blame] | 47 | #define FUTURE_GENERATOR_STOP "generator_stop" |
Guido van Rossum | 95e4d58 | 2018-01-26 08:20:18 -0800 | [diff] [blame] | 48 | #define FUTURE_ANNOTATIONS "annotations" |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 49 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 50 | struct _mod; /* Declare the existence of this type */ |
Georg Brandl | 8334fd9 | 2010-12-04 10:26:46 +0000 | [diff] [blame] | 51 | #define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar) |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 52 | PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx( |
Victor Stinner | 0d71116 | 2010-12-27 02:39:20 +0000 | [diff] [blame] | 53 | struct _mod *mod, |
Victor Stinner | 00676d1 | 2010-12-27 01:49:31 +0000 | [diff] [blame] | 54 | const char *filename, /* decoded from the filesystem encoding */ |
| 55 | PyCompilerFlags *flags, |
| 56 | int optimize, |
| 57 | PyArena *arena); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 58 | PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject( |
| 59 | struct _mod *mod, |
| 60 | PyObject *filename, |
| 61 | PyCompilerFlags *flags, |
| 62 | int optimize, |
| 63 | PyArena *arena); |
| 64 | PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST( |
| 65 | struct _mod * mod, |
| 66 | const char *filename /* decoded from the filesystem encoding */ |
| 67 | ); |
| 68 | PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject( |
| 69 | struct _mod * mod, |
| 70 | PyObject *filename |
| 71 | ); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 72 | |
Victor Stinner | 2bdc7f5 | 2011-09-29 01:04:08 +0200 | [diff] [blame] | 73 | /* _Py_Mangle is defined in compile.c */ |
| 74 | PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 75 | |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 76 | #define PY_INVALID_STACK_EFFECT INT_MAX |
| 77 | PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); |
| 78 | |
Serhiy Storchaka | 3dfbaf5 | 2017-12-25 12:47:50 +0200 | [diff] [blame] | 79 | PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, int optimize); |
INADA Naoki | 7ea143a | 2017-12-14 16:47:20 +0900 | [diff] [blame] | 80 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 81 | #ifdef __cplusplus |
| 82 | } |
| 83 | #endif |
Victor Stinner | 2bdc7f5 | 2011-09-29 01:04:08 +0200 | [diff] [blame] | 84 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 85 | #endif /* !Py_LIMITED_API */ |
Victor Stinner | 2bdc7f5 | 2011-09-29 01:04:08 +0200 | [diff] [blame] | 86 | |
| 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 */ |