Java Reference
In-Depth Information
/
Visitor code for Marker 17 on page 302
/
procedure
visit
(ArrayDefining arrayde f )
call
visit
C
hildren
( arrayde f )
arrayde f . type
new TypeDescriptor( arrayType )
arrayde f . type . elementType arrayde f . elementType . type
arrayde f . type . arraysize arrayde f . size . value
38
end
Figure 8.20:
visit
method in TypeVisitor for ArrayDefining.
8.6.5 Static Array Types
The most common form of array type constructor found in programming
languages enables a programmer to define an array type by specifying the
type of its elements and the number of elements it contains. The element type
can be described by a type name or a general type definition included as part
of the array definition. Since visiting either form of type specification yields a
reference to a type descriptor, the visitor for the ArrayDefiningnode need not
distinguish between these two cases.
The number of elements in the array is defined either by a single integer
literal (in the casewhere the lower bound is a value defined by the language) or
a pair of literals that specify lower andupper bounds. TheAST in Figure 8.19(a)
illustrates the case where only a single integer is allowed in the syntax for an
array definition. This syntax is used in languages where the lower bound of
an array is defined by the language as a fixed value (either 0 or 1) and the
integer specifies the number of elements in the array. The
method in this
section is written for processing this form of AST. The tree in Figure 8.19(b)
illustrates the case where a language allows more-flexible array definitions in
which both the lower and upper bounds are specified and these bounds can
be defined by expressions involving named constants as well as literals. Thus
expression trees appear in the AST for the two bounds. The
visit
visit
method for
the tree in Figure 8.19(b) is considered in Exercise 18.
method for an ArrayDefining node appears in Figure 8.20. It
builds a TypeDescriptor that describes the array type. The required special-
ization of TypeDescriptor was presented in Figure 8.10 of Section 8.5.1. The
pseudocode for the
The
visit
to process
the subtrees that describe its size and element type. Note that if the language
allows the size to be described by a constant expression, then the expression's
value can be computed by visiting the expression subtree with a specialized
visitor class. A new ArrayTypeDescriptor is created at Marker 38 and the
values it must contain are obtained from the elementType and size subtrees on
the following lines.
visit
method begins by invoking
visit
C
hildren
 
 
Search WWH ::




Custom Search