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