summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/visitor.py
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-08-12 20:32:46 (GMT)
committerThomas Wouters <thomas@python.org>2000-08-12 20:32:46 (GMT)
commit46cc7c0f7b7583927b8a253cdba87535c6522184 (patch)
treea2e781df185e6d78f53c3cf310f97ed5c8d8e6db /Lib/compiler/visitor.py
parent81f7eb6c6b50fb2d631c31a69fbbd4a68b9d2a50 (diff)
downloadcpython-46cc7c0f7b7583927b8a253cdba87535c6522184.zip
cpython-46cc7c0f7b7583927b8a253cdba87535c6522184.tar.gz
cpython-46cc7c0f7b7583927b8a253cdba87535c6522184.tar.bz2
Bring Tools/compiler almost up to date. Specifically:
- fix tab space issues (SF patch #101167 by Neil Schemenauer) - fix co_flags for classes to include CO_NEWLOCALS (SF patch #101145 by Neil) - fix for merger of UNPACK_LIST and UNPACK_TUPLE into UNPACK_SEQUENCE, (SF patch #101168 by, well, Neil :) - Adjust bytecode MAGIC to current bytecode. TODO: teach compile.py about list comprehensions.
Diffstat (limited to 'Lib/compiler/visitor.py')
-rw-r--r--Lib/compiler/visitor.py44
1 files changed, 22 insertions, 22 deletions
diff --git a/Lib/compiler/visitor.py b/Lib/compiler/visitor.py
index d0e5223..32e72e1 100644
--- a/Lib/compiler/visitor.py
+++ b/Lib/compiler/visitor.py
@@ -38,7 +38,7 @@ class ASTVisitor:
def __init__(self):
self.node = None
- self._cache = {}
+ self._cache = {}
def preorder(self, tree, visitor):
"""Do preorder walk of tree using visitor"""
@@ -47,7 +47,7 @@ class ASTVisitor:
self._preorder(tree)
def _preorder(self, node, *args):
- return apply(self.dispatch, (node,) + args)
+ return apply(self.dispatch, (node,) + args)
def default(self, node, *args):
for child in node.getChildren():
@@ -56,18 +56,18 @@ class ASTVisitor:
def dispatch(self, node, *args):
self.node = node
- meth = self._cache.get(node.__class__, None)
- className = node.__class__.__name__
- if meth is None:
- meth = getattr(self.visitor, 'visit' + className, self.default)
- self._cache[node.__class__] = meth
+ meth = self._cache.get(node.__class__, None)
+ className = node.__class__.__name__
+ if meth is None:
+ meth = getattr(self.visitor, 'visit' + className, self.default)
+ self._cache[node.__class__] = meth
if self.VERBOSE > 0:
if self.VERBOSE == 1:
if meth == 0:
print "dispatch", className
else:
print "dispatch", className, (meth and meth.__name__ or '')
- return apply(meth, (node,) + args)
+ return apply(meth, (node,) + args)
class ExampleASTVisitor(ASTVisitor):
"""Prints examples of the nodes that aren't visited
@@ -80,11 +80,11 @@ class ExampleASTVisitor(ASTVisitor):
def dispatch(self, node, *args):
self.node = node
- meth = self._cache.get(node.__class__, None)
- className = node.__class__.__name__
- if meth is None:
- meth = getattr(self.visitor, 'visit' + className, 0)
- self._cache[node.__class__] = meth
+ meth = self._cache.get(node.__class__, None)
+ className = node.__class__.__name__
+ if meth is None:
+ meth = getattr(self.visitor, 'visit' + className, 0)
+ self._cache[node.__class__] = meth
if self.VERBOSE > 1:
print "dispatch", className, (meth and meth.__name__ or '')
if meth:
@@ -92,15 +92,15 @@ class ExampleASTVisitor(ASTVisitor):
elif self.VERBOSE > 0:
klass = node.__class__
if not self.examples.has_key(klass):
- self.examples[klass] = klass
- print
- print self.visitor
- print klass
- for attr in dir(node):
- if attr[0] != '_':
- print "\t", "%-12.12s" % attr, getattr(node, attr)
- print
- return apply(self.default, (node,) + args)
+ self.examples[klass] = klass
+ print
+ print self.visitor
+ print klass
+ for attr in dir(node):
+ if attr[0] != '_':
+ print "\t", "%-12.12s" % attr, getattr(node, attr)
+ print
+ return apply(self.default, (node,) + args)
_walker = ASTVisitor
def walk(tree, visitor, verbose=None):