Java Reference
In-Depth Information
FIGURE 4.10 A locally declared variable (a) before analysis; (b) after analysis.
When the variable denotes a field, analysis is a little more interesting. For example,
consider the analysis of the static field
n
, when it appears in the
main()
method of our
Factorial
class example above.
1. Figure 4.11(a) shows the
JVariable
before it is analyzed.
2. Its name is looked up in the symbol table but is not found. So the defining type (the
type declaration enclosing the region where the variable appears) is consulted;
n
is
found to be a static field in class
Factorial
.
3. The implicit static field selection is made explicit by rewriting the tree to represent
pass.Factorial.n
. This produces the
JFieldSelection
illustrated in Figure 4.11
(b).
4. The
JFieldSelection
produced in step 3 is recursively analyzed to determine the
types of its target and the result, as illustrated in Figure 4.11(c).
5. It is this sub-tree that is returned to replace the original
JVariable
(a) in the parent
AST. This tree rewriting is the reason that
analyze()
everywhere returns a (possibly
rewritten) sub-tree.
FIGURE 4.11 Analysis of a variable that denotes a static field.
Search WWH ::
Custom Search