RoseTranslateSymbols.Mesa
Last Edited by: Spreitzer, April 27, 1985 9:55:27 pm PST
Last Edited by: Gasbarro, August 17, 1984 11:27:52 am PDT
DIRECTORY Asserting,
FS,
IO, OrderedSymbolTableRef, Rope, RoseTranslateTypes, RoseTranslateInsides, TextNode, TiogaFileOps, TiogaOps, ViewerClasses, ViewerOps;
RoseTranslateSymbols:
CEDAR
PROGRAM
IMPORTS Asserting, FS, IO, OSTR: OrderedSymbolTableRef, Rope, RoseTranslateInsides
EXPORTS RoseTranslateInsides =
BEGIN OPEN RoseTranslateTypes, RoseTranslateInsides;
AddSymbols:
PUBLIC
PROC [job: Job, rootName:
ROPE] =
BEGIN
error: BOOLEAN ← FALSE;
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]];
symbolsSource: IO.STREAM;
job.from ← symbolsSource ←
FS.StreamOpen[rootName.Concat[".RoseSymbols"] !
FS.Error =>
BEGIN
Whimper[nullSR, parent, "Unable to open %g.RoseSymbols", IO.rope[rootName]];
symbolsSource ← NIL;
CONTINUE;
END];
IF symbolsSource = NIL THEN RETURN [TRUE];
job.log.PutF["Reading symbols from %g.RoseSymbols... ", IO.rope[rootName]];
[] ← symbolsSource.SkipWhitespace[flushComments: FALSE];
WHILE
NOT symbolsSource.EndOf[]
DO
fun: BOOL ← symbolsSource.GetBool[];
symbolName: ROPE ← symbolsSource.GetTokenRope[MyBreak].token;
globvar: BOOL ← symbolsSource.GetBool[];
definer: ROPE ← symbolsSource.GetTokenRope[MyBreak].token;
cd: CellDef ← NEW [CellDefRep ← []];
[] ← symbolsSource.SkipWhitespace[];
SELECT symbolsSource.PeekChar[]
FROM
'F => {
IF symbolsSource.GetChar[] # 'F THEN ERROR;
};
'" => {
interfaceAsRope: ROPE ← symbolsSource.GetRopeLiteral[];
ok: BOOL ← TRUE;
iel: InterfaceEltList;
asAny: REF ANY;
job.from ← IO.RIS[interfaceAsRope];
asAny ← ParseExpression[job];
WITH asAny
SELECT
FROM
sb: SquareBracketed =>
IF sb.subject =
NIL
THEN iel ←
NIL
ELSE
WITH sb.subject
SELECT
FROM
il: InterfaceEltList => iel ← il;
ENDCASE => ok ← FALSE;
ENDCASE => ok ← FALSE;
IF
NOT ok
THEN
BEGIN
[] ← Complain[nullSR, job, "Bad interface: %g",
IO.refAny[asAny]];
job.log.PutRope["Done reading symbols\n"];
RETURN [TRUE];
END;
IF (cd.interfaceLiteral ← DigestInterface[job, iel]) =
NIL
THEN
BEGIN
job.log.PutRope["Done reading symbols\n"];
RETURN [TRUE];
END;
};
ENDCASE => ERROR;
IF fun
THEN {
cfe: cfEntry ← NEW [SymbolTableEntryRep[cellFn] ← [name: symbolName, value: cellFn[definedIn: definer, cf: NEW [CellFnRep ← [cd: cd]] ]]];
cd.forFn ← cfe.cf;
AddCellFn[job, cfe];
}
ELSE {
cce: ccEntry ← NEW [SymbolTableEntryRep[cellClass] ← [name: symbolName, value: cellClass[globvar: globvar, definedIn: definer, cd: cd]]];
AddCellClass[job, cce];
};
[] ← symbolsSource.SkipWhitespace[flushComments: FALSE];
ENDLOOP;
job.log.PutRope["done\n"];
error ← FALSE;
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[nullSR, job, "Multiple definition of cell class %g", IO.rope[cce.name]];
END
ELSE job.things.Insert[cce];
END;
AddCellFn:
PUBLIC
PROC [job: Job, cfe: cfEntry] =
BEGIN
ste: SymbolTableEntry ← NARROW[job.things.Lookup[cfe.name]];
complain: BOOLEAN ← ste # NIL;
IF complain
THEN
WITH ste
SELECT
FROM
oldCFE: cfEntry =>
IF oldCFE.definedIn =
NIL
AND cfe.definedIn #
NIL
THEN
BEGIN
oldCFE.definedIn ← cfe.definedIn;
oldCFE.cf ← cfe.cf;
RETURN;
END;
ENDCASE;
IF complain
THEN
BEGIN
Whimper[nullSR, job, "Multiple definition of cell type function %g", IO.rope[cfe.name]];
END
ELSE job.things.Insert[cfe];
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[iel.first.sr, 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;
IF Asserting.Test[$SwitchInstructions, NIL, iel.first.assertions] THEN di.hasSwitchInstruction ← 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.