The different kinds of AST nodes are represented by objects derived from
the tree_node
class. This base class includes features, such as
ID numbers, that are shared by all kinds of tree nodes.
The simplest kind of tree node is a tree_instr
. Each of these is
a leaf node that contains a single instruction or expression.
Conditional structures may be represented by tree_if
nodes.
The ASTs include two different kinds of loop nodes. The
tree_loop
nodes just record the control-flow structure of the
loops and are used to represent generic "do-while" loops. Many
optimizations, however, only apply to certain well-behaved types of
loops. Thus, the trees may also contain tree_for
nodes to
represent loops with scalar indices that vary from their initial to
final values, being incremented or decremented on every iteration, and
that meet various other requirements. Most Fortran DO
loops
qualify as tree_for
nodes. Those loops which do not meet the
requirements for tree_for
nodes are represented by
tree_loop
nodes instead.
Nested scopes are represented by tree_block
nodes. A
tree_block
contains a list of tree nodes and a symbol table. The
symbols and types in the table may only be referenced from within the
block. The node at the root of an AST is a special kind of
tree_block
called a tree_proc
. The tree_proc
objects use a slightly different kind of symbol table and include some
extra methods but are otherwise the same as the tree_block
objects.