The second group of related forms of declaration descriptors are
those for things that act like variables: actual variables, formal
parameter names and record components. Again, we define a component
of the decldesc union type
that can be used to access the shared components of any one of the
members of this group. This component is named unkvar.
The declaration for the three declaration descriptor formats that
fall in this group are shown in figure *.
/* Structure used for variable declaration descriptors. */
struct vardesc {
COMMONFIELDS
union dcldesc * vartype; /* decl. descriptor for the variable's type */
int disp; /* disp. within activation record or globals */
};
/* Structure used for formal parameter declaration descriptors. */
struct formaldesc {
COMMONFIELDS
union dcldesc * vartype; /* decl. descriptor for the formal's type */
int disp; /* disp. within activation record */
union dcldesc * formallink; /* link for list of proc's formals. */
int isVal; /* True if call by value formal */
};
/* Structure used for record field name declaration descriptors. */
struct fielddesc {
COMMONFIELDS
union dcldesc * vartype; /* decl. descriptor for component's type */
int disp; /* displacement to field within record */
union dcldesc * hashlink; /* link pointer for hash chain */
union dcldesc * recdtype; /* decl. descriptor for type to which the */
/* component belong */
union dcldesc *fieldlink; /* Next pointer for type's list of fields */
};
There are two fields shared by the declaration descriptors of variables,
formals and record components. The first is vartype which should
be set equal to a pointer to the declaration descriptor for
the variable or component type. The second is disp which
should be set equal to the displacement to the field or variable within
the record or activation record in which it is located. These are
the only special fields in the record type used for variable declaration
descriptors, vardesc.
Descriptors for formal parameters contain two additional fields.
The isVal field is basically a Boolean flag set to "true" (i.e.
1) if the parameter is to be passed by value and to "false (i.e. 0)
if the parameter is passed by reference. In addition, the formallink
field is used to chain the descriptors for the parameters of a given
procedure or function into a list.
Record fields names are associated with declaration descriptors of
type fielddesc.
The recdtype component of each such descriptor
is used to hold a back pointer to
the descriptor for the record type to which the component belongs.
The hashlink field is used to build the chains of
descriptors that form the hash table used to look up the descriptor
associated with a reference to a record field name.
Finally, the fieldlink component is used to chain all the
declaration descriptors for a given record's fields together in a
linked list.
/* Structure used for procedure declaration descriptors. */
struct procdesc {
COMMONFIELDS
union dcldesc * formallist; /* head of list of this proc's formals. */
int paramcount; /* Count of parameters proc. expects */
int isfunc; /* True if this is a function. */
int localsize; /* Size of space required for locals */
CODELBL * entrylbl; /* Label placed on first line of proc */
};