Package compiler :: Module visitor :: Class ASTVisitor
[show private | hide private]
[frames | no frames]

Class ASTVisitor

Known Subclasses:
BaseVisitor

Performs a depth-first walk of the AST

The ASTVisitor will walk the AST, performing either a preorder or
postorder traversal depending on which method is called.

methods:
preorder(tree, visitor)
postorder(tree, visitor)
    tree: an instance of ast.Node
    visitor: an instance with visitXXX methods

The ASTVisitor is responsible for walking over the tree in the
correct order.  For each node, it checks the visitor argument for
a method named 'visitNodeType' where NodeType is the name of the
node's class, e.g. Class.  If the method exists, it is called
with the node as its sole argument.

The visitor method for a particular node type can control how
child nodes are visited during a preorder walk.  (It can't control
the order during a postorder walk, because it is called _after_
the walk has occurred.)  The ASTVisitor modifies the visitor
argument by adding a visit method to the visitor; this method can
be used to visit a particular child node.  If the visitor method
returns a true value, the ASTVisitor will not traverse the child
nodes.

XXX The interface for controlling the preorder walk needs to be
re-considered.  The current interface is convenient for visitors
that mostly let the ASTVisitor do everything.  For something like
a code generator, where you want to walk to occur in a specific
order, it's a pain to add "return 1" to the end of each method.

Method Summary
  __init__(self)
  default(self, node, *args)
  dispatch(self, node, *args)
  preorder(self, tree, visitor, *args)
Do preorder walk of tree using visitor...

Class Variable Summary
int VERBOSE = 0                                                                     

Method Details

preorder(self, tree, visitor, *args)

Do preorder walk of tree using visitor

Class Variable Details

VERBOSE

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.0 on Tue Jul 22 05:30:20 2003 http://epydoc.sf.net