Home | History | Annotate | Download | only in Python

Lines Matching refs:st

21 ste_new(struct symtable *st, identifier name, _Py_block_ty block,

35 ste->ste_table = st;
67 if (st->st_cur != NULL &&
68 (st->st_cur->ste_nested ||
69 st->st_cur->ste_type == FunctionBlock))
75 if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0)
164 static int symtable_analyze(struct symtable *st);
165 static int symtable_warn(struct symtable *st, char *msg, int lineno);
166 static int symtable_enter_block(struct symtable *st, identifier name,
168 static int symtable_exit_block(struct symtable *st, void *ast);
169 static int symtable_visit_stmt(struct symtable *st, stmt_ty s);
170 static int symtable_visit_expr(struct symtable *st, expr_ty s);
171 static int symtable_visit_genexp(struct symtable *st, expr_ty s);
172 static int symtable_visit_setcomp(struct symtable *st, expr_ty e);
173 static int symtable_visit_dictcomp(struct symtable *st, expr_ty e);
174 static int symtable_visit_arguments(struct symtable *st, arguments_ty);
175 static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
176 static int symtable_visit_alias(struct symtable *st, alias_ty);
177 static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
178 static int symtable_visit_keyword(struct symtable *st, keyword_ty);
179 static int symtable_visit_slice(struct symtable *st, slice_ty);
180 static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top);
181 static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args);
182 static int symtable_implicit_arg(struct symtable *st, int pos);
197 struct symtable *st;
199 st = (struct symtable *)PyMem_Malloc(sizeof(struct symtable));
200 if (st == NULL)
203 st->st_filename = NULL;
204 st->st_symbols = NULL;
206 if ((st->st_stack = PyList_New(0)) == NULL)
208 if ((st->st_symbols = PyDict_New()) == NULL)
210 st->st_cur = NULL;
211 st->st_private = NULL;
212 return st;
214 PySymtable_Free(st);
221 struct symtable *st = symtable_new();
225 if (st == NULL)
226 return st;
227 st->st_filename = filename;
228 st->st_future = future;
230 !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0)) {
231 PySymtable_Free(st);
235 st->st_top = st->st_cur;
236 st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
242 if (!symtable_visit_stmt(st,
247 if (!symtable_visit_expr(st, mod->v.Expression.body))
253 if (!symtable_visit_stmt(st,
262 if (!symtable_exit_block(st, (void *)mod)) {
263 PySymtable_Free(st);
266 if (symtable_analyze(st))
267 return st;
268 PySymtable_Free(st);
271 (void) symtable_exit_block(st, (void *)mod);
272 PySymtable_Free(st);
277 PySymtable_Free(struct symtable *st)
279 Py_XDECREF(st->st_symbols);
280 Py_XDECREF(st->st_stack);
281 PyMem_Free((void *)st);
285 PySymtable_Lookup(struct symtable *st, void *key)
292 v = PyDict_GetItem(st->st_symbols, k);
778 symtable_analyze(struct symtable *st)
791 r = analyze_block(st->st_top, NULL, free, global);
799 symtable_warn(struct symtable *st, char *msg, int lineno)
801 if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
805 PyErr_SyntaxLocation(st->st_filename,
806 st->st_cur->ste_lineno);
819 symtable_exit_block(struct symtable *st, void *ast)
823 Py_CLEAR(st->st_cur);
824 end = PyList_GET_SIZE(st->st_stack) - 1;
826 st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack,
828 if (st->st_cur == NULL)
830 Py_INCREF(st->st_cur);
831 if (PySequence_DelItem(st->st_stack, end) < 0)
838 symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
843 if (st->st_cur) {
844 prev = st->st_cur;
845 if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
848 Py_DECREF(st->st_cur);
850 st->st_cur = ste_new(st, name, block, ast, lineno);
851 if (st->st_cur == NULL)
854 st->st_global = st->st_cur->ste_symbols;
857 (PyObject *)st->st_cur) < 0) {
865 symtable_lookup(struct symtable *st, PyObject *name)
868 PyObject *mangled = _Py_Mangle(st->st_private, name);
871 o = PyDict_GetItem(st->st_cur->ste_symbols, mangled);
879 symtable_add_def(struct symtable *st, PyObject *name, int flag)
884 PyObject *mangled = _Py_Mangle(st->st_private, name);
888 dict = st->st_cur->ste_symbols;
895 PyErr_SyntaxLocation(st->st_filename,
896 st->st_cur->ste_lineno);
912 if (PyList_Append(st->st_cur->ste_varnames, mangled) < 0)
918 if ((o = PyDict_GetItem(st->st_global, mangled))) {
924 if (PyDict_SetItem(st->st_global, mangled, o) < 0) {
946 #define VISIT(ST, TYPE, V) \
947 if (!symtable_visit_ ## TYPE((ST), (V))) \
950 #define VISIT_IN_BLOCK(ST, TYPE, V, S) \
951 if (!symtable_visit_ ## TYPE((ST), (V))) { \
952 symtable_exit_block((ST), (S)); \
956 #define VISIT_SEQ(ST, TYPE, SEQ) { \
961 if (!symtable_visit_ ## TYPE((ST), elt)) \
966 #define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \
971 if (!symtable_visit_ ## TYPE((ST), elt)) { \
972 symtable_exit_block((ST), (S)); \
978 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
983 if (!symtable_visit_ ## TYPE((ST), elt)) \
988 #define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \
993 if (!symtable_visit_ ## TYPE((ST), elt)) { \
994 symtable_exit_block((ST), (S)); \
1001 symtable_visit_stmt(struct symtable *st, stmt_ty s)
1005 if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))
1008 VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
1010 VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);
1011 if (!symtable_enter_block(st, s->v.FunctionDef.name,
1014 VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s);
1015 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s);
1016 if (!symtable_exit_block(st, s))
1021 if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))
1023 VISIT_SEQ(st, expr, s->v.ClassDef.bases);
1025 VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list);
1026 if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,
1029 tmp = st->st_private;
1030 st->st_private = s->v.ClassDef.name;
1031 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
1032 st->st_private = tmp;
1033 if (!symtable_exit_block(st, s))
1039 VISIT(st, expr, s->v.Return.value);
1040 st->st_cur->ste_returns_value = 1;
1041 if (st->st_cur->ste_generator) {
1044 PyErr_SyntaxLocation(st->st_filename,
1051 VISIT_SEQ(st, expr, s->v.Delete.targets);
1054 VISIT_SEQ(st, expr, s->v.Assign.targets);
1055 VISIT(st, expr, s->v.Assign.value);
1058 VISIT(st, expr, s->v.AugAssign.target);
1059 VISIT(st, expr, s->v.AugAssign.value);
1063 VISIT(st, expr, s->v.Print.dest);
1064 VISIT_SEQ(st, expr, s->v.Print.values);
1067 VISIT(st, expr, s->v.For.target);
1068 VISIT(st, expr, s->v.For.iter);
1069 VISIT_SEQ(st, stmt, s->v.For.body);
1071 VISIT_SEQ(st, stmt, s->v.For.orelse);
1074 VISIT(st, expr, s->v.While.test);
1075 VISIT_SEQ(st, stmt, s->v.While.body);
1077 VISIT_SEQ(st, stmt, s->v.While.orelse);
1081 VISIT(st, expr, s->v.If.test);
1082 VISIT_SEQ(st, stmt, s->v.If.body);
1084 VISIT_SEQ(st, stmt, s->v.If.orelse);
1088 VISIT(st, expr, s->v.Raise.type);
1090 VISIT(st, expr, s->v.Raise.inst);
1092 VISIT(st, expr, s->v.Raise.tback);
1097 VISIT_SEQ(st, stmt, s->v.TryExcept.body);
1098 VISIT_SEQ(st, stmt, s->v.TryExcept.orelse);
1099 VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers);
1102 VISIT_SEQ(st, stmt, s->v.TryFinally.body);
1103 VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody);
1106 VISIT(st, expr, s->v.Assert.test);
1108 VISIT(st, expr, s->v.Assert.msg);
1111 VISIT_SEQ(st, alias, s->v.Import.names);
1114 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
1115 st->st_cur->ste_opt_lineno = s->lineno;
1118 VISIT_SEQ(st, alias, s->v.ImportFrom.names);
1121 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
1122 st->st_cur->ste_opt_lineno = s->lineno;
1125 VISIT(st, expr, s->v.Exec.body);
1126 if (!st->st_cur->ste_opt_lineno)
1127 st->st_cur->ste_opt_lineno = s->lineno;
1129 st->st_cur->ste_unoptimized |= OPT_EXEC;
1130 VISIT(st, expr, s->v.Exec.globals);
1132 VISIT(st, expr, s->v.Exec.locals);
1134 st->st_cur->ste_unoptimized |= OPT_BARE_EXEC;
1143 long cur = symtable_lookup(st, name);
1156 if (!symtable_warn(st, buf, s->lineno))
1159 if (!symtable_add_def(st, name, DEF_GLOBAL))
1165 VISIT(st, expr, s->v.Expr.value);
1173 VISIT(st, expr, s->v.With.context_expr);
1175 VISIT(st, expr, s->v.With.optional_vars);
1177 VISIT_SEQ(st, stmt, s->v.With.body);
1184 symtable_visit_expr(struct symtable *st, expr_ty e)
1188 VISIT_SEQ(st, expr, e->v.BoolOp.values);
1191 VISIT(st, expr, e->v.BinOp.left);
1192 VISIT(st, expr, e->v.BinOp.right);
1195 VISIT(st, expr, e->v.UnaryOp.operand);
1201 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
1202 if (!symtable_enter_block(st, lambda,
1205 VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e);
1206 VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e);
1207 if (!symtable_exit_block(st, (void *)e))
1212 VISIT(st, expr, e->v.IfExp.test);
1213 VISIT(st, expr, e->v.IfExp.body);
1214 VISIT(st, expr, e->v.IfExp.orelse);
1217 VISIT_SEQ(st, expr, e->v.Dict.keys);
1218 VISIT_SEQ(st, expr, e->v.Dict.values);
1221 VISIT_SEQ(st, expr, e->v.Set.elts);
1224 VISIT(st, expr, e->v.ListComp.elt);
1225 VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
1228 if (!symtable_visit_genexp(st, e))
1232 if (!symtable_visit_setcomp(st, e))
1236 if (!symtable_visit_dictcomp(st, e))
1241 VISIT(st, expr, e->v.Yield.value);
1242 st->st_cur->ste_generator = 1;
1243 if (st->st_cur->ste_returns_value) {
1246 PyErr_SyntaxLocation(st->st_filename,
1252 VISIT(st, expr, e->v.Compare.left);
1253 VISIT_SEQ(st, expr, e->v.Compare.comparators);
1256 VISIT(st, expr, e->v.Call.func);
1257 VISIT_SEQ(st, expr, e->v.Call.args);
1258 VISIT_SEQ(st, keyword, e->v.Call.keywords);
1260 VISIT(st, expr, e->v.Call.starargs);
1262 VISIT(st, expr, e->v.Call.kwargs);
1265 VISIT(st, expr, e->v.Repr.value);
1273 VISIT(st, expr, e->v.Attribute.value);
1276 VISIT(st, expr, e->v.Subscript.value);
1277 VISIT(st, slice, e->v.Subscript.slice);
1280 if (!symtable_add_def(st, e->v.Name.id,
1286 VISIT_SEQ(st, expr, e->v.List.elts);
1289 VISIT_SEQ(st, expr, e->v.Tuple.elts);
1296 symtable_implicit_arg(struct symtable *st, int pos)
1301 if (!symtable_add_def(st, id, DEF_PARAM)) {
1310 symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
1320 if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
1326 if (!symtable_implicit_arg(st, i))
1333 PyErr_SyntaxLocation(st->st_filename,
1334 st->st_cur->ste_lineno);
1340 if (!symtable_visit_params_nested(st, args))
1348 symtable_visit_params_nested(struct symtable *st, asdl_seq *args)
1354 !symtable_visit_params(st, arg->v.Tuple.elts, 0))
1362 symtable_visit_arguments(struct symtable *st, arguments_ty a)
1367 if (a->args && !symtable_visit_params(st, a->args, 1))
1370 if (!symtable_add_def(st, a->vararg, DEF_PARAM))
1372 st->st_cur->ste_varargs = 1;
1375 if (!symtable_add_def(st, a->kwarg, DEF_PARAM))
1377 st->st_cur->ste_varkeywords = 1;
1379 if (a->args && !symtable_visit_params_nested(st, a->args))
1386 symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
1389 VISIT(st, expr, eh->v.ExceptHandler.type);
1391 VISIT(st, expr, eh->v.ExceptHandler.name);
1392 VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body);
1398 symtable_visit_alias(struct symtable *st, alias_ty a)
1418 int r = symtable_add_def(st, store_name, DEF_IMPORT);
1423 if (st->st_cur->ste_type != ModuleBlock) {
1424 int lineno = st->st_cur->ste_lineno;
1425 if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {
1430 st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
1438 symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)
1440 VISIT(st, expr, lc->target);
1441 VISIT(st, expr, lc->iter);
1442 VISIT_SEQ(st, expr, lc->ifs);
1448 symtable_visit_keyword(struct symtable *st, keyword_ty k)
1450 VISIT(st, expr, k->value);
1456 symtable_visit_slice(struct symtable *st, slice_ty s)
1461 VISIT(st, expr, s->v.Slice.lower)
1463 VISIT(st, expr, s->v.Slice.upper)
1465 VISIT(st, expr, s->v.Slice.step)
1468 VISIT_SEQ(st, slice, s->v.ExtSlice.dims)
1471 VISIT(st, expr, s->v.Index.value)
1480 symtable_new_tmpname(struct symtable *st)
1486 ++st->st_cur->ste_tmpname);
1490 if (!symtable_add_def(st, tmp, DEF_LOCAL))
1497 symtable_handle_comprehension(struct symtable *st, expr_ty e,
1506 VISIT(st, expr, outermost->iter);
1509 !symtable_enter_block(st, scope_name, FunctionBlock, (void *)e, 0)) {
1512 st->st_cur->ste_generator = is_generator;
1514 if (!symtable_implicit_arg(st, 0)) {
1515 symtable_exit_block(st, (void *)e);
1519 if (needs_tmp && !symtable_new_tmpname(st)) {
1520 symtable_exit_block(st, (void *)e);
1523 VISIT_IN_BLOCK(st
1524 VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
1525 VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,
1528 VISIT_IN_BLOCK(st, expr, value, (void*)e);
1529 VISIT_IN_BLOCK(st, expr, elt, (void*)e);
1530 return symtable_exit_block(st, (void *)e);
1534 symtable_visit_genexp(struct symtable *st, expr_ty e)
1536 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),
1542 symtable_visit_setcomp(struct symtable *st, expr_ty e)
1544 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp),
1550 symtable_visit_dictcomp(struct symtable *st, expr_ty e)
1552 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),