annotate python/c3/astprinter.py @ 172:5a7d37d615ee

Added function to IR
author Windel Bouwman
date Thu, 04 Apr 2013 17:58:37 +0200
parents 8104fc8b5e90
children c1ccb1cb4cef
rev   line source
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
1 from .astnodes import *
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
2 from .scope import *
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
3 from .visitor import Visitor
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
4
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
5 class AstPrinter:
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
6 def __init__(self):
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
7 self.visitor = Visitor(self.print1, self.print2)
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
8 def printAst(self, pkg):
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
9 self.indent = 0
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
10 self.visitor.visit(pkg)
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
11 def print1(self, node):
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
12 print(' ' * self.indent + str(node))
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
13 self.indent += 2
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
14 def print2(self, node):
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
15 self.indent -= 2
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents:
diff changeset
16