diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-03-10 18:52:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 18:52:34 +0200 |
commit | 13d52c268699f199a8e917a0f1dc4c51e5346c42 (patch) | |
tree | d602c97d77e3222d38c6300ed822021e51bd9dce /Python/symtable.c | |
parent | e5e56328afac50aad6d8893185d8e7ba8928afe2 (diff) | |
download | cpython-git-13d52c268699f199a8e917a0f1dc4c51e5346c42.tar.gz |
bpo-34822: Simplify AST for subscription. (GH-9605)
* Remove the slice type.
* Make Slice a kind of the expr type instead of the slice type.
* Replace ExtSlice(slices) with Tuple(slices, Load()).
* Replace Index(value) with a value itself.
All non-terminal nodes in AST for expressions are now of the expr type.
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index 290e41b64a..014570e6ef 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -202,7 +202,6 @@ static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty); static int symtable_visit_alias(struct symtable *st, alias_ty); static int symtable_visit_comprehension(struct symtable *st, comprehension_ty); static int symtable_visit_keyword(struct symtable *st, keyword_ty); -static int symtable_visit_slice(struct symtable *st, slice_ty); static int symtable_visit_params(struct symtable *st, asdl_seq *args); static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args); static int symtable_implicit_arg(struct symtable *st, int pos); @@ -1632,11 +1631,19 @@ symtable_visit_expr(struct symtable *st, expr_ty e) break; case Subscript_kind: VISIT(st, expr, e->v.Subscript.value); - VISIT(st, slice, e->v.Subscript.slice); + VISIT(st, expr, e->v.Subscript.slice); break; case Starred_kind: VISIT(st, expr, e->v.Starred.value); break; + case Slice_kind: + if (e->v.Slice.lower) + VISIT(st, expr, e->v.Slice.lower) + if (e->v.Slice.upper) + VISIT(st, expr, e->v.Slice.upper) + if (e->v.Slice.step) + VISIT(st, expr, e->v.Slice.step) + break; case Name_kind: if (!symtable_add_def(st, e->v.Name.id, e->v.Name.ctx == Load ? USE : DEF_LOCAL)) @@ -1842,28 +1849,6 @@ symtable_visit_keyword(struct symtable *st, keyword_ty k) static int -symtable_visit_slice(struct symtable *st, slice_ty s) -{ - switch (s->kind) { - case Slice_kind: - if (s->v.Slice.lower) - VISIT(st, expr, s->v.Slice.lower) - if (s->v.Slice.upper) - VISIT(st, expr, s->v.Slice.upper) - if (s->v.Slice.step) - VISIT(st, expr, s->v.Slice.step) - break; - case ExtSlice_kind: - VISIT_SEQ(st, slice, s->v.ExtSlice.dims) - break; - case Index_kind: - VISIT(st, expr, s->v.Index.value) - break; - } - return 1; -} - -static int symtable_handle_comprehension(struct symtable *st, expr_ty e, identifier scope_name, asdl_seq *generators, expr_ty elt, expr_ty value) |