Java Reference
In-Depth Information
Marker 53 , where values are designated for the rest of the fields of the type
descriptor for the class. Since only a limited number of modifiers are possible in
a class declaration, fields have been included in the type descriptor to record
the presence or absence of each possible modifier. Going on to the code at
Marker 54 , a new symbol table feature is required in order to handle name
resolution within the body of a class. All of the names declared in the parent
class (and its ancestor classes) must be directly visible as the body is being
processed. We assume there is a symbol table method named
incorporate
available to implement this extended lookup rule. It is used to include the
names visible in the parent class in the symbol table defined for the current
class ( TypeRe f . names ). After this step, that symbol table is set as the currently
open name scope. This step creates the appropriate symbol table environment
for processing the fields , constructors ,and methods subtrees. The three calls
beginning at Marker 55 propagate the current TopDeclVisitor to each of these
subtrees.
In the last steps of this method, the symbol table for this class is
popped o
the symbol table stack so that the symbol environment returns to
what it was before the execution of this visitor, with the addition of the name
of this class to that environment, and the value of currentClass is returned to
null , since we are no longer within a class declaration. If nested classes are
allowed by the language being compiled, we would instead restore a saved
value in this last statement.
ff
method as written above deals with modifiers final and abstract ,
as are included in Java. These modifiers put restrictions on how the class name
can be used, and thus imply additional checks in appropriate
The
visit
methods.
In fact, fully implementing the meaning of final requires the addition of a
check to this ClassDeclaringvisitor. Just after the check is done for parentClass
naming a class, we must also add a check that the class it names has not been
declared to be final . On the other hand, abstract will require a check elsewhere
that the name of an abstract class is not used in a constructor.
visit
The symbol table requirements of classesmake the use of a separate symbol
table structure for each scope, as illustrated in Figure 8.3, a more appropriate
technique for object-oriented languages than the alternative single symbol
table structure approach detailed in Section 8.3.3. In addition, the inclusion of
the
method in the interface requires us to consider yet another
requirement on our data structure. With the addition of this feature, the
lookup process for a name must proceed first up the list of symbol tables
for ancestor classes before traversing through the stack of scopes that enclose
the current classes (which may include another class, if nested classes are
allowed by the language). Multiple inheritance complicates the picture still
further. Exercise 23 considers the impact of this combination of features. One
more change to the symbol table interface is required to handle class (and
method) declarations. A new version of
incorporate
open
S
cope
is used just after the call
to
incorporate
at Marker 54 . It takes a symbol table as a parameter, in this
 
Search WWH ::




Custom Search