Function Name DescriptorsDeclaration DescriptorsType Name Declaration DescriptorsVariable and Field Name Descriptors

Variable and Field Name Descriptors

The second group of related forms of declaration descriptors are those for things that act like variables: actual variables, formal parameter names and structure 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 func's formals.       */
   int isVal;                   /* True if call by value formal           */
 };

    /* Structure used for struct field name declaration descriptors.   */
struct fielddesc {
   COMMONFIELDS
   union dcldesc * vartype;     /* decl. descriptor for component's type  */
   int disp;                    /* displacement to field within structure    */
   union dcldesc * hashlink;    /* link pointer for hash chain            */
   union dcldesc * structtype;  /* decl. descriptor for type to which the */
                                /*       component belong                 */
   union dcldesc *fieldlink;    /* Next pointer for type's list of fields */
 };
Declarations for variable/field name declaration descriptors
 

There are two fields shared by the declaration descriptors of variables, formals and structure 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 structure or activation record in which it is located. These are the only special fields in the struct 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 function into a list.

Structure fields names are associated with declaration descriptors of type fielddesc. The structtype component of each such descriptor is used to hold a back pointer to the descriptor for the structure 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 structure field name. Finally, the fieldlink component is used to chain all the declaration descriptors for a given structure's fields together in a linked list.

    /* Structure used for function declaration descriptors.    */
struct funcdesc {
   COMMONFIELDS
   union dcldesc * formallist;  /* head of list of this func's formals. */
   int paramcount;              /* Count of parameters func. 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 func   */
};
Declarations for function name declaration descriptors
 
Computer Science 434
Department of Computer Science
Williams College

Function Name DescriptorsDeclaration DescriptorsType Name Declaration DescriptorsVariable and Field Name Descriptors