next up previous contents
Next: Writing a Pass Up: Walkers Previous: Using A Selective Walker   Contents

Using A Group Walker

As discussed above, a group walker allows you to call a different function operator for each class that you are interested in. Below is an example, simplified from the actual code. In this code, the constructor appends a set of selective walkers to the group walker. These are the individual walkers for the various classes of object of interest. They will be invoked in a single pass through the program. It is a good idea to append the selective walkers in the constructor, as it allows others to extend the walker easily to work with new constructs. For example, a programmer can define some new loop constructs as an extension to SUIF. He or she can simply derive from this class and add more cases to the derived class's constructor. Any changes we make to this code automatically takes effect on the new walker.

     class RemoveIfAndLoopWalker: public GroupWalker {
         RemoveIfAndLoopWalker(SuifEnv* the_env, ProcedureDefinition* proc_def);
         (SuifEnv* the_env, ProcedureDefinition* proc_def)
         : GroupWalker(the_env) {
         append_walker(new while_statement_walker(the_env));
         append_walker(new do_while_statement_walker(the_env));
         append_walker (new if_statement_walker(the_env));
         append_walker (new c_for_statement_walker(the_env);

SUIF Nightly Build