-- BBBreak.mesa
-- Russ Atkinson, September 9, 1982 7:26 pm

DIRECTORY
BBObjectLocation USING [BreakpointId, Location],
Rope USING [ROPE],
RTBasic USING [TV];

BBBreak: CEDAR DEFINITIONS = BEGIN OPEN Rope, RTBasic;

-- when an action has kind = break, the data is of type BreakId
BreakList: TYPE = LIST OF BreakId;
BreakId: TYPE = REF BreakIdRep;
BreakIdRep: TYPE =
RECORD
[index: BreakIndex,
loc: BBObjectLocation.Location,
cid: BBObjectLocation.BreakpointId,
condProc: CondProc ← NIL, -- invoked before each break
condData: REFNIL,
entry, exit, enabled: BOOL];

CondProc: TYPE = PROC
[bid: BreakId, lf: TV, data: REFNIL]
RETURNS [break: BOOL];
-- this type is useful for conditional breakpoints
-- one returns TRUE to break, FALSE to continue

BreakIndex: TYPE = INT;
NullIndex: BreakIndex = 0;

BreakError: ERROR [reason: ROPE];

BreakEntry: PROC [proc: TV] RETURNS [BreakIndex];
-- add break at entry to the given procedure

BreakExit: PROC [proc: TV] RETURNS [BreakIndex];
-- add break at exit from the given procedure

ClearBreak: PROC [index: BreakIndex] RETURNS [BreakId];
-- clear the given break (if any)
-- returning the break id for that index (if any)

ClearAllBreaks: PROC [condProc: CondProc ← NIL];
-- clear all breaks with the given cond proc
-- defaults to clearing unconditional breaks

FindBreakId: PROC [index: BreakIndex] RETURNS [BreakId];
-- translate from break index to break id

AddBreakToList: PROC
[loc: BBObjectLocation.Location, condProc: CondProc ← NIL, condData: REFNIL]
RETURNS [BreakId];
-- make a new breakpoint at the given location
-- then add it to the list

RemBreakFromList: PROC [index: BreakIndex] RETURNS [BreakId];
-- remove the break from the list
-- but do not clear the breakpoint
-- warning: you may not like the results!

NextBreak: PROC [index: BreakIndex ← NullIndex] RETURNS [BreakIndex];
-- if index = NullIndex, return first break in list
-- otherwise, return first break index after given break
-- returns NullIndex if no such break

END.