DefinitionsImpl.mesa
Copyright Ó 1990 by Xerox Corporation. All rights reserved.
Theimer, May 17, 1989 3:56:05 pm PDT
Changed by Theimer on May 20, 1989 6:42:37 pm PDT
Last changed by Theimer on May 31, 1989 3:54:36 pm PDT
Spreitze, January 9, 1992 10:02 am PST
DIRECTORY
CCTypes USING [CCTypeProcs, CreateCedarType, GetGroundType, GetTypeClass, GetIndirectType, PrintTypeBracketed, sia],
CirioTypes USING[CompilerContext, Type],
Definitions,
IO,
Rope,
StructuredStreams;
DefinitionsImpl: CEDAR PROGRAM
IMPORTS CCTypes, IO, Rope, StructuredStreams
EXPORTS Definitions
= BEGIN OPEN CCTypes, Definitions, SS:StructuredStreams;
CC: TYPE = CirioTypes.CompilerContext;
Type: TYPE = CirioTypes.Type;
Type operations.
CreateDefinitionType: PUBLIC PROC [underType: Type, name: Rope.ROPE, cc: CC] RETURNS [Type] = {
dti: DefinitionTypeInfo ← NEW[DefinitionTypeInfoBody ← [underType, name]];
type: Type ← CCTypes.CreateCedarType[$definition, DefinitionTypeCCTypeProcs, IndirectDefinitionTypeCCTypeProcs, cc, dti, underType];
RETURN [type];
};
DefinitionTypeCCTypeProcs: REF CCTypes.CCTypeProcs ← NEW[CCTypes.CCTypeProcs ←[
getGroundType: DefinitionCCTypesGetGroundType,
getTypeRepresentation: DefinitionTypeGetTypeRepresentation,
printType: DefinitionCCTypesPrintType]];
IndirectDefinitionTypeCCTypeProcs: REF CCTypes.CCTypeProcs ← NEW[CCTypes.CCTypeProcs ←[
getGroundType: IndirectDefinitionCCTypesGetGroundType,
getTypeRepresentation: DefinitionTypeGetTypeRepresentation,
printType: DefinitionCCTypesPrintType]];
DefinitionTypeGetTypeRepresentation: PROC[type: Type, cc: CC, procData: REF ANY] RETURNS[Type]
~ {RETURN[NIL]};
DefinitionCCTypesGetGroundType: PROC [type: Type, cc: CC, procData: REF ANY] RETURNS [Type] = {
info: DefinitionTypeInfo ← NARROW[procData];
IF CCTypes.GetTypeClass[info.underType] = $definition
THEN {
RETURN [GetGroundType[type, cc, info.underType]];
}
ELSE {
RETURN [info.underType];
};
};
DefinitionCCTypesPrintType: PROC [to: IO.STREAM, type: Type, printDepth: INT, printWidth: INT, cc: CC, procData: REF ANY] = {
info: DefinitionTypeInfo ← NARROW[procData];
to.PutRope[info.name];
IF printDepth <= 1 OR IsBaseType[info.name] THEN RETURN;
to.PutRope[": TYPE"];
SS.Bp[to, lookLeft, CCTypes.sia, " "];
to.PutRope["= "];
CCTypes.PrintTypeBracketed[to, info.underType, printDepth-1, printWidth, cc];
RETURN};
IndirectDefinitionCCTypesGetGroundType: PROC [type: Type, cc: CC, procData: REF ANY] RETURNS [Type] = {
info: DefinitionTypeInfo ← NARROW[procData];
indirectType: Type ← GetIndirectType[info.underType];
IF CCTypes.GetTypeClass[indirectType] = $definition
THEN {
RETURN [GetGroundType[type, cc, indirectType]];
}
ELSE {
RETURN [indirectType];
};
};
IsBaseType: PROC [typeName: Rope.ROPE] RETURNS [BOOLEAN] = {
IF Rope.Equal[typeName, "INT"] OR
Rope.Equal[typeName, "INT16"] OR
Rope.Equal[typeName, "CARDINAL"] OR
Rope.Equal[typeName, "CARD"] OR
Rope.Equal[typeName, "REAL"] OR
Rope.Equal[typeName, "CHAR"] OR
Rope.Equal[typeName, "BOOLEAN"]
THEN {
RETURN [TRUE];
}
ELSE {
RETURN [FALSE];
};
};
Node operations. There are no definition nodes.
END.