compile.h 2.88 KB
Newer Older
1 2
#ifndef Py_COMPILE_H
#define Py_COMPILE_H
3

4
#ifndef Py_LIMITED_API
5 6
#include "code.h"

7 8 9 10
#ifdef __cplusplus
extern "C" {
#endif

Guido van Rossum's avatar
Guido van Rossum committed
11
/* Public interface */
12
struct _node; /* Declare the existence of this type */
13
PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
14 15 16 17 18
/* XXX (ncoghlan): Unprefixed type name in a public API! */

#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
                   CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
19
                   CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
20 21 22 23 24 25 26 27 28 29 30
#define PyCF_MASK_OBSOLETE (CO_NESTED)
#define PyCF_SOURCE_IS_UTF8  0x0100
#define PyCF_DONT_IMPLY_DEDENT 0x0200
#define PyCF_ONLY_AST 0x0400
#define PyCF_IGNORE_COOKIE 0x0800

#ifndef Py_LIMITED_API
typedef struct {
    int cf_flags;  /* bitmask of CO_xxx flags relevant to future */
} PyCompilerFlags;
#endif
31

32 33 34
/* Future feature support */

typedef struct {
Jeremy Hylton's avatar
Jeremy Hylton committed
35 36
    int ff_features;      /* flags set by future statements */
    int ff_lineno;        /* line number of last future statement */
37 38 39
} PyFutureFeatures;

#define FUTURE_NESTED_SCOPES "nested_scopes"
40
#define FUTURE_GENERATORS "generators"
41
#define FUTURE_DIVISION "division"
42
#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
43
#define FUTURE_WITH_STATEMENT "with_statement"
44
#define FUTURE_PRINT_FUNCTION "print_function"
45
#define FUTURE_UNICODE_LITERALS "unicode_literals"
46
#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
47
#define FUTURE_GENERATOR_STOP "generator_stop"
48
#define FUTURE_ANNOTATIONS "annotations"
49

Jeremy Hylton's avatar
Jeremy Hylton committed
50
struct _mod; /* Declare the existence of this type */
51
#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
52
PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
53
    struct _mod *mod,
54 55 56 57
    const char *filename,       /* decoded from the filesystem encoding */
    PyCompilerFlags *flags,
    int optimize,
    PyArena *arena);
58 59 60 61 62 63 64 65 66 67 68 69 70 71
PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
    struct _mod *mod,
    PyObject *filename,
    PyCompilerFlags *flags,
    int optimize,
    PyArena *arena);
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
    struct _mod * mod,
    const char *filename        /* decoded from the filesystem encoding */
    );
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
    struct _mod * mod,
    PyObject *filename
    );
Jeremy Hylton's avatar
Jeremy Hylton committed
72

73 74
/* _Py_Mangle is defined in compile.c */
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
Jeremy Hylton's avatar
Jeremy Hylton committed
75

76 77 78
#define PY_INVALID_STACK_EFFECT INT_MAX
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);

79
PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, int optimize);
80

81 82 83
#ifdef __cplusplus
}
#endif
84

85
#endif /* !Py_LIMITED_API */
86 87 88 89 90 91 92 93

/* These definitions must match corresponding definitions in graminit.h.
   There's code in compile.c that checks that they are the same. */
#define Py_single_input 256
#define Py_file_input 257
#define Py_eval_input 258

#endif /* !Py_COMPILE_H */