1.1 --- a/micropython/ast.py Wed May 02 01:01:58 2012 +0200
1.2 +++ b/micropython/ast.py Wed May 02 01:03:55 2012 +0200
1.3 @@ -52,7 +52,6 @@
1.4 container.
1.5 """
1.6
1.7 - ASTVisitor.__init__(self)
1.8 Assembler.__init__(self, program)
1.9 self.visitor = self
1.10 self.module = module
2.1 --- a/micropython/common.py Wed May 02 01:01:58 2012 +0200
2.2 +++ b/micropython/common.py Wed May 02 01:03:55 2012 +0200
2.3 @@ -19,7 +19,6 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 -import compiler.visitor
2.8 import operator
2.9
2.10 try:
2.11 @@ -263,16 +262,25 @@
2.12
2.13 # Visitors and activities related to node annotations.
2.14
2.15 -class ASTVisitor(compiler.visitor.ASTVisitor):
2.16 +class ASTVisitor:
2.17
2.18 "A base class for visitors."
2.19
2.20 + def default(self, node, *args):
2.21 + for n in node.getChildNodes():
2.22 + self.dispatch(n)
2.23 +
2.24 def dispatch(self, node, *args):
2.25
2.26 "Dispatch using 'node', annotating any raised exceptions."
2.27
2.28 + # Dispatch via a generic visit method.
2.29 +
2.30 try:
2.31 - return compiler.visitor.ASTVisitor.dispatch(self, node, *args)
2.32 + return node.visit(self, *args)
2.33 +
2.34 + # Annotate the exception in case of failure.
2.35 +
2.36 except NodeProcessingError, exc:
2.37 if exc.astnode is None:
2.38 exc.astnode = node
3.1 --- a/micropython/inspect.py Wed May 02 01:01:58 2012 +0200
3.2 +++ b/micropython/inspect.py Wed May 02 01:03:55 2012 +0200
3.3 @@ -92,7 +92,6 @@
3.4 used to provide access to other modules when required.
3.5 """
3.6
3.7 - ASTVisitor.__init__(self)
3.8 Module.__init__(self, name, importer)
3.9 self.visitor = self
3.10
4.1 --- a/micropython/report.py Wed May 02 01:01:58 2012 +0200
4.2 +++ b/micropython/report.py Wed May 02 01:03:55 2012 +0200
4.3 @@ -502,7 +502,6 @@
4.4 "A module source code browser."
4.5
4.6 def __init__(self, module, program):
4.7 - ASTVisitor.__init__(self)
4.8 self.visitor = self
4.9 self.module = module
4.10 self.program = program
4.11 @@ -864,6 +863,12 @@
4.12 self.stream.write("</div>\n")
4.13 self.stream.write("</div>\n")
4.14
4.15 + def visitYield(self, node):
4.16 + self.stream.write("<div class='yield nowrap'>\n")
4.17 + self._keyword("yield")
4.18 + self.dispatch(node.value)
4.19 + self.stream.write("</div>\n")
4.20 +
4.21 # Expression-related helper methods.
4.22
4.23 def _visitBitBinary(self, node, name, symbol):
4.24 @@ -1009,6 +1014,15 @@
4.25 self._span_end()
4.26 self._span_end()
4.27
4.28 + def visitIfExp(self, node):
4.29 + self._span_start("ifexp")
4.30 + self.dispatch(node.then)
4.31 + self._keyword("if")
4.32 + self.dispatch(node.test)
4.33 + self._keyword("else")
4.34 + self.dispatch(node.else_)
4.35 + self._span_end()
4.36 +
4.37 def visitKeyword(self, node):
4.38 self._span_start("keyword-arg")
4.39 self.stream.write(node.name)