|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
Changer Class ReferenceA functional class to traverse an AST, and perform some transformation at each of its Nodes.
More...
|
Public Types | |
enum | Order { Preorder, Postorder, Both } |
enum | Depth { Subtree, NodeOnly } |
Public Member Functions | |
Changer (Order the_order, Depth depth, bool delete_old) | |
Create a new instance of a Changer. | |
Accessors | |
Methods to get and set fields in the class. | |
Order | order () const |
Return the order in which Nodes of an AST should be visited. | |
Depth | depth () const |
Return which Nodes of an AST should be visited. | |
bool | delete_old () const |
Return whether this Changer deletes Nodes which are removed from the AST by "at_" methods. | |
"at_" methods | |
These methods define the functions that should be performed when different classes of Nodes are encountered in the AST. The most specific "at_" method that matches a given Node's class will be called. | |
virtual Node * | at_node (Node *the_node, Order ord) |
virtual Node * | at_unit (unitNode *the_unit, Order ord) |
virtual Node * | at_def (defNode *the_def, Order ord) |
virtual Node * | at_decl (declNode *the_decl, Order ord) |
virtual Node * | at_subdecl (subdeclNode *the_subdecl, Order ord) |
virtual Node * | at_proc (procNode *the_proc, Order ord) |
virtual Node * | at_type (typeNode *the_type, Order ord) |
virtual Node * | at_prim (primNode *the_prim, Order ord) |
virtual Node * | at_tdef (tdefNode *the_tdef, Order ord) |
virtual Node * | at_ptr (ptrNode *the_ptr, Order ord) |
virtual Node * | at_array (arrayNode *the_array, Order ord) |
virtual Node * | at_func (funcNode *the_func, Order ord) |
virtual Node * | at_sue (sueNode *the_sue, Order ord) |
virtual Node * | at_struct (structNode *the_struct, Order ord) |
virtual Node * | at_union (unionNode *the_union, Order ord) |
virtual Node * | at_enum (enumNode *the_enum, Order ord) |
virtual Node * | at_suespec (suespecNode *the_suespec, Order ord) |
virtual Node * | at_expr (exprNode *the_expr, Order ord) |
virtual Node * | at_index (indexNode *the_index, Order ord) |
virtual Node * | at_const (constNode *the_const, Order ord) |
virtual Node * | at_id (idNode *the_id, Order ord) |
virtual Node * | at_binary (binaryNode *the_binary, Order ord) |
virtual Node * | at_unary (unaryNode *the_unary, Order ord) |
virtual Node * | at_cast (castNode *the_cast, Order ord) |
virtual Node * | at_comma (commaNode *the_comma, Order ord) |
virtual Node * | at_ternary (ternaryNode *the_ternary, Order ord) |
virtual Node * | at_call (callNode *the_call, Order ord) |
virtual Node * | at_initializer (initializerNode *the_initializer, Order ord) |
virtual Node * | at_stmt (stmtNode *the_stmt, Order ord) |
virtual Node * | at_block (blockNode *the_block, Order ord) |
virtual Node * | at_basicblock (basicblockNode *the_basicblock, Order ord) |
virtual Node * | at_exprstmt (exprstmtNode *the_exprstmt, Order ord) |
virtual Node * | at_target (targetNode *the_target, Order ord) |
virtual Node * | at_label (labelNode *the_label, Order ord) |
virtual Node * | at_case (caseNode *the_case, Order ord) |
virtual Node * | at_selection (selectionNode *the_selection, Order ord) |
virtual Node * | at_if (ifNode *the_if, Order ord) |
virtual Node * | at_switch (switchNode *the_switch, Order ord) |
virtual Node * | at_loop (loopNode *the_loop, Order ord) |
virtual Node * | at_while (whileNode *the_while, Order ord) |
virtual Node * | at_do (doNode *the_do, Order ord) |
virtual Node * | at_for (forNode *the_for, Order ord) |
virtual Node * | at_jump (jumpNode *the_jump, Order ord) |
virtual Node * | at_goto (gotoNode *the_goto, Order ord) |
virtual Node * | at_continue (continueNode *the_continue, Order ord) |
virtual Node * | at_break (breakNode *the_break, Order ord) |
virtual Node * | at_return (returnNode *the_return, Order ord) |
virtual Node * | at_attrib (attribNode *the_attrib, Order ord) |
virtual Node * | at_operand (operandNode *the_oper, Order ord) |
virtual Node * | at_conditiongoto (conditiongotoNode *the_condgoto, Order ord) |
virtual Node * | at_threeAddr (threeAddrNode *the_3addr, Order ord) |
virtual Node * | at_text (textNode *the_text, Order ord) |
Private Attributes | |
Order | _order |
The order in which AST Nodes should be visited. | |
Depth | _depth |
Which Nodes in the AST should be visited. | |
bool | _delete_old |
Whether old Nodes should be deleted. |
A Changer is a functional class that traverses an abstract syntax tree, and performs some transformation at each of its Nodes. At each Node, the transformation it performs depends on the class of the Node.
Corresponding to each class in the Node hierarchy, Changer defines an "at_" method. To specify the transformation that should be performed for Nodes of a particular class, create a subclass of Changer that overrides the "at_" method corresponding to that class. These "at_" methods take a Node, and return a transformed Node. By default, the "at_" methods simply return the Node they are passed. Thus, a Changer subclass only needs to override the "at_" methods corresponding to Node types that are relevant to that changer.
As the AST is traversed, the most specific "at_" method that has been defined for each Node will be called on that Node. For example, if a Changer subclass overrides "at_decl()", but not "at_subdecl()," then the "at_decl()" method wil be called for all declNodes and subDeclnodes encountered in the AST. However, if a Changer subclass overrides both "at_decl()" and "at_subdecl," then the "at_decl()" method will be called for all declNodes encountered in the AST, and the "at_subdecl()" method will be called for all subdeclNodes encountered in the AST. If you wish for both "at_subdecl()" and "at_decl()" to be called for subdeclNodes, then you should explicitly call the "at_decl()" method from "at_subdecl()."
As the changer traverses the AST, the "at_" methods for a Node can be called before its children have been visited, after its children have been visited, or both before and after its children have been visited. When the "at_" methods for a Node are called before its children, they are said to be called in "preorder." When the "at_" methods for a Node are called after its children, they are said to be called in "postorder." If "at_" methods are called both in preorder and in postorder, then the preorder call will always preceed the postorder call.
When a new Changer is created, the order(s) that Nodes are visited in should be specified. In general, all instances of a given subclass of Changer will visit Nodes in the same order. However, it may occasionally be useful to specify different orders for two different instances of the same subclass of Changer.
New instances of Changer can also specify the "depth" of the traversal. If the depth is "SubTree," then a Changer will visit the entire AST rooted at the Node that it is called on. If the depth is "NodeOnly," then the Changer will only call the "at_" method for Node it is called on, and not for any of its sub-Nodes. A Changer with a depth of NodeOnly is different from a Visitor, because the "Node.change()" method will return a transformed Node, whereas "Node.visit()" cannot return a transformed Node.
Changers may modify any fields of the Nodes it visits, including fields that contain sub-Nodes. If a field containing a sub-Node is changed in a preorder call to an "at_" method, then the AST rooted at the new sub-Node will be traversed. If a field containing a sub-Node is changed in a postorder call to an "at_" method, then the AST rooted at the new sub-Node will not be traversed.
Currently, Changers traverse the AST in a depth-first order. Preorder calls to the "at_" methods are called before descending into a Node's children, and postorder calls to the "at_" method are called after returning from the children in the traversal. At the leaves, the postorder calls to the "at_" methods immediately follow the preorder calls. However, this ordering is subject to change, and should not be relied upon. The only aspects of the AST traversal ordering which are guaranteed are:
Changers should never be used to traverse ASTs containing cycles; since they detect no mechanism to detect cycles, this would cause an infinite loop.
To use a changer "my_changer" to traverse an AST rooted at "my_node," use the code:
my_node = my_node->change(my_changer);
Definition at line 143 of file changer.h.
|
|
|
|
|
Create a new instance of a Changer. This constructor is usually called by a subclass.
|
|
Definition at line 253 of file changer.h. References at_type(). |
|
Definition at line 364 of file changer.h. References at_stmt(). |
|
Reimplemented in constantFoldingChanger. Definition at line 313 of file changer.h. References at_block(). |
|
Reimplemented in SelectionDismantle, ArrowDismantle, and ExpressionDismantle. Definition at line 286 of file changer.h. References at_expr(). |
|
Reimplemented in StaticToGlobalDismantle, and InitializerDismantle. Definition at line 310 of file changer.h. References at_stmt(). Referenced by at_basicblock(). |
|
Reimplemented in BreakContinueChanger. Definition at line 358 of file changer.h. References at_jump(). |
|
Reimplemented in ExpressionDismantle. Definition at line 301 of file changer.h. References at_expr(). |
|
Definition at line 325 of file changer.h. References at_target(). |
|
Reimplemented in ExpressionDismantle. Definition at line 292 of file changer.h. References at_expr(). |
|
Reimplemented in ExpressionDismantle. Definition at line 295 of file changer.h. References at_expr(). |
|
Reimplemented in constantPropChanger, constantFoldingChanger, and constantsChanger. Definition at line 370 of file changer.h. References at_goto(). |
|
Definition at line 280 of file changer.h. References at_index(). |
|
Reimplemented in BreakContinueChanger. Definition at line 355 of file changer.h. References at_jump(). |
|
Reimplemented in StaticToGlobalDismantle, InitializerDismantle, FlattenDismantle, and ref_clone_changer. Definition at line 232 of file changer.h. References at_def(). Referenced by at_subdecl(). |
|
Definition at line 229 of file changer.h. References at_node(). |
|
Reimplemented in LoopDismantle. Definition at line 343 of file changer.h. References at_loop(). |
|
Definition at line 268 of file changer.h. References at_sue(). |
|
Definition at line 274 of file changer.h. References at_node(). Referenced by at_binary(), at_call(), at_cast(), at_comma(), at_index(), at_initializer(), at_operand(), at_ternary(), and at_unary(). |
|
Reimplemented in SelectionDismantle, ExpressionDismantle, and FlattenDismantle. Definition at line 316 of file changer.h. References at_stmt(). |
|
Reimplemented in LoopDismantle. Definition at line 346 of file changer.h. References at_loop(). |
|
Definition at line 256 of file changer.h. References at_type(). |
|
Reimplemented in FlattenDismantle. Definition at line 352 of file changer.h. References at_jump(). Referenced by at_conditiongoto(). |
|
Reimplemented in UnusedDeclarationCleanupChanger, and constantsChanger. Definition at line 283 of file changer.h. References at_index(). |
|
Reimplemented in SelectionDismantle. Definition at line 331 of file changer.h. References at_selection(). |
|
Definition at line 277 of file changer.h. References at_expr(). Referenced by at_const(), and at_id(). |
|
Definition at line 304 of file changer.h. References at_expr(). |
|
Definition at line 349 of file changer.h. References at_stmt(). Referenced by at_break(), at_continue(), at_goto(), and at_return(). |
|
Reimplemented in LabelDismantle, FlattenDismantle, and ref_clone_changer. Definition at line 322 of file changer.h. References at_target(). |
|
Definition at line 337 of file changer.h. References at_stmt(). Referenced by at_do(), at_for(), and at_while(). |
|
Reimplemented in ref_clone_changer. Definition at line 223 of file changer.h. Referenced by at_def(), at_expr(), at_stmt(), at_text(), at_type(), and at_unit(). |
|
Definition at line 367 of file changer.h. References at_expr(). |
|
Definition at line 244 of file changer.h. References at_type(). |
|
Reimplemented in Dismantle, StaticToGlobalDismantle, ControlDismantle, ReturnDismantle, FlattenDismantle, function_inline, cfg_changer, copyPropChanger, deadCodeEliminationChanger, and UnusedDeclarationCleanupChanger. Definition at line 238 of file changer.h. References at_def(). |
|
Definition at line 250 of file changer.h. References at_type(). |
|
Reimplemented in SelectionDismantle, ReturnDismantle, FlattenDismantle, and constantPropChanger. Definition at line 361 of file changer.h. References at_jump(). |
|
Definition at line 328 of file changer.h. References at_stmt(). Referenced by at_if(), and at_switch(). |
|
Reimplemented in TernaryDismantle, and SelectionDismantle. Definition at line 307 of file changer.h. References at_node(). Referenced by at_attrib(), at_block(), at_exprstmt(), at_jump(), at_loop(), at_selection(), at_target(), and at_threeAddr(). |
|
Definition at line 262 of file changer.h. References at_sue(). |
|
Definition at line 235 of file changer.h. References at_decl(). |
|
Definition at line 259 of file changer.h. References at_type(). Referenced by at_enum(), at_struct(), and at_union(). |
|
Definition at line 271 of file changer.h. References at_type(). |
|
Reimplemented in SelectionDismantle, and ref_clone_changer. Definition at line 334 of file changer.h. References at_selection(). |
|
Definition at line 319 of file changer.h. References at_stmt(). Referenced by at_case(), and at_label(). |
|
Definition at line 247 of file changer.h. References at_type(). |
|
Reimplemented in TernaryDismantle. Definition at line 298 of file changer.h. References at_expr(). |
|
Definition at line 376 of file changer.h. References at_node(). |
|
Reimplemented in FlattenDismantle, function_inline, constantPropChanger, constantFoldingChanger, deadCodeEliminationChanger, constantsChanger, and deadcodeChanger. Definition at line 373 of file changer.h. References at_stmt(). |
|
Reimplemented in TernaryDismantle, and ExpressionDismantle. Definition at line 241 of file changer.h. References at_node(). Referenced by at_array(), at_func(), at_prim(), at_ptr(), at_sue(), at_suespec(), and at_tdef(). |
|
Reimplemented in ExpressionDismantle. Definition at line 289 of file changer.h. References at_expr(). |
|
Definition at line 265 of file changer.h. References at_sue(). |
|
Reimplemented in Dismantle, and StaticToGlobalDismantle. Definition at line 226 of file changer.h. References at_node(). |
|
Reimplemented in LoopDismantle. Definition at line 340 of file changer.h. References at_loop(). |
|
Return whether this Changer deletes Nodes which are removed from the AST by "at_" methods.
Definition at line 209 of file changer.h. References _delete_old. Referenced by change_list(). |
|
Return which Nodes of an AST should be visited. A value of SubTree specifies that the entire AST should be traversed. A value of NodeOnly specifies that only the root Node in the AST should be visited. Definition at line 204 of file changer.h. References _depth. |
|
Return the order in which Nodes of an AST should be visited. Nodes can be visited before their children (Preorder), after their children (Postorder), or both (Both). Definition at line 196 of file changer.h. References _order. |
|
Whether old Nodes should be deleted.
Definition at line 162 of file changer.h. Referenced by delete_old(). |
|
Which Nodes in the AST should be visited.
Definition at line 158 of file changer.h. Referenced by depth(). |
|
The order in which AST Nodes should be visited.
Definition at line 154 of file changer.h. Referenced by order(). |
Generated on February 1, 2006
Back to the C-Breeze home page