Java Reference
In-Depth Information
FIGURE 4.2 The structure of a context.
The pointer
surroundingContext
points to the context for the surrounding region of
scope; the chain of these pointers is the stack that captures the nested scope in j-- programs.
The pointer
compilationUnitContext
points to the context for the enclosing compilation
unit, that is, a
CompilationUnitContext
. In the current definition of j--, there is just one
compilation unit but one might imagine an extension to j-- permitting the compilation of
several files, each of which defines a compilation unit. The pointer
classContext
points to
the context (a
ClassContext
) for the enclosing class. As we shall see below, no names are
declared in a
ClassContext
but this could change if we were to add nested type declarations
to j--.
A
CompilationUnitContext
represents the scope of the entire program and contains a
mapping from names to types:
The implicitly declared types,
java.lang.Object
, and
java.lang.String
Imported types
User-defined types, that is, types introduced in class declarations
A
ClassContext
represents the scope within a class declaration. In the j-- symbol table,
no names are declared here. All members, that is all constructors, methods and fields are
recorded in the
Class
object that represents the type; we discuss this in the next section.
If we were to add nested type declarations to j--, they might be declared here.
A
MethodContext
represents the scope within a method declaration. A method's formal
parameters are declared here. A
MethodContext
is a kind of
LocalContext
.
A
LocalContex
t represents the scope within a block, that is, the region between two
curly brackets
{
and
}
. This includes the block defining the body to a method. Local
variables are declared here.
Each kind of context derives from (extends) the class
Context
, which supplies the
mapping from names to definitions (
IDefns
). Because a method defines a local context,
MethodContext
extends
LocalContext
. The inheritance tree for contexts is illustrated in
Figure 4.3
Search WWH ::
Custom Search