Go to the first, previous, next, last section, table of contents.


Tree Node Lists

A tree_node_list is a doubly-linked list of tree nodes, derived from the dlist class. See section Doubly-Linked Lists. Most nodes in an AST have their children recorded in tree node lists. For example, the body of a block node is a tree node list. Besides the standard list features, each tree node list includes a back-pointer to its parent tree node. These pointers are maintained automatically by the SUIF library and can be accessed using the parent method. In addition, each node on a tree node list contains pointers back to the list and the list element. See section Other Features Shared by All Tree Nodes. These pointers are set by the set_elem method (see section Generic Lists) which is automatically called every time an element is added to the list.

In a tree_for node, the lower bound, upper bound, and step value are usually treated as operands; however, the operands are actually stored as tree node lists. See section For Nodes. Each of these lists is required to contain a single expression with a dummy copy instruction at the root. The destination of the dummy copy must be a null operand. The tree_node_list class includes several methods to handle these special lists. The is_op method checks if the list consists of a single copy instruction with a null destination. The op method retrieves the operand stored in the list. If after converting the list to expression tree form, the is_op method returns TRUE, the op method returns the source operand of the dummy copy instruction; otherwise, an error occurs. The set_op method is used to set the contents of the tree node list to a dummy copy instruction with the specified operand as its source. The list must either be empty or already contain the dummy copy. Finally, the op_is_intconst method checks if the operand in the tree node list is a constant integer, and if so, returns the value.

Tree node lists can easily be printed out as text. The print method simply iterates through the list and calls the print method for each tree node. The optional depth parameter specifies the indentation level to be used. A separate method is used to print tree node lists that hold tree_for operands. If the is_op method for one of these lists returns TRUE, the print_expr method prints the operand directly. Otherwise, it prints the list as usual.


Go to the first, previous, next, last section, table of contents.