CDCountCommands.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi, February 20, 1985 10:41:19 am PST
Last edited by: Christian Jacobi, October 20, 1986 12:30:39 pm PDT
DIRECTORY
TerminalIO,
CD,
CDSequencer,
CDOps,
CDCommandOps,
CDBasics,
Commander USING [CommandProc, Handle, Register],
IO,
SweepCollectableStorage USING [InfoProc, EnumerateCollectableStorage];
CDCountCommands: CEDAR PROGRAM
IMPORTS TerminalIO, CD, CDSequencer, CDOps, CDCommandOps, Commander, IO, SweepCollectableStorage =
BEGIN
--the global variables mare monitored using CDCommandOps.CallWithResource;
--these variables are global so they can be used by MyDrawChild
rectCounter, childCounter: INT;
MyDrawChild: CD.DrawProc = {
childCounter ← childCounter+1;
inst.ob.class.drawMe[inst: inst, pos: inst.location, orient: inst.orientation, pr: pr];
};
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.WriteRope[IO.PutFR["rectangles %g objects %g\n",
IO.int[rectCounter],
IO.int[childCounter]
]];
};
CountFlatComm: PROC [comm: CDSequencer.Command] = {
TerminalIO.WriteRope["flat count rectangles\n"];
[] ← CDCommandOps.CallWithResource[ProtectedCount, comm, $myDrawRef, NEW[BOOLFALSE]];
};
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.WriteRope["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.