next up previous
Next: Class Definition Up: A Loop Peeling Changer Previous: A Loop Peeling Changer

Class Declaration: looppeel.h

Here is our Changer's class declaration:

//
// looppeel.h
//

class LoopPeelingChanger: public Changer {

        // This function will peel a While loop

        Node * peel_while_loop (whileNode *);

        // This function will peel a Do loop

        Node * peel_do_loop (doNode *);

        // This function will peel a For loop

        Node * peel_for_loop (forNode *);

        // This method will peel all loops in the program

        virtual Node * at_loop (loopNode *, Order);

        public:

        // The constructor for LoopPeelingChanger will call the constructor 
        // for Changer such that LoopPeelingChanger will visit tree in 
        // Postorder.

        LoopPeelingChanger (void) :
                Changer(Postorder, Subtree, false) { }

        // This function peels one loop, calling one of the private functions 
        // above.  peel_loop() can be used from a subclass of 
        // LoopPeelingChanger to peel just one loop.

        Node * peel_loop (loopNode *);
};

Most of the member functions of a Walker or Changer accept and return a (subclass of) Node *. The parameter is the old loop, before peeling. The return value contains the newly constructed result of peeling the loop.

Note that loopNode is an abstract class, whose subclasses are whileNode, doNode and forNode. This gives rise to the at_loop() virtual function of the Changer (and Walker); from that point, we are guaranteed to be working with a loop, and we can find out (using the typ() of the loopNode *) what kind of loop it is, i.e. typ() will be For, While or Do.



Adam C. Brown 2006-01-26