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

ID Numbers for Tree Nodes and Instructions

Within each procedure, the tree nodes and instructions are assigned unique ID numbers. These numbers can be used to identify the nodes and instructions internally and in annotations that are written to the output files. The number method retrieves the ID numbers. It is generally best to avoid using the numbers on tree_instr nodes, because they are not written to the output files and the tree_instr nodes are automatically rearranged when converting between expression trees and flat lists of instructions. Instead, use the ID numbers for the corresponding instructions.

The number_instrs method in the tree_proc class assigns ID numbers to tree nodes and instructions that do yet have numbers (i.e. those that were created since the procedure was read in). This method is called automatically before each procedure is written out, but you may also call it whenever ID numbers are needed for new tree nodes or instructions. The next unused ID number is recorded in the procedure symbol table. In the proc_symtab class, the next_instr_num method returns the next ID number and increments the counter; the instr_num method returns the next number but does not increment the counter. Since you can only assign new ID numbers with the number_instrs method, you will rarely, if ever, need to access this counter directly.

In some circumstances, the tree node and instruction ID numbers must be reset. The most common case is when moving code from one procedure to another. Since the ID numbers are only unique within each procedure, moving things between procedures is likely to create duplicate ID numbers. To avoid this problem, the tree_node, tree_node_list, and instruction classes provide clear_numbers methods to reset the ID numbers. These methods recursively descend the ASTs and expression trees to set all of the ID numbers within the object and its children to zero.


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