Saved and restored logging._handlerList at the same time as saving/restoring logging...
[python.git] / Include / symtable.h
blobfefe08bb31b3b9637b00a1fe5d86e95d73e42974
1 #ifndef Py_SYMTABLE_H
2 #define Py_SYMTABLE_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
7 typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
8 _Py_block_ty;
10 struct _symtable_entry;
12 struct symtable {
13 const char *st_filename; /* name of file being compiled */
14 struct _symtable_entry *st_cur; /* current symbol table entry */
15 struct _symtable_entry *st_top; /* module entry */
16 PyObject *st_symbols; /* dictionary of symbol table entries */
17 PyObject *st_stack; /* stack of namespace info */
18 PyObject *st_global; /* borrowed ref to MODULE in st_symbols */
19 int st_nblocks; /* number of blocks */
20 PyObject *st_private; /* name of current class or NULL */
21 int st_tmpname; /* temporary name counter */
22 PyFutureFeatures *st_future; /* module's future features */
25 typedef struct _symtable_entry {
26 PyObject_HEAD
27 PyObject *ste_id; /* int: key in st_symbols */
28 PyObject *ste_symbols; /* dict: name to flags */
29 PyObject *ste_name; /* string: name of block */
30 PyObject *ste_varnames; /* list of variable names */
31 PyObject *ste_children; /* list of child ids */
32 _Py_block_ty ste_type; /* module, class, or function */
33 int ste_unoptimized; /* false if namespace is optimized */
34 unsigned ste_nested : 1; /* true if block is nested */
35 unsigned ste_free : 1; /* true if block has free variables */
36 unsigned ste_child_free : 1; /* true if a child block has free vars,
37 including free refs to globals */
38 unsigned ste_generator : 1; /* true if namespace is a generator */
39 unsigned ste_varargs : 1; /* true if block has varargs */
40 unsigned ste_varkeywords : 1; /* true if block has varkeywords */
41 int ste_lineno; /* first line of block */
42 int ste_opt_lineno; /* lineno of last exec or import * */
43 int ste_tmpname; /* counter for listcomp temp vars */
44 struct symtable *ste_table;
45 } PySTEntryObject;
47 PyAPI_DATA(PyTypeObject) PySTEntry_Type;
49 #define PySTEntry_Check(op) ((op)->ob_type == &PySTEntry_Type)
51 PyAPI_FUNC(PySTEntryObject *) \
52 PySTEntry_New(struct symtable *, identifier, _Py_block_ty, void *, int);
53 PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
55 PyAPI_FUNC(struct symtable *) PySymtable_Build(mod_ty, const char *,
56 PyFutureFeatures *);
57 PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
59 PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
61 /* Flags for def-use information */
63 #define DEF_GLOBAL 1 /* global stmt */
64 #define DEF_LOCAL 2 /* assignment in code block */
65 #define DEF_PARAM 2<<1 /* formal parameter */
66 #define USE 2<<2 /* name is used */
67 #define DEF_STAR 2<<3 /* parameter is star arg */
68 #define DEF_DOUBLESTAR 2<<4 /* parameter is star-star arg */
69 #define DEF_INTUPLE 2<<5 /* name defined in tuple in parameters */
70 #define DEF_FREE 2<<6 /* name used but not defined in nested block */
71 #define DEF_FREE_GLOBAL 2<<7 /* free variable is actually implicit global */
72 #define DEF_FREE_CLASS 2<<8 /* free variable from class's method */
73 #define DEF_IMPORT 2<<9 /* assignment occurred via import */
75 #define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
77 /* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
78 table. GLOBAL is returned from PyST_GetScope() for either of them.
79 It is stored in ste_symbols at bits 12-14.
81 #define SCOPE_OFF 11
82 #define SCOPE_MASK 7
84 #define LOCAL 1
85 #define GLOBAL_EXPLICIT 2
86 #define GLOBAL_IMPLICIT 3
87 #define FREE 4
88 #define CELL 5
90 /* The following three names are used for the ste_unoptimized bit field */
91 #define OPT_IMPORT_STAR 1
92 #define OPT_EXEC 2
93 #define OPT_BARE_EXEC 4
94 #define OPT_TOPLEVEL 8 /* top-level names, including eval and exec */
96 #define GENERATOR 1
97 #define GENERATOR_EXPRESSION 2
99 #ifdef __cplusplus
101 #endif
102 #endif /* !Py_SYMTABLE_H */