1 #ifndef Py_COMPILE_H 2 #define Py_COMPILE_H 3 4 #ifndef Py_LIMITED_API 5 #include "code.h" 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 /* Public interface */ 12 struct _node; /* Declare the existence of this type */ 13 PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *); 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 | \ 19 CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS) 20 #define PyCF_MASK_OBSOLETE (CO_NESTED) 21 22 /* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique. 23 PyCF_ constants can use bits from 0x0100 to 0x10000. 24 CO_FUTURE_ constants use bits starting at 0x20000. */ 25 #define PyCF_SOURCE_IS_UTF8 0x0100 26 #define PyCF_DONT_IMPLY_DEDENT 0x0200 27 #define PyCF_ONLY_AST 0x0400 28 #define PyCF_IGNORE_COOKIE 0x0800 29 #define PyCF_TYPE_COMMENTS 0x1000 30 #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000 31 #define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \ 32 PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT) 33 34 #ifndef Py_LIMITED_API 35 typedef struct { 36 int cf_flags; /* bitmask of CO_xxx flags relevant to future */ 37 int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */ 38 } PyCompilerFlags; 39 40 #define _PyCompilerFlags_INIT \ 41 (PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION} 42 #endif 43 44 /* Future feature support */ 45 46 typedef struct { 47 int ff_features; /* flags set by future statements */ 48 int ff_lineno; /* line number of last future statement */ 49 } PyFutureFeatures; 50 51 #define FUTURE_NESTED_SCOPES "nested_scopes" 52 #define FUTURE_GENERATORS "generators" 53 #define FUTURE_DIVISION "division" 54 #define FUTURE_ABSOLUTE_IMPORT "absolute_import" 55 #define FUTURE_WITH_STATEMENT "with_statement" 56 #define FUTURE_PRINT_FUNCTION "print_function" 57 #define FUTURE_UNICODE_LITERALS "unicode_literals" 58 #define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL" 59 #define FUTURE_GENERATOR_STOP "generator_stop" 60 #define FUTURE_ANNOTATIONS "annotations" 61 62 struct _mod; /* Declare the existence of this type */ 63 #define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar) 64 PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx( 65 struct _mod *mod, 66 const char *filename, /* decoded from the filesystem encoding */ 67 PyCompilerFlags *flags, 68 int optimize, 69 PyArena *arena); 70 PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject( 71 struct _mod *mod, 72 PyObject *filename, 73 PyCompilerFlags *flags, 74 int optimize, 75 PyArena *arena); 76 PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST( 77 struct _mod * mod, 78 const char *filename /* decoded from the filesystem encoding */ 79 ); 80 PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject( 81 struct _mod * mod, 82 PyObject *filename 83 ); 84 85 /* _Py_Mangle is defined in compile.c */ 86 PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name); 87 88 #define PY_INVALID_STACK_EFFECT INT_MAX 89 PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); 90 PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); 91 92 PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, int optimize); 93 94 #ifdef __cplusplus 95 } 96 #endif 97 98 #endif /* !Py_LIMITED_API */ 99 100 /* These definitions must match corresponding definitions in graminit.h. */ 101 #define Py_single_input 256 102 #define Py_file_input 257 103 #define Py_eval_input 258 104 #define Py_func_type_input 345 105 106 #endif /* !Py_COMPILE_H */ 107