Home | History | Annotate | Download | only in Python

Lines Matching refs:st

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

33 ste->ste_table = st;
65 if (st->st_cur != NULL &&
66 (st->st_cur->ste_nested ||
67 st->st_cur->ste_type == FunctionBlock))
73 if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0)
162 static int symtable_analyze(struct symtable *st);
163 static int symtable_warn(struct symtable *st, char *msg, int lineno);
164 static int symtable_enter_block(struct symtable *st, identifier name,
166 static int symtable_exit_block(struct symtable *st, void *ast);
167 static int symtable_visit_stmt(struct symtable *st, stmt_ty s);
168 static int symtable_visit_expr(struct symtable *st, expr_ty s);
169 static int symtable_visit_genexp(struct symtable *st, expr_ty s);
170 static int symtable_visit_setcomp(struct symtable *st, expr_ty e);
171 static int symtable_visit_dictcomp(struct symtable *st, expr_ty e);
172 static int symtable_visit_arguments(struct symtable *st, arguments_ty);
173 static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
174 static int symtable_visit_alias(struct symtable *st, alias_ty);
175 static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
176 static int symtable_visit_keyword(struct symtable *st, keyword_ty);
177 static int symtable_visit_slice(struct symtable *st, slice_ty);
178 static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top);
179 static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args);
180 static int symtable_implicit_arg(struct symtable *st, int pos);
195 struct symtable *st;
197 st = (struct symtable *)PyMem_Malloc(sizeof(struct symtable));
198 if (st == NULL)
201 st->st_filename = NULL;
202 st->st_symbols = NULL;
204 if ((st->st_stack = PyList_New(0)) == NULL)
206 if ((st->st_symbols = PyDict_New()) == NULL)
208 st->st_cur = NULL;
209 st->st_private = NULL;
210 return st;
212 PySymtable_Free(st);
219 struct symtable *st = symtable_new();
223 if (st == NULL)
224 return st;
225 st->st_filename = filename;
226 st->st_future = future;
228 !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0)) {
229 PySymtable_Free(st);
233 st->st_top = st->st_cur;
234 st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
240 if (!symtable_visit_stmt(st,
245 if (!symtable_visit_expr(st, mod->v.Expression.body))
251 if (!symtable_visit_stmt(st,
260 if (!symtable_exit_block(st, (void *)mod)) {
261 PySymtable_Free(st);
264 if (symtable_analyze(st))
265 return st;
266 PySymtable_Free(st);
269 (void) symtable_exit_block(st, (void *)mod);
270 PySymtable_Free(st);
275 PySymtable_Free(struct symtable *st)
277 Py_XDECREF(st->st_symbols);
278 Py_XDECREF(st->st_stack);
279 PyMem_Free((void *)st);
283 PySymtable_Lookup(struct symtable *st, void *key)
290 v = PyDict_GetItem(st->st_symbols, k);
776 symtable_analyze(struct symtable *st)
789 r = analyze_block(st->st_top, NULL, free, global);
797 symtable_warn(struct symtable *st, char *msg, int lineno)
799 if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
803 PyErr_SyntaxLocation(st->st_filename,
804 st->st_cur->ste_lineno);
817 symtable_exit_block(struct symtable *st, void *ast)
821 Py_CLEAR(st->st_cur);
822 end = PyList_GET_SIZE(st->st_stack) - 1;
824 st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack,
826 if (st->st_cur == NULL)
828 Py_INCREF(st->st_cur);
829 if (PySequence_DelItem(st->st_stack, end) < 0)
836 symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
841 if (st->st_cur) {
842 prev = st->st_cur;
843 if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
846 Py_DECREF(st->st_cur);
848 st->st_cur = ste_new(st, name, block, ast, lineno);
849 if (st->st_cur == NULL)
852 st->st_global = st->st_cur->ste_symbols;
855 (PyObject *)st->st_cur) < 0) {
863 symtable_lookup(struct symtable *st, PyObject *name)
866 PyObject *mangled = _Py_Mangle(st->st_private, name);
869 o = PyDict_GetItem(st->st_cur->ste_symbols, mangled);
877 symtable_add_def(struct symtable *st, PyObject *name, int flag)
882 PyObject *mangled = _Py_Mangle(st->st_private, name);
886 dict = st->st_cur->ste_symbols;
893 PyErr_SyntaxLocation(st->st_filename,
894 st->st_cur->ste_lineno);
910 if (PyList_Append(st->st_cur->ste_varnames, mangled) < 0)
916 if ((o = PyDict_GetItem(st->st_global, mangled))) {
922 if (PyDict_SetItem(st->st_global, mangled, o) < 0) {
944 #define VISIT(ST, TYPE, V) \
945 if (!symtable_visit_ ## TYPE((ST), (V))) \
948 #define VISIT_IN_BLOCK(ST, TYPE, V, S) \
949 if (!symtable_visit_ ## TYPE((ST), (V))) { \
950 symtable_exit_block((ST), (S)); \
954 #define VISIT_SEQ(ST, TYPE, SEQ) { \
959 if (!symtable_visit_ ## TYPE((ST), elt)) \
964 #define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \
969 if (!symtable_visit_ ## TYPE((ST), elt)) { \
970 symtable_exit_block((ST), (S)); \
976 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
981 if (!symtable_visit_ ## TYPE((ST), elt)) \
986 #define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \
991 if (!symtable_visit_ ## TYPE((ST), elt)) { \
992 symtable_exit_block((ST), (S)); \
999 symtable_visit_stmt(struct symtable *st, stmt_ty s)
1003 if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))
1006 VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
1008 VISIT_SEQ(st
1009 if (!symtable_enter_block(st, s->v.FunctionDef.name,
1012 VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s);
1013 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s);
1014 if (!symtable_exit_block(st, s))
1019 if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))
1021 VISIT_SEQ(st, expr, s->v.ClassDef.bases);
1023 VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list);
1024 if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,
1027 tmp = st->st_private;
1028 st->st_private = s->v.ClassDef.name;
1029 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
1030 st->st_private = tmp;
1031 if (!symtable_exit_block(st, s))
1037 VISIT(st, expr, s->v.Return.value);
1038 st->st_cur->ste_returns_value = 1;
1039 if (st->st_cur->ste_generator) {
1042 PyErr_SyntaxLocation(st->st_filename,
1049 VISIT_SEQ(st, expr, s->v.Delete.targets);
1052 VISIT_SEQ(st, expr, s->v.Assign.targets);
1053 VISIT(st, expr, s->v.Assign.value);
1056 VISIT(st, expr, s->v.AugAssign.target);
1057 VISIT(st, expr, s->v.AugAssign.value);
1061 VISIT(st, expr, s->v.Print.dest);
1062 VISIT_SEQ(st, expr, s->v.Print.values);
1065 VISIT(st, expr, s->v.For.target);
1066 VISIT(st, expr, s->v.For.iter);
1067 VISIT_SEQ(st, stmt, s->v.For.body);
1069 VISIT_SEQ(st, stmt, s->v.For.orelse);
1072 VISIT(st, expr, s->v.While.test);
1073 VISIT_SEQ(st, stmt, s->v.While.body);
1075 VISIT_SEQ(st, stmt, s->v.While.orelse);
1079 VISIT(st, expr, s->v.If.test);
1080 VISIT_SEQ(st, stmt, s->v.If.body);
1082 VISIT_SEQ(st, stmt, s->v.If.orelse);
1086 VISIT(st, expr, s->v.Raise.type);
1088 VISIT(st, expr, s->v.Raise.inst);
1090 VISIT(st, expr, s->v.Raise.tback);
1095 VISIT_SEQ(st, stmt, s->v.TryExcept.body);
1096 VISIT_SEQ(st, stmt, s->v.TryExcept.orelse);
1097 VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers);
1100 VISIT_SEQ(st, stmt, s->v.TryFinally.body);
1101 VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody);
1104 VISIT(st, expr, s->v.Assert.test);
1106 VISIT(st, expr, s->v.Assert.msg);
1109 VISIT_SEQ(st, alias, s->v.Import.names);
1112 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
1113 st->st_cur->ste_opt_lineno = s->lineno;
1116 VISIT_SEQ(st, alias, s->v.ImportFrom.names);
1119 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
1120 st->st_cur->ste_opt_lineno = s->lineno;
1123 VISIT(st, expr, s->v.Exec.body);
1124 if (!st->st_cur->ste_opt_lineno)
1125 st->st_cur->ste_opt_lineno = s->lineno;
1127 st->st_cur->ste_unoptimized |= OPT_EXEC;
1128 VISIT(st, expr, s->v.Exec.globals);
1130 VISIT(st, expr, s->v.Exec.locals);
1132 st->st_cur->ste_unoptimized |= OPT_BARE_EXEC;
1141 long cur = symtable_lookup(st, name);
1154 if (!symtable_warn(st, buf, s->lineno))
1157 if (!symtable_add_def(st, name, DEF_GLOBAL))
1163 VISIT(st, expr, s->v.Expr.value);
1171 VISIT(st, expr, s->v.With.context_expr);
1173 VISIT(st, expr, s->v.With.optional_vars);
1175 VISIT_SEQ(st, stmt, s->v.With.body);
1182 symtable_visit_expr(struct symtable *st, expr_ty e)
1186 VISIT_SEQ(st, expr, e->v.BoolOp.values);
1189 VISIT(st, expr, e->v.BinOp.left);
1190 VISIT(st, expr, e->v.BinOp.right);
1193 VISIT(st, expr, e->v.UnaryOp.operand);
1199 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
1200 if (!symtable_enter_block(st, lambda,
1203 VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e);
1204 VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e);
1205 if (!symtable_exit_block(st, (void *)e))
1210 VISIT(st, expr, e->v.IfExp.test);
1211 VISIT(st, expr, e->v.IfExp.body);
1212 VISIT(st, expr, e->v.IfExp.orelse);
1215 VISIT_SEQ(st, expr, e->v.Dict.keys);
1216 VISIT_SEQ(st, expr, e->v.Dict.values);
1219 VISIT_SEQ(st, expr, e->v.Set.elts);
1222 VISIT(st, expr, e->v.ListComp.elt);
1223 VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
1226 if (!symtable_visit_genexp(st, e))
1230 if (!symtable_visit_setcomp(st, e))
1234 if (!symtable_visit_dictcomp(st, e))
1239 VISIT(st, expr, e->v.Yield.value);
1240 st->st_cur->ste_generator = 1;
1241 if (st->st_cur->ste_returns_value) {
1244 PyErr_SyntaxLocation(st->st_filename,
1250 VISIT(st, expr, e->v.Compare.left);
1251 VISIT_SEQ(st, expr, e->v.Compare.comparators);
1254 VISIT(st, expr, e->v.Call.func);
1255 VISIT_SEQ(st, expr, e->v.Call.args);
1256 VISIT_SEQ(st, keyword, e->v.Call.keywords);
1258 VISIT(st, expr, e->v.Call.starargs);
1260 VISIT(st, expr, e->v.Call.kwargs);
1263 VISIT(st, expr, e->v.Repr.value);
1271 VISIT(st, expr, e->v.Attribute.value);
1274 VISIT(st, expr, e->v.Subscript.value);
1275 VISIT(st, slice, e->v.Subscript.slice);
1278 if (!symtable_add_def(st, e->v.Name.id,
1284 VISIT_SEQ(st, expr, e->v.List.elts);
1287 VISIT_SEQ(st, expr, e->v.Tuple.elts);
1294 symtable_implicit_arg(struct symtable *st, int pos)
1299 if (!symtable_add_def(st, id, DEF_PARAM)) {
1308 symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
1318 if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
1324 if (!symtable_implicit_arg(st, i))
1331 PyErr_SyntaxLocation(st->st_filename,
1332 st->st_cur->ste_lineno);
1338 if (!symtable_visit_params_nested(st, args))
1346 symtable_visit_params_nested(struct symtable *st, asdl_seq *args)
1352 !symtable_visit_params(st, arg->v.Tuple.elts, 0))
1360 symtable_visit_arguments(struct symtable *st, arguments_ty a)
1365 if (a->args && !symtable_visit_params(st, a->args, 1))
1368 if (!symtable_add_def(st, a->vararg, DEF_PARAM))
1370 st->st_cur->ste_varargs = 1;
1373 if (!symtable_add_def(st, a->kwarg, DEF_PARAM))
1375 st->st_cur->ste_varkeywords = 1;
1377 if (a->args && !symtable_visit_params_nested(st, a->args))
1384 symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
1387 VISIT(st, expr, eh->v.ExceptHandler.type);
1389 VISIT(st, expr, eh->v.ExceptHandler.name);
1390 VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body);
1396 symtable_visit_alias(struct symtable *st, alias_ty a)
1416 int r = symtable_add_def(st, store_name, DEF_IMPORT);
1421 if (st->st_cur->ste_type != ModuleBlock) {
1422 int lineno = st->st_cur->ste_lineno;
1423 if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {
1428 st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
1436 symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)
1438 VISIT(st, expr, lc->target);
1439 VISIT(st, expr, lc->iter);
1440 VISIT_SEQ(st, expr, lc->ifs);
1446 symtable_visit_keyword(struct symtable *st, keyword_ty k)
1448 VISIT(st, expr, k->value);
1454 symtable_visit_slice(struct symtable *st, slice_ty s)
1459 VISIT(st, expr, s->v.Slice.lower)
1461 VISIT(st, expr, s->v.Slice.upper)
1463 VISIT(st, expr, s->v.Slice.step)
1466 VISIT_SEQ(st, slice, s->v.ExtSlice.dims)
1469 VISIT(st, expr, s->v.Index.value)
1478 symtable_new_tmpname(struct symtable *st)
1484 ++st->st_cur->ste_tmpname);
1488 if (!symtable_add_def(st, tmp, DEF_LOCAL))
1495 symtable_handle_comprehension(struct symtable *st, expr_ty e,
1504 VISIT(st, expr, outermost->iter);
1507 !symtable_enter_block(st, scope_name, FunctionBlock, (void *)e, 0)) {
1510 st->st_cur->ste_generator = is_generator;
1512 if (!symtable_implicit_arg(st, 0)) {
1513 symtable_exit_block(st, (void *)e);
1517 if (needs_tmp && !symtable_new_tmpname(st)) {
1518 symtable_exit_block(st, (void *)e);
1521 VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);
1522 VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
1523 st, comprehension,
1526 VISIT_IN_BLOCK(st, expr, value, (void*)e);
1527 VISIT_IN_BLOCK(st, expr, elt, (void*)e);
1528 return symtable_exit_block(st, (void *)e);
1532 symtable_visit_genexp(struct symtable *st, expr_ty e)
1534 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),
1540 symtable_visit_setcomp(struct symtable *st, expr_ty e)
1542 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp),
1548 symtable_visit_dictcomp(struct symtable *st, expr_ty e)
1550 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),