RoseWireTypeUseImpl.Mesa
Spreitzer, October 21, 1985 7:55:29 pm PDT
Barth, September 3, 1985 4:36:21 pm PDT
DIRECTORY Rope, RedBlackTree, RedBlackTreeExtras, RoseWireTypes, RoseWireTypeUse;
RoseWireTypeUseImpl:
CEDAR
PROGRAM
IMPORTS RedBlackTree, RedBlackTreeExtras, Rope
EXPORTS RoseWireTypeUse
=
BEGIN OPEN RoseWireTypes, RoseWireTypeUse;
Table: TYPE = RedBlackTree.Table;
RoseWireTypeUser: TYPE = REF RoseWireTypeUserRep;
RoseWireTypeUserRep:
PUBLIC
TYPE =
RECORD [
moduleRefs: ARRAY ModuleRefType OF Table ← ALL[NIL],
classes: Table ← RedBlackTreeExtras.NewRefTable[],
repAux: ROPE ← NIL
];
CreateUser:
PUBLIC
PROC
RETURNS [user: RoseWireTypeUser] = {
user ← NEW [RoseWireTypeUserRep ← []];
FOR mrt: ModuleRefType
IN ModuleRefType
DO
user.moduleRefs[mrt] ← RedBlackTreeExtras.NewRopeTable[];
ENDLOOP;
user ← user;
};
AddRWCAux:
PUBLIC
PROC [user: RoseWireTypeUser, rwc: RoseWireClass] = {
IF user.classes.Lookup[rwc] # NIL THEN RETURN;
user.classes.Insert[rwc, rwc];
IF rwc.super.MesaRepAux #
NIL
THEN {
dra: Mesa ← rwc.super.MesaRepAux[rwc];
AddMesa[user, dra];
SELECT rwc.structure
FROM
atom => NULL;
sequence => AddRWCAux[user, rwc.super.SubClass[rwc, [subscript[0]]]];
record => {
user ← user;
FOR i:
NAT
IN [0 .. rwc.length)
DO
swc: RoseWireClass = rwc.super.SubClass[rwc, [field[i]]];
AddRWCAux[user, swc];
ENDLOOP;
user ← user;
};
ENDCASE => ERROR;
};
};
AddMesa:
PUBLIC
PROC [user: RoseWireTypeUser, mesa: Mesa] = {
user.repAux ← StmtCat[user.repAux, mesa.mesa];
NoteMesa[user, mesa];
};
NoteMesa:
PUBLIC
PROC [user: RoseWireTypeUser, mesa: Mesa] = {
NoteModuleRefs[user, Directory, mesa.directory];
NoteModuleRefs[user, Import, mesa.imports];
};
NoteModuleRefs:
PUBLIC
PROC [user: RoseWireTypeUser, type: ModuleRefType, refs:
LOR] = {
SELECT type
FROM
Open, Import, Export => NoteModuleRefs[user, Directory, refs];
Directory => NULL;
ENDCASE => ERROR;
FOR refs ← refs, refs.rest
WHILE refs #
NIL
DO
mr: ROPE = refs.first;
IF user.moduleRefs[type].Lookup[mr] =
NIL
THEN {
user.moduleRefs[type].Insert[mr, mr];
};
ENDLOOP;
refs ← refs;
};
DestroyUser:
PUBLIC
PROC [user: RoseWireTypeUser]
RETURNS [repAux:
ROPE, moduleRefs: ModuleRefs] = {
Report:
PROC [mrt: ModuleRefType] = {
NoteRef:
PROC [data:
REF
ANY]
RETURNS [stop:
BOOL ←
FALSE]
--RedBlackTree.EachNode-- = {
r: ROPE = NARROW[data];
moduleRefs[mrt] ← CONS[r, moduleRefs[mrt]];
};
user.moduleRefs[mrt].EnumerateIncreasing[NoteRef];
user.moduleRefs[mrt].DestroyTable[];
};
repAux ← user.repAux;
moduleRefs ← ALL[NIL];
FOR mrt: ModuleRefType IN ModuleRefType DO Report[mrt] ENDLOOP;
user^ ← [classes: NIL];
};
StmtCat:
PUBLIC
PROC [s1, s2:
ROPE]
RETURNS [catted:
ROPE] = {
IF s1.Length[] = 0 THEN RETURN [s2];
IF s2.Length[] = 0 THEN RETURN [s1];
catted ← s1.Cat[";\n", s2];
};
END.