mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
81f7eb6c6b
commit
46cc7c0f7b
6 changed files with 692 additions and 690 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue