File indexing completed on 2025-11-19 09:50:50
0001 #ifndef Py_INTERNAL_SYMTABLE_H
0002 #define Py_INTERNAL_SYMTABLE_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 struct _mod;
0012
0013 typedef enum _block_type {
0014 FunctionBlock, ClassBlock, ModuleBlock,
0015
0016
0017 AnnotationBlock,
0018
0019
0020
0021
0022
0023
0024
0025
0026 TypeAliasBlock,
0027
0028
0029 TypeParametersBlock,
0030
0031
0032
0033
0034 TypeVariableBlock,
0035 } _Py_block_ty;
0036
0037 typedef enum _comprehension_type {
0038 NoComprehension = 0,
0039 ListComprehension = 1,
0040 DictComprehension = 2,
0041 SetComprehension = 3,
0042 GeneratorExpression = 4 } _Py_comprehension_ty;
0043
0044
0045 typedef struct {
0046 int lineno;
0047 int end_lineno;
0048 int col_offset;
0049 int end_col_offset;
0050 } _Py_SourceLocation;
0051
0052 #define SRC_LOCATION_FROM_AST(n) \
0053 (_Py_SourceLocation){ \
0054 .lineno = (n)->lineno, \
0055 .end_lineno = (n)->end_lineno, \
0056 .col_offset = (n)->col_offset, \
0057 .end_col_offset = (n)->end_col_offset }
0058
0059 static const _Py_SourceLocation NO_LOCATION = {-1, -1, -1, -1};
0060
0061
0062 typedef struct {
0063 int ff_features;
0064 _Py_SourceLocation ff_location;
0065 } _PyFutureFeatures;
0066
0067 struct _symtable_entry;
0068
0069 struct symtable {
0070 PyObject *st_filename;
0071
0072 struct _symtable_entry *st_cur;
0073 struct _symtable_entry *st_top;
0074 PyObject *st_blocks;
0075
0076 PyObject *st_stack;
0077 PyObject *st_global;
0078 int st_nblocks;
0079
0080
0081 PyObject *st_private;
0082 _PyFutureFeatures *st_future;
0083
0084 int recursion_depth;
0085 int recursion_limit;
0086 };
0087
0088 typedef struct _symtable_entry {
0089 PyObject_HEAD
0090 PyObject *ste_id;
0091 PyObject *ste_symbols;
0092 PyObject *ste_name;
0093 PyObject *ste_varnames;
0094 PyObject *ste_children;
0095 PyObject *ste_directives;
0096 PyObject *ste_mangled_names;
0097
0098 _Py_block_ty ste_type;
0099
0100
0101
0102
0103
0104
0105 const char *ste_scope_info;
0106
0107 int ste_nested;
0108 unsigned ste_free : 1;
0109 unsigned ste_child_free : 1;
0110
0111 unsigned ste_generator : 1;
0112 unsigned ste_coroutine : 1;
0113 _Py_comprehension_ty ste_comprehension;
0114 unsigned ste_varargs : 1;
0115 unsigned ste_varkeywords : 1;
0116 unsigned ste_returns_value : 1;
0117
0118 unsigned ste_needs_class_closure : 1;
0119
0120
0121 unsigned ste_needs_classdict : 1;
0122
0123 unsigned ste_comp_inlined : 1;
0124 unsigned ste_comp_iter_target : 1;
0125 unsigned ste_can_see_class_scope : 1;
0126
0127 int ste_comp_iter_expr;
0128 int ste_lineno;
0129 int ste_col_offset;
0130 int ste_end_lineno;
0131 int ste_end_col_offset;
0132 int ste_opt_lineno;
0133 int ste_opt_col_offset;
0134 struct symtable *ste_table;
0135 } PySTEntryObject;
0136
0137 extern PyTypeObject PySTEntry_Type;
0138
0139 #define PySTEntry_Check(op) Py_IS_TYPE((op), &PySTEntry_Type)
0140
0141 extern long _PyST_GetSymbol(PySTEntryObject *, PyObject *);
0142 extern int _PyST_GetScope(PySTEntryObject *, PyObject *);
0143 extern int _PyST_IsFunctionLike(PySTEntryObject *);
0144
0145 extern struct symtable* _PySymtable_Build(
0146 struct _mod *mod,
0147 PyObject *filename,
0148 _PyFutureFeatures *future);
0149 extern PySTEntryObject* _PySymtable_Lookup(struct symtable *, void *);
0150
0151 extern void _PySymtable_Free(struct symtable *);
0152
0153 extern PyObject *_Py_MaybeMangle(PyObject *privateobj, PySTEntryObject *ste, PyObject *name);
0154 extern PyObject* _Py_Mangle(PyObject *p, PyObject *name);
0155
0156
0157
0158 #define DEF_GLOBAL 1
0159 #define DEF_LOCAL 2
0160 #define DEF_PARAM (2<<1)
0161 #define DEF_NONLOCAL (2<<2)
0162 #define USE (2<<3)
0163 #define DEF_FREE (2<<4)
0164 #define DEF_FREE_CLASS (2<<5)
0165 #define DEF_IMPORT (2<<6)
0166 #define DEF_ANNOT (2<<7)
0167 #define DEF_COMP_ITER (2<<8)
0168 #define DEF_TYPE_PARAM (2<<9)
0169 #define DEF_COMP_CELL (2<<10)
0170
0171 #define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
0172
0173
0174
0175
0176
0177 #define SCOPE_OFFSET 12
0178 #define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
0179
0180 #define LOCAL 1
0181 #define GLOBAL_EXPLICIT 2
0182 #define GLOBAL_IMPLICIT 3
0183 #define FREE 4
0184 #define CELL 5
0185
0186 #define GENERATOR 1
0187 #define GENERATOR_EXPRESSION 2
0188
0189
0190 extern struct symtable* _Py_SymtableStringObjectFlags(
0191 const char *str,
0192 PyObject *filename,
0193 int start,
0194 PyCompilerFlags *flags);
0195
0196 int _PyFuture_FromAST(
0197 struct _mod * mod,
0198 PyObject *filename,
0199 _PyFutureFeatures* futures);
0200
0201 #ifdef __cplusplus
0202 }
0203 #endif
0204 #endif