mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73376 | benjamin.peterson | 2009-06-11 17:29:23 -0500 (Thu, 11 Jun 2009) | 1 line remove check for case handled in sub-function ........ r73393 | alexandre.vassalotti | 2009-06-12 13:56:57 -0500 (Fri, 12 Jun 2009) | 2 lines Clear reference to the static PyExc_RecursionErrorInst in _PyExc_Fini. ........ r73398 | alexandre.vassalotti | 2009-06-12 15:57:12 -0500 (Fri, 12 Jun 2009) | 3 lines Add const qualifier to PyErr_SetFromErrnoWithFilename and to PyErr_SetFromErrnoWithUnicodeFilename. ........ r73400 | alexandre.vassalotti | 2009-06-12 16:43:47 -0500 (Fri, 12 Jun 2009) | 2 lines Delete outdated make file for building the parser with MSVC 6. ........ r73404 | benjamin.peterson | 2009-06-12 20:40:00 -0500 (Fri, 12 Jun 2009) | 1 line keep the slice.step field as NULL if no step expression is given ........ r73405 | benjamin.peterson | 2009-06-12 22:46:30 -0500 (Fri, 12 Jun 2009) | 1 line prevent import statements from assigning to None ........ r73409 | benjamin.peterson | 2009-06-13 08:06:21 -0500 (Sat, 13 Jun 2009) | 1 line allow importing from a module named None if it has an 'as' clause ........ r73419 | benjamin.peterson | 2009-06-13 11:19:19 -0500 (Sat, 13 Jun 2009) | 1 line set Print.values to NULL if there are no values ........ r73420 | benjamin.peterson | 2009-06-13 12:08:53 -0500 (Sat, 13 Jun 2009) | 1 line give a better error message when deleting () ........ r73421 | benjamin.peterson | 2009-06-13 15:23:33 -0500 (Sat, 13 Jun 2009) | 1 line when no module is given in a 'from' relative import, make ImportFrom.module NULL ........ r73432 | amaury.forgeotdarc | 2009-06-14 16:20:40 -0500 (Sun, 14 Jun 2009) | 3 lines #6227: Because of a wrong indentation, the test was not testing what it should. Ensure that the snippet in doctest_aliases actually contains aliases. ........ r73457 | benjamin.peterson | 2009-06-16 18:13:09 -0500 (Tue, 16 Jun 2009) | 1 line add underscores ........ r73460 | benjamin.peterson | 2009-06-16 22:23:04 -0500 (Tue, 16 Jun 2009) | 1 line remove unused 'encoding' member from the compiler struct ........ r73485 | benjamin.peterson | 2009-06-19 17:07:47 -0500 (Fri, 19 Jun 2009) | 1 line remove duplicate test ........ r73486 | benjamin.peterson | 2009-06-19 17:09:17 -0500 (Fri, 19 Jun 2009) | 1 line add missing assertion #6313 ........ r73488 | benjamin.peterson | 2009-06-19 17:16:28 -0500 (Fri, 19 Jun 2009) | 1 line show that this one isn't used ........ r73489 | benjamin.peterson | 2009-06-19 17:21:12 -0500 (Fri, 19 Jun 2009) | 1 line use closures ........ r73501 | benjamin.peterson | 2009-06-21 18:01:07 -0500 (Sun, 21 Jun 2009) | 1 line don't need to add the name 'lambda' as assigned ........ r73502 | benjamin.peterson | 2009-06-21 18:03:36 -0500 (Sun, 21 Jun 2009) | 1 line remove tmpname support since it's no longer used ........ r73513 | benjamin.peterson | 2009-06-22 20:18:57 -0500 (Mon, 22 Jun 2009) | 1 line fix grammar ........ r73514 | benjamin.peterson | 2009-06-22 22:01:56 -0500 (Mon, 22 Jun 2009) | 1 line remove some unused symtable constants ........
This commit is contained in:
parent
c609b6b04b
commit
78565b2216
20 changed files with 113 additions and 150 deletions
|
@ -1332,11 +1332,6 @@ ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
|
|||
col_offset, PyArena *arena)
|
||||
{
|
||||
stmt_ty p;
|
||||
if (!module) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"field module is required for ImportFrom");
|
||||
return NULL;
|
||||
}
|
||||
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
@ -4465,8 +4460,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
|
|||
Py_XDECREF(tmp);
|
||||
tmp = NULL;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom");
|
||||
return 1;
|
||||
module = NULL;
|
||||
}
|
||||
if (PyObject_HasAttrString(obj, "names")) {
|
||||
int res;
|
||||
|
|
86
Python/ast.c
86
Python/ast.c
|
@ -362,12 +362,12 @@ static const char* FORBIDDEN[] = {
|
|||
};
|
||||
|
||||
static int
|
||||
forbidden_name(expr_ty e, const node *n)
|
||||
forbidden_name(identifier name, const node *n)
|
||||
{
|
||||
const char **p;
|
||||
assert(PyUnicode_Check(e->v.Name.id));
|
||||
assert(PyUnicode_Check(name));
|
||||
for (p = FORBIDDEN; *p; p++) {
|
||||
if (PyUnicode_CompareWithASCIIString(e->v.Name.id, *p) == 0) {
|
||||
if (PyUnicode_CompareWithASCIIString(name, *p) == 0) {
|
||||
ast_error(n, "assignment to keyword");
|
||||
return 1;
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
|
|||
break;
|
||||
case Name_kind:
|
||||
if (ctx == Store) {
|
||||
if (forbidden_name(e, n))
|
||||
if (forbidden_name(e->v.Name.id, n))
|
||||
return 0; /* forbidden_name() calls ast_error() */
|
||||
}
|
||||
e->v.Name.ctx = ctx;
|
||||
|
@ -424,10 +424,13 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
|
|||
s = e->v.List.elts;
|
||||
break;
|
||||
case Tuple_kind:
|
||||
if (asdl_seq_LEN(e->v.Tuple.elts) == 0)
|
||||
return ast_error(n, "can't assign to ()");
|
||||
e->v.Tuple.ctx = ctx;
|
||||
s = e->v.Tuple.elts;
|
||||
if (asdl_seq_LEN(e->v.Tuple.elts)) {
|
||||
e->v.Tuple.ctx = ctx;
|
||||
s = e->v.Tuple.elts;
|
||||
}
|
||||
else {
|
||||
expr_name = "()";
|
||||
}
|
||||
break;
|
||||
case Lambda_kind:
|
||||
expr_name = "lambda";
|
||||
|
@ -1378,7 +1381,7 @@ ast_for_atom(struct compiling *c, const node *n)
|
|||
/* testlist_comp: test ( comp_for | (',' test)* [','] ) */
|
||||
if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == comp_for))
|
||||
return ast_for_genexp(c, ch);
|
||||
|
||||
|
||||
return ast_for_testlist(c, ch);
|
||||
case LSQB: /* list (or list comprehension) */
|
||||
ch = CHILD(n, 1);
|
||||
|
@ -1513,14 +1516,7 @@ ast_for_slice(struct compiling *c, const node *n)
|
|||
|
||||
ch = CHILD(n, NCH(n) - 1);
|
||||
if (TYPE(ch) == sliceop) {
|
||||
if (NCH(ch) == 1) {
|
||||
/* No expression, so step is None */
|
||||
ch = CHILD(ch, 0);
|
||||
step = Name(new_identifier("None", c->c_arena), Load,
|
||||
LINENO(ch), ch->n_col_offset, c->c_arena);
|
||||
if (!step)
|
||||
return NULL;
|
||||
} else {
|
||||
if (NCH(ch) != 1) {
|
||||
ch = CHILD(ch, 1);
|
||||
if (TYPE(ch) == test) {
|
||||
step = ast_for_expr(c, ch);
|
||||
|
@ -2014,7 +2010,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
|
|||
} else if (e->kind != Name_kind) {
|
||||
ast_error(CHILD(ch, 0), "keyword can't be an expression");
|
||||
return NULL;
|
||||
} else if (forbidden_name(e, ch)) {
|
||||
} else if (forbidden_name(e->v.Name.id, ch)) {
|
||||
return NULL;
|
||||
}
|
||||
key = e->v.Name.id;
|
||||
|
@ -2160,6 +2156,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static asdl_seq *
|
||||
ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context)
|
||||
{
|
||||
|
@ -2260,49 +2257,64 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
|
|||
}
|
||||
|
||||
static alias_ty
|
||||
alias_for_import_name(struct compiling *c, const node *n)
|
||||
alias_for_import_name(struct compiling *c, const node *n, int store)
|
||||
{
|
||||
/*
|
||||
import_as_name: NAME ['as' NAME]
|
||||
dotted_as_name: dotted_name ['as' NAME]
|
||||
dotted_name: NAME ('.' NAME)*
|
||||
*/
|
||||
PyObject *str, *name;
|
||||
identifier str, name;
|
||||
|
||||
loop:
|
||||
switch (TYPE(n)) {
|
||||
case import_as_name:
|
||||
case import_as_name: {
|
||||
node *name_node = CHILD(n, 0);
|
||||
str = NULL;
|
||||
if (NCH(n) == 3) {
|
||||
str = NEW_IDENTIFIER(CHILD(n, 2));
|
||||
if (!str)
|
||||
return NULL;
|
||||
}
|
||||
name = NEW_IDENTIFIER(CHILD(n, 0));
|
||||
name = NEW_IDENTIFIER(name_node);
|
||||
if (!name)
|
||||
return NULL;
|
||||
if (NCH(n) == 3) {
|
||||
node *str_node = CHILD(n, 2);
|
||||
str = NEW_IDENTIFIER(str_node);
|
||||
if (!str)
|
||||
return NULL;
|
||||
if (store && forbidden_name(str, str_node))
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
if (forbidden_name(name, name_node))
|
||||
return NULL;
|
||||
}
|
||||
return alias(name, str, c->c_arena);
|
||||
}
|
||||
case dotted_as_name:
|
||||
if (NCH(n) == 1) {
|
||||
n = CHILD(n, 0);
|
||||
goto loop;
|
||||
}
|
||||
else {
|
||||
alias_ty a = alias_for_import_name(c, CHILD(n, 0));
|
||||
node *asname_node = CHILD(n, 2);
|
||||
alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0);
|
||||
if (!a)
|
||||
return NULL;
|
||||
assert(!a->asname);
|
||||
a->asname = NEW_IDENTIFIER(CHILD(n, 2));
|
||||
a->asname = NEW_IDENTIFIER(asname_node);
|
||||
if (!a->asname)
|
||||
return NULL;
|
||||
if (forbidden_name(a->asname, asname_node))
|
||||
return NULL;
|
||||
return a;
|
||||
}
|
||||
break;
|
||||
case dotted_name:
|
||||
if (NCH(n) == 1) {
|
||||
name = NEW_IDENTIFIER(CHILD(n, 0));
|
||||
node *name_node = CHILD(n, 0);
|
||||
name = NEW_IDENTIFIER(name_node);
|
||||
if (!name)
|
||||
return NULL;
|
||||
if (store && forbidden_name(name, name_node))
|
||||
return NULL;
|
||||
return alias(name, NULL, c->c_arena);
|
||||
}
|
||||
else {
|
||||
|
@ -2382,7 +2394,7 @@ ast_for_import_stmt(struct compiling *c, const node *n)
|
|||
if (!aliases)
|
||||
return NULL;
|
||||
for (i = 0; i < NCH(n); i += 2) {
|
||||
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
|
||||
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);
|
||||
if (!import_alias)
|
||||
return NULL;
|
||||
asdl_seq_SET(aliases, i / 2, import_alias);
|
||||
|
@ -2393,13 +2405,15 @@ ast_for_import_stmt(struct compiling *c, const node *n)
|
|||
int n_children;
|
||||
int idx, ndots = 0;
|
||||
alias_ty mod = NULL;
|
||||
identifier modname;
|
||||
identifier modname = NULL;
|
||||
|
||||
/* Count the number of dots (for relative imports) and check for the
|
||||
optional module name */
|
||||
for (idx = 1; idx < NCH(n); idx++) {
|
||||
if (TYPE(CHILD(n, idx)) == dotted_name) {
|
||||
mod = alias_for_import_name(c, CHILD(n, idx));
|
||||
mod = alias_for_import_name(c, CHILD(n, idx), 0);
|
||||
if (!mod)
|
||||
return NULL;
|
||||
idx++;
|
||||
break;
|
||||
} else if (TYPE(CHILD(n, idx)) == ELLIPSIS) {
|
||||
|
@ -2444,14 +2458,14 @@ ast_for_import_stmt(struct compiling *c, const node *n)
|
|||
|
||||
/* handle "from ... import *" special b/c there's no children */
|
||||
if (TYPE(n) == STAR) {
|
||||
alias_ty import_alias = alias_for_import_name(c, n);
|
||||
alias_ty import_alias = alias_for_import_name(c, n, 1);
|
||||
if (!import_alias)
|
||||
return NULL;
|
||||
asdl_seq_SET(aliases, 0, import_alias);
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < NCH(n); i += 2) {
|
||||
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
|
||||
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);
|
||||
if (!import_alias)
|
||||
return NULL;
|
||||
asdl_seq_SET(aliases, i / 2, import_alias);
|
||||
|
@ -2459,8 +2473,6 @@ ast_for_import_stmt(struct compiling *c, const node *n)
|
|||
}
|
||||
if (mod != NULL)
|
||||
modname = mod->name;
|
||||
else
|
||||
modname = new_identifier("", c->c_arena);
|
||||
return ImportFrom(modname, aliases, ndots, lineno, col_offset,
|
||||
c->c_arena);
|
||||
}
|
||||
|
|
|
@ -117,7 +117,6 @@ struct compiler_unit {
|
|||
members, you can reach all early allocated blocks. */
|
||||
basicblock *u_blocks;
|
||||
basicblock *u_curblock; /* pointer to current block */
|
||||
int u_tmpname; /* temporary variables for list comps */
|
||||
|
||||
int u_nfblocks;
|
||||
struct fblockinfo u_fblock[CO_MAXBLOCKS];
|
||||
|
@ -146,7 +145,6 @@ struct compiler {
|
|||
|
||||
struct compiler_unit *u; /* compiler state for current block */
|
||||
PyObject *c_stack; /* Python list holding compiler_unit ptrs */
|
||||
char *c_encoding; /* source encoding (a borrowed reference) */
|
||||
PyArena *c_arena; /* pointer to memory allocation arena */
|
||||
};
|
||||
|
||||
|
@ -295,9 +293,6 @@ PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
|
|||
goto finally;
|
||||
}
|
||||
|
||||
/* XXX initialize to NULL for now, need to handle */
|
||||
c.c_encoding = NULL;
|
||||
|
||||
co = compiler_mod(&c, mod);
|
||||
|
||||
finally:
|
||||
|
@ -488,7 +483,6 @@ compiler_enter_scope(struct compiler *c, identifier name, void *key,
|
|||
}
|
||||
|
||||
u->u_blocks = NULL;
|
||||
u->u_tmpname = 0;
|
||||
u->u_nfblocks = 0;
|
||||
u->u_firstlineno = lineno;
|
||||
u->u_lineno = 0;
|
||||
|
@ -2154,6 +2148,13 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
|||
|
||||
PyObject *names = PyTuple_New(n);
|
||||
PyObject *level;
|
||||
static PyObject *empty_string;
|
||||
|
||||
if (!empty_string) {
|
||||
empty_string = PyUnicode_FromString("");
|
||||
if (!empty_string)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!names)
|
||||
return 0;
|
||||
|
@ -2171,23 +2172,24 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
|||
PyTuple_SET_ITEM(names, i, alias->name);
|
||||
}
|
||||
|
||||
if (s->lineno > c->c_future->ff_lineno) {
|
||||
if (!PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module,
|
||||
"__future__")) {
|
||||
Py_DECREF(level);
|
||||
Py_DECREF(names);
|
||||
return compiler_error(c,
|
||||
"from __future__ imports must occur "
|
||||
if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
|
||||
!PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module, "__future__")) {
|
||||
Py_DECREF(level);
|
||||
Py_DECREF(names);
|
||||
return compiler_error(c, "from __future__ imports must occur "
|
||||
"at the beginning of the file");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ADDOP_O(c, LOAD_CONST, level, consts);
|
||||
Py_DECREF(level);
|
||||
ADDOP_O(c, LOAD_CONST, names, consts);
|
||||
Py_DECREF(names);
|
||||
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
||||
if (s->v.ImportFrom.module) {
|
||||
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
||||
}
|
||||
else {
|
||||
ADDOP_NAME(c, IMPORT_NAME, empty_string, names);
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);
|
||||
identifier store_name;
|
||||
|
|
|
@ -38,7 +38,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
|
|||
goto fail;
|
||||
ste->ste_table = st;
|
||||
ste->ste_id = k;
|
||||
ste->ste_tmpname = 0;
|
||||
|
||||
ste->ste_name = name;
|
||||
Py_INCREF(name);
|
||||
|
@ -66,7 +65,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
|
|||
ste->ste_varargs = 0;
|
||||
ste->ste_varkeywords = 0;
|
||||
ste->ste_opt_lineno = 0;
|
||||
ste->ste_tmpname = 0;
|
||||
ste->ste_lineno = lineno;
|
||||
|
||||
if (st->st_cur != NULL &&
|
||||
|
@ -1099,7 +1097,6 @@ symtable_new_tmpname(struct symtable *st)
|
|||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
||||
{
|
||||
|
@ -1297,12 +1294,8 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
|||
/* 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);
|
||||
|
@ -1326,8 +1319,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
|
|||
VISIT(st, expr, e->v.UnaryOp.operand);
|
||||
break;
|
||||
case Lambda_kind: {
|
||||
if (!GET_IDENTIFIER(lambda) ||
|
||||
!symtable_add_def(st, lambda, DEF_LOCAL))
|
||||
if (!GET_IDENTIFIER(lambda))
|
||||
return 0;
|
||||
if (e->v.Lambda.args->defaults)
|
||||
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue