Java Reference
In-Depth Information
TypeDeclaring
typeName
typeSpec
Identifier
Type
type
Subtree
attributesRef
name
Figure 8.15: Abstract Syntax Tree for Type Declarations
detail in the following section.
8.6.3 Type Declarations
We have just seen how type name references are processed when used in
variable declarations. We now consider how type declarations are processed
to create the structures accessed by type references. A type declaration in any
language includes a name and a description of the type to be associated with
it. The abstract syntax tree shown in Figure 8.15 can be used to represent such
a declaration regardless of its particular syntax.
As seen in Figure 8.16, the actions performed by the
method that de-
clares a type are similar for those used for declaring a variable. The type iden-
tifier must be entered into the current symbol table and an Attributesdescriptor
associated with it. In this case, the Attributesdescriptor must indicate that the
identifier names a type and must contain a reference to a TypeDescriptor for
the type it names.
Figure 8.15 and the
visit
method leave unanswered the obvious question
of what kind of subtree is pointed to by typeSpec . This part of the abstract
syntax tree must define a type that is to be represented by typeName .Since
type names are given to types defined by a programmer, typeSpec can point to
a subtree that represents any form of type constructor allowed by the language
being compiled. In the next two sections, we will be describing how to process
two of the most common examples of such constructors: definitions of struct
and array types.
By using TypeVisitor (rather than TopDeclVisitor) to process the subtree
referenced by typeSpec , we require that the semantic processing for a type
definition result in the construction of a TypeDescriptor.Aswehaveju t
seen, the semantic processing for TypeDeclaringassociates a reference to that
TypeDescriptorwith a type name. Notice that using this approach means that
visit
 
Search WWH ::




Custom Search