[Python-checkins] CVS: python/dist/src/Tools/compiler/compiler symbols.py,1.5,1.6
Jeremy Hylton
jhylton@users.sourceforge.net
Mon, 27 Aug 2001 14:06:37 -0700
Update of /cvsroot/python/python/dist/src/Tools/compiler/compiler
In directory usw-pr-cvs1:/tmp/cvs-serv23621
Modified Files:
symbols.py
Log Message:
Fix for sibling nodes that define the same free variable
Evan Simpson's fix. And his explanation:
If you defined two nested functions in a row that refer to the
same non-global variable, the second one will be generated as
though the variable were global.
Index: symbols.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/symbols.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** symbols.py 2001/04/12 07:06:25 1.5
--- symbols.py 2001/08/27 21:06:35 1.6
***************
*** 80,84 ****
def DEBUG(self):
- return
print >> sys.stderr, self.name, self.nested and "nested" or ""
print >> sys.stderr, "\tglobals: ", self.globals
--- 80,83 ----
***************
*** 163,172 ****
elif isinstance(self, FunctionScope) and sc == SC_LOCAL:
self.cells[name] = 1
! else:
child_globals.append(name)
else:
if sc == SC_LOCAL:
self.cells[name] = 1
! else:
child_globals.append(name)
return child_globals
--- 162,171 ----
elif isinstance(self, FunctionScope) and sc == SC_LOCAL:
self.cells[name] = 1
! elif sc != SC_CELL:
child_globals.append(name)
else:
if sc == SC_LOCAL:
self.cells[name] = 1
! elif sc != SC_CELL:
child_globals.append(name)
return child_globals
***************
*** 222,226 ****
self.visit(node.code, scope)
self.handle_free_vars(scope, parent)
- scope.DEBUG()
def visitLambda(self, node, parent):
--- 221,224 ----
***************
*** 244,249 ****
def handle_free_vars(self, scope, parent):
parent.add_child(scope)
- if scope.children:
- scope.DEBUG()
scope.handle_children()
--- 242,245 ----
***************
*** 299,302 ****
--- 295,306 ----
scope.add_def(node.name)
+ def visitAssAttr(self, node, scope, assign=0):
+ self.visit(node.expr, scope, 0)
+
+ def visitSubscript(self, node, scope, assign=0):
+ self.visit(node.expr, scope, 0)
+ for n in node.subs:
+ self.visit(n, scope, 0)
+
def visitAugAssign(self, node, scope):
# If the LHS is a name, then this counts as assignment.