Next: , Up: TypeProp


7.1 Defining a type

A type denotation describes the characteristics of a user-defined type in terms of language-defined types and other user-defined types. It may be bound to a type identifier in a type definition.

Here is the type analysis specification for Mystery type denotations:

     SYMBOL Procedure INHERITS TypeDenotation END;
     SYMBOL SubrTy    INHERITS TypeDenotation END;
     SYMBOL ArrayTy   INHERITS TypeDenotation END;
     SYMBOL ProcTy    INHERITS TypeDenotation END;
     
     SYMBOL Type COMPUTE SYNT.Type=CONSTITUENT TypeDenotation.Type; END;

(Note that a procedure denotation is also a type denotation in Mystery. The reason is that procedures can be assigned to variables and passed as parameters, and therefore they must be typed entities.)

Information characterizing a user-defined type is often stored as properties of the definition table key that is the value of TypeDenotation.Type. The post-condition TypeDenotation.GotProp establishes the fact that such properties have been set, but it can only be used for computations that are not themselves dependent on any aspect of type analysis (see Dependences for typed entities).

For example, a subrange type in Mystery is characterized by its bounds. The bound information may be needed in various contexts where the type is used, and therefore it is reasonable to store that information as properties of the subrange type's key. Suppose, therefore, that Lower and Upper are defined as integer-valued properties. Since bound information is independent of any aspect of type analysis, TypeDenotation.GotProp can be used as the post-condition of the computation to set those properties:

     ATTR Lower, Upper: int;
     
     RULE: SubrTy ::= '[' Number 'TO' Number ']'
     COMPUTE
       SubrTy.Lower=atoi(StringTable(Number[1]));
       SubrTy.Upper=atoi(StringTable(Number[2]));
       SubrTy.GotProp=
         ORDER(
           ResetLower(SubrTy.Type,SubrTy.Lower),
           ResetUpper(SubrTy.Type,SubrTy.Upper));
     END;

(The Lower and Upper attributes are necessary to pass bounds to an enclosing array type, if one exists. Number is a non-literal terminal symbol whose value is the digit string appearing in the Mystery source text; atoi is the string-to-integer conversion routine from the C library.)