RefTabPrintImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, March 14, 1986 10:23:50 am PST
DIRECTORY
Atom, AMBridge, AMTypes, IO, PrintTV, Rope, RefTab, ProcessProps;
RefTabPrintImpl: CEDAR PROGRAM
IMPORTS Atom, AMBridge, IO, PrintTV, RefTab, ProcessProps
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
TVPrint: PrintTV.TVPrintProc ~ TRUSTED {
IF NOT AMBridge.IsRemote[tv] THEN
RETURN [RefPrint[AMBridge.ReadOnlyRefFromTV[tv], NIL, stream, depth, width, verbose]];
};
TVFromRef: PROC [ref: REF] RETURNS [tv: AMTypes.TV] ~ TRUSTED {
WITH ref SELECT FROM
atom: ATOM => tv ← AMBridge.TVForATOM[atom];
rope: ROPE => tv ← AMBridge.TVForROPE[rope];
ENDCASE => tv ← AMBridge.TVForReadOnlyReferent[ref];
};
GetNest: PROC RETURNS [INT] ~ {
WITH Atom.GetPropFromList[ProcessProps.GetPropList[], $PrintNest] SELECT FROM
int: REF INT => RETURN [int^];
ENDCASE => RETURN [0];
};
DoNested: PROC [inner: PROC] ~ {
nest: INT ~ GetNest[];
ProcessProps.AddPropList[LIST[NEW[Atom.DottedPairNode ← [$PrintNest, NEW[INT←nest+1]]]], inner];
};
NewLine: PROC [stream: IO.STREAM] ~ {
nest: INT ~ GetNest[];
stream.PutChar['\n];
FOR i: INT IN [0..nest) DO
stream.PutChar['\t];
ENDLOOP;
};
RefPrint: PrintTV.RefPrintProc ~ TRUSTED {
WITH LOOPHOLE[ref, REF] SELECT FROM
r: RefTab.Ref => {
size: INT ~ RefTab.GetSize[r];
i: INT ← 0;
Action: RefTab.EachPairAction ~ TRUSTED {
IO.PutChar[stream, '[];
{
p: SAFE PROC ~ TRUSTED {
PrintTV.Print[tv: TVFromRef[key], put: stream, depth: depth-1, width: width, verbose: verbose];
IO.PutRope[stream, ", "];
PrintTV.Print[tv: TVFromRef[val], put: stream, depth: depth-1, width: width, verbose: verbose];
};
DoNested[p];
};
IO.PutChar[stream, ']];
i ← i + 1;
IF i # size THEN {stream.PutChar[',]; NewLine[stream]};
quit ← (i >= width);
};
IO.PutRope[stream, "REFTAB["];
{
p: SAFE PROC ~ TRUSTED {
IF size > 1 THEN NewLine[stream];
IF RefTab.Pairs[r, Action] THEN IO.PutRope[stream, "..."];
};
DoNested[p];
};
IO.PutRope[stream, "]"];
RETURN [useOld: FALSE];
};
ENDCASE => NULL;
RETURN [useOld: TRUE];
};
PrintTV.RegisterTVPrintProc[[CODE[RefTab.RefTabRep]], TVPrint];
END.