-- Dependencies.mesa
--  last edit     August 2, 1982 4:05 pm  Sturgis

--DIRECTORY
  

Dependencies: DEFINITIONS =

BEGIN

DependencySet: TYPE = REF DependencySetBody;
Action: TYPE = REF ActionBody;
DataItem: TYPE = REF DataItemBody;
ActionProc: TYPE = PROCEDURE[Action, REF ANY];


CreateDependencySet: PROCEDURE RETURNS[DependencySet];

DefineAction: PROCEDURE[inSet: DependencySet, act: ActionProc, actInfo: REF ANY] RETURNS[Action]; 
DefineDataItem: PROCEDURE[inSet: DependencySet] RETURNS[DataItem];

NoteThatDataItemIsReadByAction: PROCEDURE[DataItem, Action];
NoteThatActionModifiesDataItem: PROCEDURE[Action, DataItem];

DeactivateAction: PROCEDURE[Action];
DeactivateDataItem: PROCEDURE[DataItem];

SortDependencySet: PROCEDURE[DependencySet];

MarkDataItemDirty: PROCEDURE[DataItem];
MarkActionDirty: PROCEDURE[Action];
DataItemIsSource: PROCEDURE[DataItem] RETURNS[--yes-- BOOLEAN];
PerformDirtyActions: PROCEDURE[DependencySet];


MisMatchedDependencySets: ERROR;
MalFormedDependencySet: ERROR;
LoopInDependencyGraph: ERROR;
MultipleAssignmentToOneDataItem: ERROR;

-- for debugging

GetActionInfo: PROCEDURE[Action] RETURNS[DependencySet, ActionProc, REF ANY];
Verify: PROCEDURE[DependencySet];




-- private info below this line, will be opaque type when debugger able to handle opaque types

DependencySetBody: TYPE = RECORD[
   changed: BOOLEAN, -- true if actions or dataItems have been added since last sort, or dependencies changed in any way
   sortedList: Action, -- contains the sorted actions in the set
   unSortedList: Action, -- contains all actions in the set
   dirtyActionsExist: BOOLEAN,
   dataItems: DataItem, -- contains all data items in the set, chained on dataItem.nextItem
   dirtyDataItems: DataItem
   ];

ActionBody: TYPE = RECORD[
   act: ActionProc,
   info: REF ANY,
   
   dirty: BOOLEAN,
   
   dependentData: ListCell, -- the list of data items modified by this action
   
   firstDataList: ListCell,  -- these are the occurances of this action as dependent on some data item
   
   -- info used to sort actions
   
   set: DependencySet,
   sorting: BOOLEAN,
   sorted: BOOLEAN,
   isSource: BOOLEAN,
   prevUnsorted, nextUnsorted: Action,
   prevSorted, nextSorted: Action
   ];
   
DataItemBody: TYPE = RECORD[
   dirty: BOOLEAN,
   set: DependencySet,
   nextItem, prevItem: DataItem,
   nextDirtyItem, prevDirtyItem: DataItem,
   
   dependentActions: ListCell, -- the list of actions that read this data item
   
   firstActionList: ListCell -- these are the occurances of this data item as dependent on some action
   ];
   
   
ListCell: TYPE = REF ListCellBody;

ListCellBody: TYPE = RECORD[
   action: Action,
   dataItem: DataItem,
   prevOnList, nextOnList: ListCell, -- this is the chain of dependent items hanging from some item
   prevList, nextList: ListCell -- this is the chain of occurances of the item on different items
   ];
   

END..

--  14-Feb-82 14:51:16: Sturgis, started Dependencies.mesa
-- 14-Feb-82 17:08:03: first go round complete, DependenciesImpl compiles.
-- 16-Feb-82 15:39:32: restructure the interface completely, so as to have explicit data items with lists of dependent actions.
--  4-Mar-82 17:20:57: add getActionInfo for Debugging
--  4-Mar-82 17:36:06: had to add actionProc as a type.
--  5-Mar-82 11:41:21: add Verify
-- 12-Mar-82 10:33:16: add MarkActinoDirty, DataItemIsSource.

-- August 2, 1982 4:07 pm: add a flag to indicate that new dataItems or Actions have been added to a set., or other changes have been made