mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
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.
This commit is contained in:
parent
e5e56328af
commit
13d52c2686
15 changed files with 300 additions and 709 deletions
|
@ -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))
|
||||
|
@ -1841,28 +1848,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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue