next up previous
Next: Changer subclass definitions Up: Changers Previous: Definition of a Changer

How Changers Work

A changer works similarly to a Walker subclass. You define your changer and override the at_-functions of the nodes you're interested in, but your new member functions must now return a Node * ; this is a pointer to the new value you want that node to assume. Note: You need to be careful what you return from a changer's at_-function; it must ``fit'' in the AST where the old node was. For instance, if you return some sort of expression node from, say, the at_stmt member function, something is going to go wrong because somewhere in the tree there will be an expression node where a statement node belongs.



Calvin Lin
2002-01-31