Java Reference
In-Depth Information
MethodDeclaring
name
modifiers
returnType
Identifier
type
Identifier
type
parameters
body
attributeRef
attributeRef
name
name
Subtree of
Declarations
and Statements
List of
paramDeclaring
Figure 8.30: Abstract Syntax Tree for a Method Declaration
case, the symbol table for the current class, and makes that symbol table the
new open scope. It can be distinguished from the previously defined version
of
by standard overloading resolution rules.
The final feature of classes that we will consider in this section is the
list of interface names that may be part of a class declaration in Java. Each
interface has a set of declarations associated with it, again represented by a
symbol table. After all of the declarations of a class have been processed, its
declarations must be checked against each of the interfaces specified, in order
to ensure that all of the interfaces are indeed fully implemented by the class.
The list of interfaces must become one of the fields of the class type so that
appropriate type checking can be done when an instance of the class is used
in a context that requires an object conforming to an interface.
open
S
cope
8.7.2 Processing Method Declarations
The AST node in Figure 8.30 illustrates the information available to the
visit
method for a method declaration. As with other declarations, the visit to a
MethodDeclaringnode will create a new entry in the current symbol table for
the method name. Since the body defines a new scope, as is the case for a class,
a new nested symbol table will be created by this
method.
The MethodDeclaring visitor is found in Figure 8.31. It does not make a
call to
visit
method for a ClassDeclaring
node. Rather, the various subtrees referenced by the MethodDeclaring node
are processed by visitors in a more customized way. This process begins at
Marker 56 , where an instance of TypeVisitoris created for the returnType .The
result of this visit, found in the type field of the Identifier node referenced by
returnType , is set as the return type of the method. Note that no check is
done for errorType , since we want to process the rest of this declaration even
visit
C
hildren
, as was the case for the
visit
 
 
 
Search WWH ::




Custom Search