Java Reference
In-Depth Information
2. During analysis, JFieldDeclaration 's analyze() rewrites the initializing expression,
5 as an explicit assignment statement, n=5; producing the sub-tree illustrated in
(b).
3. Finally, when analysis returns back up the AST to JClassDeclaration (after recurs-
ing down the tree, these methods also back out and they may do tasks on the way
back up), its analyze() copies the initializations to fields in its node. It separates
the initializations into two lists: staticFieldInitializations for static fields and
instanceFieldInitializations for instance fields. In the case of our example, n is
static, and so the initialization is added to staticFieldInitializations as illus-
trated in (c).
In addition to this tree surgery on field initializations, analyze() does little at the top
of the AST. The only other significant task is in JMethodDeclaration , where analyze()
declares parameters and allocates locations relative to the base of the current stack frame.
We discuss this in the next section.
4.5.2 Declaring Formal Parameters and Local Variables
MethodContext s and LocalContext s
Both formal parameters and local variables are declared in the symbol table and allocated
locations within a method invocation's run-time stack frame. For example, consider the
following class declaration:
publicclassLocals{
publicintfoo(intt,Stringu){
intv=u.length();
{
intw=v+5,x=w+7;
v=w+x;
}
{
inty=3;
intz=v+y;
t=t+y+z;
}
returnt+v;
}
}
The stack frame allocated for an invocation of foo() at run- time by the JVM is illustrated
in Figure 4.6. Because foo() is an instance method, space is allocated at location 0 for
this .
 
Search WWH ::




Custom Search