RoseTranslateSymbols.Mesa
Last Edited by: Spreitzer, July 12, 1985 2:04:30 pm PDT
Last Edited by: Gasbarro, August 17, 1984 11:27:52 am PDT
DIRECTORY Asserting, Basics, FS, IO, RedBlackTree, Rope, RoseTranslateTypes, RoseTranslateInsides, TextNode, TiogaFileOps, TiogaOps, ViewerClasses, ViewerOps;
RoseTranslateSymbols: CEDAR PROGRAM
IMPORTS Asserting, FS, IO, RedBlackTree, 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, 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;
isVar: BOOL ← symbolsSource.GetBool[];
definer: ROPE ← symbolsSource.GetRopeLiteral[];
cd: CellDef ← NEW [CellDefRep ← []];
[] ← symbolsSource.SkipWhitespace[];
SELECT symbolsSource.PeekChar[] FROM
'N => {
IF NOT symbolsSource.GetTokenRope[MyBreak].token.Equal["NIL"] THEN ERROR;
};
'" => {
interfaceAsRope: ROPE ← symbolsSource.GetRopeLiteral[];
ok: BOOLTRUE;
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[isVar: isVar, 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, cce.name];
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, cfe.name];
END;
DigestInterface: PUBLIC PROC [context: REF ANY, iel: InterfaceEltList] RETURNS [di: DigestedInterface] =
BEGIN
di ← NEW [DigestedInterfaceRep ← [
asTable: RedBlackTree.Create[GetInterfaceEltKey, 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, iel.first.name];
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;
GetInterfaceEltKey: PROC [data: REF ANY] RETURNS [key: ROPE] --RedBlackTree.GetKey-- =
{ie: InterfaceElt ← NARROW[data]; key ← ie.name};
CompareInterfaceElts: PROC [k, data: REF ANY] RETURNS [c: Basics.Comparison] --RedBlackTree.Compare-- =
BEGIN
s1: ROPENARROW[k];
s2: ROPE ← GetInterfaceEltKey[data];
c ← s1.Compare[s2, FALSE];
END;
END.