Java Reference
In-Depth Information
EnumTypeDescriptor
constants => a list of symbol nodes
EnumAttributes
myValue => an integer
enumType => a type reference
Figure 8.25: Type and Attribute Descriptor Objects for Enumerations
method for processing an EnumDefiningAST node, as with those
for processing records and arrays, will build a TypeDescriptor that describes
the enumeration type. In addition, each of the identifiers used to define the
enumeration type is entered into the current symbol table. Its attributes will
indicate that it is an enumeration constant, and include the value used to rep-
resent it and a reference to the TypeDescriptorfor the enumeration type itself.
The type will be represented by a list of the symbols and Attributesrecords for
its constants. The required specializations of Attributesand TypeDescriptorare
illustrated in Figure 8.25.
The
visit
method in Figure 8.23 begins at Marker 45 by getting a new
EnumTypeDescriptor and initializing a local variable nextval that will be used
to define the values of the constants of the enumeration type. The loop that
begins at Marker 46 processes each of the constants of the enumeration type
in turn. As with all of the other kinds of names declared in this chapter, a check
is done at Marker 47 to be sure that the constant name is not already declared
in this scope. If the name can be added to the current scope, then the block of
code at Marker 48 creates an Attributes record for it, and sets its value from
nextval and its type as the enumeration type currently being defined. The body
of the constant declaring loop finishes at Marker 49 by entering the constant
name in the symbol table and also adding its name to the list of constants
in the TypeDescriptor that describes the enumeration type. After executing
this loop for all of the constants in the type definition, the
The
visit
method com-
pletes its work at Marker 50 by including a reference to the now completed
EnumTypeDescriptor in the EnumTypeNode in the AST for the enumeration
type. Figure 8.26 shows the EnumTypeDescriptorthat would be constructed to
represent the enumeration type defined by (red, yellow, blue, green).
visit
 
Search WWH ::




Custom Search