Java Reference
In-Depth Information
/
Visitor code for Marker 18 on page 302
/
procedure
visit
(StructDefining structde f )
typeRe f
new TypeDescriptor( structType )
typeRe f . fields
39
new SymbolTable()
foreach decl structde f . fieldList do
40
call decl . f ieldType . accept( this )
foreach id vld . idList do
41
if typeRe f . fields . declaredLocally( id . name )
then
call
42
error
(” Name cannot be redeclared :”
, id . name )
id . type errorType
id . attributesRe f
null
else
attr . kind f ieldAttributes
attr . f ieldType decl . f ieldType . type
call typeRe f . fields . enterSymbol( id . name , attr )
id . type decl . f ieldType . type
id . attributesRe f attr
43
structde f . type typeRe f
44
end
Figure 8.22:
visit
method in TypeVisitor for StructDefining.
outer loop, the TypeVisitor is propagated to the AST representing the type
specification for one set of fields. Within the inner loop, each field identifier is
checked for previous declaration within the struct (at Marker 42 ). Presuming
that it passes this test, beginning at Marker 43 ,aFieldAttriburesrepresentation
is created for the name, which is then entered into the symbol table for the
struct. The
method finishes at Marker 44 by leaving a reference to the
completed TypeDescriptor for the struct type within the StructDefining node
that represents it in the AST.
visit
8.6.7 Enumeration Types
An enumeration type is defined by a list of distinct identifiers. Each identifier
is a constant of the enumeration type. These constants are ordered by their
position in the type definition and are represented internally by integer values.
Typically, the value used to represent the first identifier is zero, and the value
for each subsequent identifier is one more than that for its predecessor in the
list (although Ada does allow a programmer to specify the values used to
represent enumeration literals). If runtime error checking is enabled, then the
value zero might be used to represent ”uninitialized,” with valid enumeration
values begining at one. An abstract syntax tree for an enumeration type
definition is shown in Figure 8.24.
 
 
Search WWH ::




Custom Search