![]() | ![]() | ![]() | Type Name Declaration Descriptors |
The first group includes all descriptors for names associated with types. This includes struct type descriptors, array type descriptors and a special descriptor for the built-in integer type. The definitions for this group of type descriptors is shown in figure *.
/* Structure used to reference common fields of type descriptor. */
struct unktypedesc {
COMMONFIELDS
int typesize; /* Memory required for var. of this type */
};
/* Structure used for array type declaration descriptors. */
struct arraydesc {
COMMONFIELDS
int typesize; /* Memory required for array of this type */
int size; /* Number of elements in array */
union dcldesc * elmntvar; /* decl. descriptor for imaginary variable of
this array's element type */
};
/* Structure used for struct type declaration descriptors. */
struct structdesc {
COMMONFIELDS
int typesize; /* Memory required for recd. of this type */
union dcldesc *fields; /* Header for list of this type's components */
};
All type name declaration descriptors share a field named typesize
which should be set equal to the number of units of memory needed
to hold an element of the type. To provide a way to write clear
code that accesses this field without determining the particular
sort of type involved, a structure named unktypedesc
is
declared and a choice of unktype
is included in the
decldesc
union type.
Structure types are described by declaration descriptors of type
structdesc
. The only special component of such a descriptor
is a pointer, fields
, to a list of declaration descriptors
for the components of the structure type.
Array types are described by declaration descriptors of type
arraydesc
. An array declaration descriptor contains a size
field in which the compiler will store the number of elements in the
array. It also needs to somehow represent the element type of the
array. The natural way to accomplish this would be to have the
array type's declaration descriptor point to the descriptor for the
element type. We will use a somewhat more complex scheme (for reasons
that will not become clear until near the end of the project).
For each array you will need to create a declaration descriptor for
an imaginary variable of the array's element type. The array type's
elmntvar
field will then be set to point to this variable
descriptor which will in turn point to the descriptor for the array's
element type.
![]() | ![]() | ![]() | Type Name Declaration Descriptors |