<> <> <> <> DIRECTORY TerminalIO, CD, CDSequencer, CDOps, CDCommandOps, CDBasics, Commander USING [CommandProc, Handle, Register], IO, SweepCollectableStorage USING [InfoProc, EnumerateCollectableStorage]; CDCountCommands: CEDAR PROGRAM IMPORTS CD, CDSequencer, CDOps, CDCommandOps, Commander, IO, SweepCollectableStorage, TerminalIO = BEGIN <<--the global variables mare monitored using CDCommandOps.DoWithResource;>> <<--these variables are global so they can be used by MyDrawChild>> rectCounter, childCounter: INT; MyDrawChild: CD.DrawProc = { childCounter _ childCounter+1; CD.DrawOb[ob: ob, trans: trans, pr: pr, readOnlyInstProps: readOnlyInstProps]; }; MyDrawRect: CD.DrawRectProc = { rectCounter _ rectCounter+1; }; ProtectedCount: PROC [comm: CDSequencer.Command] = { myDrawRef: CD.DrawRef _ CD.CreateDrawRef[[ interestClip: CDBasics.universe, drawChild: MyDrawChild, drawRect: MyDrawRect, design: comm.design ]]; rectCounter _ childCounter _ 0; CDOps.DrawDesign[design: comm.design, pr: myDrawRef]; myDrawRef _ NIL; TerminalIO.PutF["rectangles %g objects %g\n", IO.int[rectCounter], IO.int[childCounter]]; }; <<>> CountFlatComm: PROC [comm: CDSequencer.Command] = { TerminalIO.PutRope["flat count rectangles\n"]; [] _ CDCommandOps.DoWithResource[ProtectedCount, comm, $myDrawRef]; }; Count: PROC [out: IO.STREAM] = { EachObject: SweepCollectableStorage.InfoProc = { <<--PROC [type: SafeStorage.Type, size: INT, object: ..] RETURNS [continue: BOOL] >> IF type=CODE[CD.InstanceRep] THEN inst _ inst+1 ELSE IF type=CODE[CD.ObjectRep] THEN ob _ ob+1 ELSE IF type=CODE[CD.CellRep] THEN cell _ cell+1 ELSE IF type=CODE[CD.ObjectClassRec] THEN obClasses _ obClasses+1 ELSE IF type=CODE[CD.DesignRec] THEN design _ design+1 ELSE others _ others+1; RETURN [TRUE]; }; others, inst, ob, cell, obClasses, design: INT _ 0; TRUSTED { SweepCollectableStorage.EnumerateCollectableStorage[EachObject] }; out.PutF["instances = %g\n", IO.int[inst]]; out.PutF["objects = %g\n", IO.int[ob]]; out.PutF["cells = %g\n", IO.int[cell]]; out.PutF["object classes = %g\n", IO.int[obClasses]]; out.PutF["designs = %g\n", IO.int[design]]; out.PutF["others = %g\n", IO.int[others]]; }; CountTypesCommand: Commander.CommandProc = { Count[cmd.out]; }; CountTypesComm: PROC [comm: CDSequencer.Command] = { TerminalIO.PutRope["count types using SweepCollectableStorage\n"]; Count[TerminalIO.TOS[]]; }; CDSequencer.ImplementCommand[$CountRects, CountFlatComm,, dontQueue]; CDSequencer.ImplementCommand[$CountTypes, CountTypesComm,, dontQueue]; Commander.Register[key: "///Commands/CDCount", proc: CountTypesCommand, doc: "Count features of ChipNDale"]; END.