Java Reference
In-Depth Information
One new mechanism is necessary to implement the semantic checking re-
quired by classes and methods. Certain validity checks described in Chapter 9
will require reference to the class or method currently being compiled. Our
AST representation does not readily provide access to this information, since
the node representing the current class or method may be arbitrarily far up
the tree and, in addition, our tree nodes as described thus far do not include
upward links. Rather than making a radical change in our representation, we
introduce several methods that are defined as visible within all of our
visit
methods. The best way to implement these methods depends on the particu-
lar language being used, so no concrete implementation is specified here. The
methods are:
procedure
set
C
urrent
C
lass
( ClassAttributes c )
function
get
C
urrent
C
lass
() returns ClassAttributes
procedure
set
C
urrent
M
ethod
( MethodAttributes m )
function
get
C
urrent
M
ethod
() returns MethodAttributes
procedure
set
C
urrent
C
onstructor
( MethodAttributes m )
function
get
C
urrent
C
onstructor
() returns MethodAttributes
methods as
processing begins for declarations of each kind of construct. Various
The
visit
methods in this section will make use of the
set
visit
methods in Chapter 9 will use the
methods to access the information
they need about the context in which they are operating. Note that these
methods distinguish between the context created by a constructor declaration
and a method declaration, though both are represented by a MethodAttributes
structure.
get
8.7.1 Processing Class Declarations
A class declaration may specify a parent class to which the defined class is
related by inheritance. In some languages, such as Java, a class declaration
may begin with modifiers such as abstract and final ,whicha
ect properties
or uses of the class. Java class declarations may also name a set of interfaces
implemented by the class. The AST node in Figure 8.27 includes subtrees
for all of these features except
ff
interfaces
implemented. That feature will be
considered separately.
As has typically been the case for our declarations-processing visitors, the
visit
method for a ClassDeclaringnodeworks with the AST subtrees accessible
from the node as needed in order to implement a class declaration. The code
in Figure 8.29 begins at Marker 51 with the creation of a TypeDescriptor for
the class and the creation of a symbol table to hold the names declared within
the class. These steps are followed by creation of an Attributesstructure for the
class and entry of the name of the class in the current symbol table. Figure 8.28
illustrates the information that is associated with the class name in its symbol
 
 
Search WWH ::




Custom Search