summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-02-27 22:32:47 (GMT)
committerGuido van Rossum <guido@python.org>2006-02-27 22:32:47 (GMT)
commitc2e20744b2b7811632030470971c31630f0975e2 (patch)
treee97b1c1471fd00e4e5648ed317274c1d9005d2ca /Python/symtable.c
parent5fec904f84a40005f824abe295525a1710056be0 (diff)
downloadcpython-c2e20744b2b7811632030470971c31630f0975e2.zip
cpython-c2e20744b2b7811632030470971c31630f0975e2.tar.gz
cpython-c2e20744b2b7811632030470971c31630f0975e2.tar.bz2
PEP 343 -- the with-statement.
This was started by Mike Bland and completed by Guido (with help from Neal). This still needs a __future__ statement added; Thomas is working on Michael's patch for that aspect. There's a small amount of code cleanup and refactoring in ast.c, compile.c and ceval.c (I fixed the lltrace behavior when EXT_POP is used -- however I had to make lltrace a static global).
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index b66abc9..bc0fc33 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -891,6 +891,21 @@ error:
}
static int
+symtable_new_tmpname(struct symtable *st)
+{
+ char tmpname[256];
+ identifier tmp;
+
+ PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
+ ++st->st_cur->ste_tmpname);
+ tmp = PyString_InternFromString(tmpname);
+ if (!symtable_add_def(st, tmp, DEF_LOCAL))
+ return 0;
+ Py_DECREF(tmp);
+ return 1;
+}
+
+static int
symtable_visit_stmt(struct symtable *st, stmt_ty s)
{
switch (s->kind) {
@@ -1051,6 +1066,17 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
case Continue_kind:
/* nothing to do here */
break;
+ case With_kind:
+ if (!symtable_new_tmpname(st))
+ return 0;
+ VISIT(st, expr, s->v.With.context_expr);
+ if (s->v.With.optional_vars) {
+ if (!symtable_new_tmpname(st))
+ return 0;
+ VISIT(st, expr, s->v.With.optional_vars);
+ }
+ VISIT_SEQ(st, stmt, s->v.With.body);
+ break;
}
return 1;
}
@@ -1093,26 +1119,16 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
VISIT_SEQ(st, expr, e->v.Dict.keys);
VISIT_SEQ(st, expr, e->v.Dict.values);
break;
- case ListComp_kind: {
- char tmpname[256];
- identifier tmp;
-
- PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
- ++st->st_cur->ste_tmpname);
- tmp = PyString_InternFromString(tmpname);
- if (!symtable_add_def(st, tmp, DEF_LOCAL))
+ case ListComp_kind:
+ if (!symtable_new_tmpname(st))
return 0;
- Py_DECREF(tmp);
VISIT(st, expr, e->v.ListComp.elt);
VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
break;
- }
- case GeneratorExp_kind: {
- if (!symtable_visit_genexp(st, e)) {
+ case GeneratorExp_kind:
+ if (!symtable_visit_genexp(st, e))
return 0;
- }
break;
- }
case Yield_kind:
if (e->v.Yield.value)
VISIT(st, expr, e->v.Yield.value);