Go to the first, previous, next, last section, table of contents.
Enumerated types are much like integer types, except that each member of
an enumeration is given a name. The TYPE_ENUM operator is
classified as one of the base type operators, and the enum_type
class which it uses is derived from the base_type class.
See section Base Types. Since an enumerated type behaves like an integer
type, the same base_type methods can be used to specify the size
and whether or not it is signed.
Like structures and unions, enumerated types are given names. The
name method returns the name for an enum_type, which
should be different from the names of other types in the symbol table
where it is defined. The set_name method automatically enters
the name in the lexicon (see section Lexicon).
Each enumerated type contains arrays to hold the names and values of its
members. The num_values method returns the number of members.
The set_num_values method may be called at any time to change the
number of members. It will allocate more space for the arrays if
necessary. The member method returns the name of a particular
member, and the value method returns its value. The members are
numbered beginning with zero. The set_member method changes the
name of a member and enters the new name in the lexicon. Similarly, the
set_value method changes the value for a method. All of the
values must fit within the size of the type, and negative values are not
allowed with unsigned enumerations.
The find_member_by_name method searches through the members of an
enumerated type for a particular name. If successful, it returns the
index of the member; otherwise, it returns a value of -1. The
find_member_by_value method returns the index of the first member
that it finds with a certain value. If the value is not found, it
returns a value of -1, just like find_member_by_name.
Go to the first, previous, next, last section, table of contents.