next up previous
Next: Changers Up: Walkers Previous: A Sample Walker: recursionWalker

Invoking a Walker

Every AST node class has a walk member function that accepts an object of (sub)class Walker. By calling this member function of some node with an object of your walker class, you can start traversing the tree from that node. Often, you'll want to run your walker on the entire AST; to do this, you can use the following code segment, where yourWalker is the type name for your walker.

        yourWalker w;
        for (unit_list_p u=CBZ::Program.begin(); u!= CBZ::Program.end(); u++)
                (*u)->walk (w);

This calls the walk method for each unitNode in the program using your walker. This is the kind of code you would stick into a phase; see the section on phases.



Calvin Lin
2002-01-31