Remove st_nested_scopes from struct symtable,

because nested scopes are always enabled.

(Accidentally checked in one small change along this path yesterday,
wreaking havoc in the Windows build.)
This commit is contained in:
Jeremy Hylton 2001-08-11 21:51:24 +00:00
parent d5d8fc559c
commit 1abf610b15
2 changed files with 45 additions and 130 deletions

View File

@ -20,7 +20,6 @@ struct _symtable_entry;
struct symtable {
int st_pass; /* pass == 1 or 2 */
int st_nested_scopes; /* true if nested scopes are enabled */
char *st_filename; /* name of file being compiled */
struct _symtable_entry *st_cur; /* current symbol table entry */
PyObject *st_symbols; /* dictionary of symbol table entries */

View File

@ -2158,9 +2158,6 @@ static int
com_make_closure(struct compiling *c, PyCodeObject *co)
{
int i, free = PyTuple_GET_SIZE(co->co_freevars);
/* If the code is compiled with st->st_nested_scopes == 0,
then no variable will ever be added to co_freevars.
*/
if (free == 0)
return 0;
for (i = 0; i < free; ++i) {
@ -4056,8 +4053,9 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
static int
get_ref_type(struct compiling *c, char *name)
{
char buf[350];
PyObject *v;
if (c->c_symtable->st_nested_scopes) {
if (PyDict_GetItemString(c->c_cellvars, name) != NULL)
return CELL;
if (PyDict_GetItemString(c->c_locals, name) != NULL)
@ -4072,20 +4070,6 @@ get_ref_type(struct compiling *c, char *name)
return GLOBAL_IMPLICIT;
}
}
} else {
if (PyDict_GetItemString(c->c_locals, name) != NULL)
return LOCAL;
v = PyDict_GetItemString(c->c_globals, name);
if (v) {
if (v == Py_None)
return GLOBAL_EXPLICIT;
else {
return GLOBAL_IMPLICIT;
}
}
}
{
char buf[350];
sprintf(buf,
"unknown scope for %.100s in %.100s(%s) "
"in %s\nsymbols: %s\nlocals: %s\nglobals: %s\n",
@ -4098,8 +4082,7 @@ get_ref_type(struct compiling *c, char *name)
);
Py_FatalError(buf);
}
return -1; /* can't get here */
return -1;
}
/* Helper functions to issue warnings */
@ -4375,61 +4358,11 @@ symtable_check_unoptimized(struct compiling *c,
}
}
if (c->c_symtable->st_nested_scopes) {
PyErr_SetString(PyExc_SyntaxError, buf);
PyErr_SyntaxLocation(c->c_symtable->st_filename,
ste->ste_opt_lineno);
return -1;
}
else {
return issue_warning(buf, c->c_filename, ste->ste_lineno);
}
return 0;
}
static int
symtable_check_shadow(struct symtable *st, PyObject *name, int flags)
{
char buf[500];
PyObject *children, *v;
PySymtableEntryObject *child = NULL;
int i;
if (!(flags & DEF_BOUND))
return 0;
/* The semantics of this code will change with nested scopes.
It is defined in the current scope and referenced in a
child scope. Under the old rules, the child will see a
global. Under the new rules, the child will see the
binding in the current scope.
*/
/* Find name of child function that has free variable */
children = st->st_cur->ste_children;
for (i = 0; i < PyList_GET_SIZE(children); i++) {
int cflags;
child = (PySymtableEntryObject *)PyList_GET_ITEM(children, i);
v = PyDict_GetItem(child->ste_symbols, name);
if (v == NULL)
continue;
cflags = PyInt_AS_LONG(v);
if (!(cflags & DEF_BOUND))
break;
}
assert(child != NULL);
sprintf(buf, "local name '%.100s' in '%.100s' shadows "
"use of '%.100s' as global in nested scope '%.100s'",
PyString_AS_STRING(name),
PyString_AS_STRING(st->st_cur->ste_name),
PyString_AS_STRING(name),
PyString_AS_STRING(child->ste_name)
);
return symtable_warn(st, buf);
}
static int
symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste,
@ -4489,26 +4422,17 @@ symtable_load_symbols(struct compiling *c)
while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {
flags = PyInt_AS_LONG(v);
if (st->st_nested_scopes == 0
&& (flags & (DEF_FREE | DEF_FREE_CLASS))) {
if (symtable_check_shadow(st, name, flags) < 0)
goto fail;
}
if (flags & DEF_FREE_GLOBAL)
/* undo the original DEF_FREE */
flags &= ~(DEF_FREE | DEF_FREE_CLASS);
/* Deal with names that need two actions:
1. Cell variables, which are also locals.
1. Cell variables that are also locals.
2. Free variables in methods that are also class
variables or declared global.
*/
if (st->st_nested_scopes) {
if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
if (flags & (DEF_FREE | DEF_FREE_CLASS))
symtable_resolve_free(c, name, flags, &si);
}
}
if (flags & DEF_STAR) {
c->c_argcount--;
@ -4544,7 +4468,7 @@ symtable_load_symbols(struct compiling *c)
if (PyList_Append(c->c_varnames, name) < 0)
goto fail;
} else if (is_free(flags)) {
if (ste->ste_nested && st->st_nested_scopes) {
if (ste->ste_nested) {
v = PyInt_FromLong(si.si_nfrees++);
if (v == NULL)
goto fail;
@ -4569,9 +4493,6 @@ symtable_load_symbols(struct compiling *c)
assert(PyDict_Size(c->c_freevars) == si.si_nfrees);
if (st->st_nested_scopes == 0)
assert(si.si_nfrees == 0);
if (si.si_ncells > 1) { /* one cell is always in order */
if (symtable_cellvar_offsets(&c->c_cellvars, c->c_argcount,
c->c_varnames, c->c_flags) < 0)
@ -4596,11 +4517,6 @@ symtable_init()
return NULL;
st->st_pass = 1;
/* XXX Tim: Jeremy deleted the next line and everything went to hell.
XXX It should probably get fixed by getting rid of st_nested_scopes
XXX entirely. */
st->st_nested_scopes = 1;
st->st_filename = NULL;
if ((st->st_stack = PyList_New(0)) == NULL)
goto fail;