annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/python3.8/symtable.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 #ifndef Py_LIMITED_API
jpayne@69 2 #ifndef Py_SYMTABLE_H
jpayne@69 3 #define Py_SYMTABLE_H
jpayne@69 4 #ifdef __cplusplus
jpayne@69 5 extern "C" {
jpayne@69 6 #endif
jpayne@69 7
jpayne@69 8 #include "Python-ast.h" /* mod_ty */
jpayne@69 9
jpayne@69 10 /* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
jpayne@69 11 * names.
jpayne@69 12 */
jpayne@69 13
jpayne@69 14 typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
jpayne@69 15 _Py_block_ty;
jpayne@69 16
jpayne@69 17 struct _symtable_entry;
jpayne@69 18
jpayne@69 19 struct symtable {
jpayne@69 20 PyObject *st_filename; /* name of file being compiled,
jpayne@69 21 decoded from the filesystem encoding */
jpayne@69 22 struct _symtable_entry *st_cur; /* current symbol table entry */
jpayne@69 23 struct _symtable_entry *st_top; /* symbol table entry for module */
jpayne@69 24 PyObject *st_blocks; /* dict: map AST node addresses
jpayne@69 25 * to symbol table entries */
jpayne@69 26 PyObject *st_stack; /* list: stack of namespace info */
jpayne@69 27 PyObject *st_global; /* borrowed ref to st_top->ste_symbols */
jpayne@69 28 int st_nblocks; /* number of blocks used. kept for
jpayne@69 29 consistency with the corresponding
jpayne@69 30 compiler structure */
jpayne@69 31 PyObject *st_private; /* name of current class or NULL */
jpayne@69 32 PyFutureFeatures *st_future; /* module's future features that affect
jpayne@69 33 the symbol table */
jpayne@69 34 int recursion_depth; /* current recursion depth */
jpayne@69 35 int recursion_limit; /* recursion limit */
jpayne@69 36 };
jpayne@69 37
jpayne@69 38 typedef struct _symtable_entry {
jpayne@69 39 PyObject_HEAD
jpayne@69 40 PyObject *ste_id; /* int: key in ste_table->st_blocks */
jpayne@69 41 PyObject *ste_symbols; /* dict: variable names to flags */
jpayne@69 42 PyObject *ste_name; /* string: name of current block */
jpayne@69 43 PyObject *ste_varnames; /* list of function parameters */
jpayne@69 44 PyObject *ste_children; /* list of child blocks */
jpayne@69 45 PyObject *ste_directives;/* locations of global and nonlocal statements */
jpayne@69 46 _Py_block_ty ste_type; /* module, class, or function */
jpayne@69 47 int ste_nested; /* true if block is nested */
jpayne@69 48 unsigned ste_free : 1; /* true if block has free variables */
jpayne@69 49 unsigned ste_child_free : 1; /* true if a child block has free vars,
jpayne@69 50 including free refs to globals */
jpayne@69 51 unsigned ste_generator : 1; /* true if namespace is a generator */
jpayne@69 52 unsigned ste_coroutine : 1; /* true if namespace is a coroutine */
jpayne@69 53 unsigned ste_comprehension : 1; /* true if namespace is a list comprehension */
jpayne@69 54 unsigned ste_varargs : 1; /* true if block has varargs */
jpayne@69 55 unsigned ste_varkeywords : 1; /* true if block has varkeywords */
jpayne@69 56 unsigned ste_returns_value : 1; /* true if namespace uses return with
jpayne@69 57 an argument */
jpayne@69 58 unsigned ste_needs_class_closure : 1; /* for class scopes, true if a
jpayne@69 59 closure over __class__
jpayne@69 60 should be created */
jpayne@69 61 unsigned ste_comp_iter_target : 1; /* true if visiting comprehension target */
jpayne@69 62 int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
jpayne@69 63 int ste_lineno; /* first line of block */
jpayne@69 64 int ste_col_offset; /* offset of first line of block */
jpayne@69 65 int ste_opt_lineno; /* lineno of last exec or import * */
jpayne@69 66 int ste_opt_col_offset; /* offset of last exec or import * */
jpayne@69 67 struct symtable *ste_table;
jpayne@69 68 } PySTEntryObject;
jpayne@69 69
jpayne@69 70 PyAPI_DATA(PyTypeObject) PySTEntry_Type;
jpayne@69 71
jpayne@69 72 #define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type)
jpayne@69 73
jpayne@69 74 PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
jpayne@69 75
jpayne@69 76 PyAPI_FUNC(struct symtable *) PySymtable_Build(
jpayne@69 77 mod_ty mod,
jpayne@69 78 const char *filename, /* decoded from the filesystem encoding */
jpayne@69 79 PyFutureFeatures *future);
jpayne@69 80 PyAPI_FUNC(struct symtable *) PySymtable_BuildObject(
jpayne@69 81 mod_ty mod,
jpayne@69 82 PyObject *filename,
jpayne@69 83 PyFutureFeatures *future);
jpayne@69 84 PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
jpayne@69 85
jpayne@69 86 PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
jpayne@69 87
jpayne@69 88 /* Flags for def-use information */
jpayne@69 89
jpayne@69 90 #define DEF_GLOBAL 1 /* global stmt */
jpayne@69 91 #define DEF_LOCAL 2 /* assignment in code block */
jpayne@69 92 #define DEF_PARAM 2<<1 /* formal parameter */
jpayne@69 93 #define DEF_NONLOCAL 2<<2 /* nonlocal stmt */
jpayne@69 94 #define USE 2<<3 /* name is used */
jpayne@69 95 #define DEF_FREE 2<<4 /* name used but not defined in nested block */
jpayne@69 96 #define DEF_FREE_CLASS 2<<5 /* free variable from class's method */
jpayne@69 97 #define DEF_IMPORT 2<<6 /* assignment occurred via import */
jpayne@69 98 #define DEF_ANNOT 2<<7 /* this name is annotated */
jpayne@69 99 #define DEF_COMP_ITER 2<<8 /* this name is a comprehension iteration variable */
jpayne@69 100
jpayne@69 101 #define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
jpayne@69 102
jpayne@69 103 /* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
jpayne@69 104 table. GLOBAL is returned from PyST_GetScope() for either of them.
jpayne@69 105 It is stored in ste_symbols at bits 12-15.
jpayne@69 106 */
jpayne@69 107 #define SCOPE_OFFSET 11
jpayne@69 108 #define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
jpayne@69 109
jpayne@69 110 #define LOCAL 1
jpayne@69 111 #define GLOBAL_EXPLICIT 2
jpayne@69 112 #define GLOBAL_IMPLICIT 3
jpayne@69 113 #define FREE 4
jpayne@69 114 #define CELL 5
jpayne@69 115
jpayne@69 116 #define GENERATOR 1
jpayne@69 117 #define GENERATOR_EXPRESSION 2
jpayne@69 118
jpayne@69 119 #ifdef __cplusplus
jpayne@69 120 }
jpayne@69 121 #endif
jpayne@69 122 #endif /* !Py_SYMTABLE_H */
jpayne@69 123 #endif /* !Py_LIMITED_API */