summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
commit7544508f0245173bff5866aa1598c8f6cce1fc5f (patch)
treebf80850d9cd46fc811f04b8c2484fb50775c697d /Python/symtable.c
parent4e6bf4b3da03b132b0698f30ee931a350585b117 (diff)
downloadcpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.zip
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.gz
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.bz2
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 812c052..3677e59 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -180,7 +180,7 @@ 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);
-static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
+static int symtable_visit_annotations(struct symtable *st, stmt_ty s, arguments_ty, expr_ty);
static int symtable_visit_withitem(struct symtable *st, withitem_ty item);
@@ -1147,7 +1147,8 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
if (s->v.FunctionDef.args->kw_defaults)
VISIT_SEQ_WITH_NULL(st, expr, s->v.FunctionDef.args->kw_defaults);
- if (!symtable_visit_annotations(st, s))
+ if (!symtable_visit_annotations(st, s, s->v.FunctionDef.args,
+ s->v.FunctionDef.returns))
VISIT_QUIT(st, 0);
if (s->v.FunctionDef.decorator_list)
VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);
@@ -1315,6 +1316,39 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
VISIT_SEQ(st, withitem, s->v.With.items);
VISIT_SEQ(st, stmt, s->v.With.body);
break;
+ case AsyncFunctionDef_kind:
+ if (!symtable_add_def(st, s->v.AsyncFunctionDef.name, DEF_LOCAL))
+ VISIT_QUIT(st, 0);
+ if (s->v.AsyncFunctionDef.args->defaults)
+ VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.args->defaults);
+ if (s->v.AsyncFunctionDef.args->kw_defaults)
+ VISIT_SEQ_WITH_NULL(st, expr,
+ s->v.AsyncFunctionDef.args->kw_defaults);
+ if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args,
+ s->v.AsyncFunctionDef.returns))
+ VISIT_QUIT(st, 0);
+ if (s->v.AsyncFunctionDef.decorator_list)
+ VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.decorator_list);
+ if (!symtable_enter_block(st, s->v.AsyncFunctionDef.name,
+ FunctionBlock, (void *)s, s->lineno,
+ s->col_offset))
+ VISIT_QUIT(st, 0);
+ VISIT(st, arguments, s->v.AsyncFunctionDef.args);
+ VISIT_SEQ(st, stmt, s->v.AsyncFunctionDef.body);
+ if (!symtable_exit_block(st, s))
+ VISIT_QUIT(st, 0);
+ break;
+ case AsyncWith_kind:
+ VISIT_SEQ(st, withitem, s->v.AsyncWith.items);
+ VISIT_SEQ(st, stmt, s->v.AsyncWith.body);
+ break;
+ case AsyncFor_kind:
+ VISIT(st, expr, s->v.AsyncFor.target);
+ VISIT(st, expr, s->v.AsyncFor.iter);
+ VISIT_SEQ(st, stmt, s->v.AsyncFor.body);
+ if (s->v.AsyncFor.orelse)
+ VISIT_SEQ(st, stmt, s->v.AsyncFor.orelse);
+ break;
}
VISIT_QUIT(st, 1);
}
@@ -1392,6 +1426,10 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
VISIT(st, expr, e->v.YieldFrom.value);
st->st_cur->ste_generator = 1;
break;
+ case Await_kind:
+ VISIT(st, expr, e->v.Await.value);
+ st->st_cur->ste_generator = 1;
+ break;
case Compare_kind:
VISIT(st, expr, e->v.Compare.left);
VISIT_SEQ(st, expr, e->v.Compare.comparators);
@@ -1492,10 +1530,9 @@ symtable_visit_argannotations(struct symtable *st, asdl_seq *args)
}
static int
-symtable_visit_annotations(struct symtable *st, stmt_ty s)
+symtable_visit_annotations(struct symtable *st, stmt_ty s,
+ arguments_ty a, expr_ty returns)
{
- arguments_ty a = s->v.FunctionDef.args;
-
if (a->args && !symtable_visit_argannotations(st, a->args))
return 0;
if (a->vararg && a->vararg->annotation)
@@ -1504,7 +1541,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty s)
VISIT(st, expr, a->kwarg->annotation);
if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
return 0;
- if (s->v.FunctionDef.returns)
+ if (returns)
VISIT(st, expr, s->v.FunctionDef.returns);
return 1;
}