<> <> <> <<>> 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.