RoseTranslateSymbols.Mesa
Last Edited by: Spreitzer, March 11, 1984 6:33:53 pm PST
DIRECTORY FS, IO, OrderedSymbolTableRef, Rope, RoseTranslateTypes, RoseTranslateInsides, TextNode, TiogaFileOps, TiogaOps, ViewerClasses, ViewerOps;
RoseTranslateSymbols: CEDAR PROGRAM
IMPORTS FS, IO, OSTR: OrderedSymbolTableRef, Rope, RoseTranslateInsides
EXPORTS RoseTranslateInsides =
BEGIN OPEN RoseTranslateTypes, RoseTranslateInsides;
AddSymbols: PUBLIC PROC [job: Job, rootName: ROPE] =
BEGIN
error: BOOLEANFALSE;
IF job.libbed.Lookup[rootName] # NIL THEN RETURN;
job.libbed.Insert[rootName];
IF NOT error THEN [] ← DigestSymbols[job, rootName];
END;
DigestSymbols: PROC [parent: Job, rootName: ROPE] RETURNS [error: BOOLEAN] =
BEGIN
job: Job ← NEW [JobRep ← [
log: parent.log,
exec: parent.exec,
rootName: rootName,
things: parent.things,
type: TranslateJob]];
job.from ← FS.StreamOpen[rootName.Concat[".RoseSymbols"] !FS.Error =>
BEGIN
Whimper[parent, "Unable to open %g.RoseSymbols", IO.rope[rootName]];
job.from ← NIL;
CONTINUE;
END];
IF job.from = NIL THEN RETURN [TRUE];
job.log.PutF["Reading symbols from %g.RoseSymbols...\n", IO.rope[rootName]];
[] ← job.from.SkipWhitespace[flushComments: FALSE];
WHILE NOT job.from.EndOf[] DO
className: ROPE ← job.from.GetTokenRope[MyBreak].token;
definer: ROPE ← job.from.GetTokenRope[MyBreak].token;
bits: CARDINAL ← job.from.GetInt[];
defaultInitExpr: ROPENARROW[job.from.GetRefAny[]];
asAny: REF ANY;
stoppedOn: ROPE;
cce: ccEntry ← NEW [SymbolTableEntryRep[cellClass] ← [name: className, value: cellClass[definedIn: rootName, cd: NEW [CellDefRep ← [defaultInitExprGiven: (bits MOD 2) > 0, initializerGiven: (bits MOD 4) > 1, initDataGiven: (bits MOD 8) > 3, defaultInitExpr: defaultInitExpr]] ]]];
iel: InterfaceEltList;
[asAny, stoppedOn] ← ParseExpression[job, TRUE];
IF NOT stoppedOn.Equal["!!"] THEN
BEGIN
[] ← Complain[job, "Not terminated properly"];
job.log.PutRope["Done reading symbols\n"];
RETURN [TRUE];
END;
IF asAny = NIL THEN iel ← NIL
ELSE WITH asAny SELECT FROM
sb: SquareBracketed => iel ← sb.iel;
ENDCASE => BEGIN
[] ← Complain[job, "Bad interface: %g", IO.refAny[asAny]];
job.log.PutRope["Done reading symbols\n"];
RETURN [TRUE];
END;
IF (cce.cd.interface ← DigestInterface[job, iel]) = NIL THEN
BEGIN
job.log.PutRope["Done reading symbols\n"];
RETURN [TRUE];
END;
AddCellClass[job, cce];
[] ← job.from.SkipWhitespace[flushComments: FALSE];
ENDLOOP;
job.log.PutRope["Done reading symbols\n"];
END;
AddCellClass: PUBLIC PROC [job: Job, cce: ccEntry] =
BEGIN
ste: SymbolTableEntry ← NARROW[job.things.Lookup[cce.name]];
complain: BOOLEAN ← ste # NIL;
IF complain THEN WITH ste SELECT FROM
oldCCE: ccEntry => IF oldCCE.definedIn = NIL AND cce.definedIn # NIL THEN
BEGIN
oldCCE.definedIn ← cce.definedIn;
oldCCE.cd ← cce.cd;
RETURN;
END;
ENDCASE;
IF complain THEN
BEGIN
Whimper[job, "Multiple definition of cell class %g", IO.rope[cce.name]];
END
ELSE job.things.Insert[cce];
END;
DigestInterface: PUBLIC PROC [context: REF ANY, iel: InterfaceEltList] RETURNS [di: DigestedInterface] =
BEGIN
di ← NEW [DigestedInterfaceRep ← [
asTable: OSTR.CreateTable[CompareInterfaceElts],
asList: iel]];
FOR iel ← iel, iel.rest WHILE iel # NIL DO
IF di.asTable.Lookup[iel.first.name] # NIL THEN
BEGIN
[] ← Complain[context, "Multiple def of %g in interface %g", IO.rope[iel.first.name], IO.refAny[di]];
RETURN [NIL];
END;
di.asTable.Insert[iel.first];
IF NOT iel.first.sti.st.simple THEN di.hasSwitchElt ← TRUE;
ENDLOOP;
END;
CompareInterfaceElts: OSTR.CompareProc =
BEGIN
s1, s2: ROPE;
s1 ← WITH r1 SELECT FROM
r: ROPE => r,
ie: InterfaceElt => ie.name,
ENDCASE => ERROR;
s2 ← WITH r2 SELECT FROM
r: ROPE => r,
ie: InterfaceElt => ie.name,
ENDCASE => ERROR;
RETURN [s1.Compare[s2, FALSE]];
END;
END.