LupineDeps.Mesa
Last Edited by: Spreitzer, September 13, 1985 6:33:19 pm PDT
Last Edited by: Pavel, May 28, 1984 3:06:54 pm PDT
Last tweaked by Mike Spreitzer on October 27, 1989 11:49:51 am PDT
JKF January 11, 1989 10:15:47 am PST
DIRECTORY
BasicTime USING [earliestGMT, GMT, Period],
FS USING [ComponentPositions, Error, ExpandName, StreamOpen],
IO USING [Close, EndOf, GetLineRope, PutFR, rope, SkipWhitespace, STREAM],
MakeDo USING [Action, ActionClass, ActionClassRep, ActionDep, AddFinder, fileClass, From, GetNode, InnerEnumerateSources, InnerGetCreated, Node, NodeList, notExistTime, PublicPartsOfAction, PublicPartsOfNode, Time],
Rope USING [Cat, Concat, Equal, Length, ROPE, Substr];
LupineDeps: CEDAR PROGRAM
IMPORTS BasicTime, FS, IO, MakeDo, Rope =
BEGIN
ROPE: TYPE = Rope.ROPE;
LupineAction: TYPE = REF LupineActionRep;
LupineActionRep: TYPE = RECORD [
interfaceName, resultPrefix: ROPE,
sourceNode, switchesNode: MakeDo.Node
];
lupineClass: MakeDo.ActionClass ← NEW [MakeDo.ActionClassRep ← [
CheckConsistency: CheckLupineConsistency,
Rederive: RederiveLupine
]];
LupineFind: PROC [resultName: ROPE, finderData: REF ANY] RETURNS [found: BOOLEAN, sought: MakeDo.Node, makes, cmdFrom: MakeDo.NodeList, from: MakeDo.From, cmd: ROPE, class: MakeDo.ActionClass, foundData: REF ANY] -- MakeDo.FinderProc -- =
BEGIN
EndsIn: PROC [ending: ROPE] RETURNS [ans: BOOL] = {
elen: INT = ending.Length[];
IF elen > slen THEN RETURN [FALSE];
IF (ans ← resultShort.Substr[start: slen - elen, len: elen].Equal[s2: ending, case: FALSE]) THEN {plen ← slen - elen; sending ← ending}};
Tail: PROC [ending: ROPE] RETURNS [node: MakeDo.Node] = {
node ← MakeDo.GetNode[resultPrefix.Cat[ending], MakeDo.fileClass];
IF ending.Equal[sending] THEN sought ← node};
resultCP: FS.ComponentPositions;
resultFull, resultPrefix, resultShort, interfaceName, sourceName, sending: ROPE;
sourceNode, switchesNode: MakeDo.Node;
la: LupineAction;
slen, plen: INT ← 0;
sought ← NIL;
found ← TRUE;
[resultFull, resultCP, ] ← FS.ExpandName[resultName !FS.Error => {found ← FALSE; CONTINUE}];
IF NOT found THEN RETURN;
resultShort ← resultFull.Substr[start: resultCP.base.start, len: (resultCP.ext.start + resultCP.ext.length) - resultCP.base.start];
slen ← resultShort.Length[];
found ← EndsIn["RpcControl.Mesa"] OR EndsIn["RpcClientImpl.Mesa"] OR EndsIn["RpcBinderImpl.Mesa"] OR EndsIn["RpcServerImpl.Mesa"];
IF NOT found THEN RETURN;
interfaceName ← resultShort.Substr[start: 0, len: plen];
resultPrefix ← resultFull.Substr[start: 0, len: resultCP.base.start].Concat[interfaceName];
cmdFrom ← LIST[
sourceNode ← MakeDo.GetNode[sourceName ← resultPrefix.Cat[".BCD"], MakeDo.fileClass],
switchesNode ← MakeDo.GetNode[resultPrefix.Cat[".LupineSwitches"], MakeDo.fileClass]
];
foundData ← la ← NEW [LupineActionRep ← [
interfaceName: interfaceName,
resultPrefix: resultPrefix,
sourceNode: sourceNode,
switchesNode: switchesNode
]];
cmd ← DeriveCmd[la];
makes ← LIST[
Tail["RpcControl.Mesa"],
Tail["RpcClientImpl.Mesa"],
Tail["RpcBinderImpl.Mesa"],
Tail["RpcServerImpl.Mesa"]];
IF sought = NIL THEN ERROR;
from ← DeriveFrom[la];
class ← lupineClass;
END;
GetSwitches: PROC [resultPrefix: ROPE] RETURNS [switches: ROPE] = {
ss: IO.STREAMNIL;
ss ← FS.StreamOpen[resultPrefix.Cat[".LupineSwitches"] !FS.Error => CONTINUE];
IF ss = NIL THEN RETURN [NIL];
[] ← ss.SkipWhitespace[];
IF ss.EndOf[] THEN RETURN [NIL];
switches ← ss.GetLineRope[];
ss.Close[];
};
DeriveFrom: PROC [la: LupineAction] RETURNS [from: MakeDo.From] =
BEGIN
from ← [mustHave: LIST[la.sourceNode], optional: NIL];
END;
DeriveCmd: PROC [la: LupineAction] RETURNS [cmd: ROPE] = {
cmd ← IO.PutFR[
"Lupine %g TranslateInterface[%g]",
IO.rope[GetSwitches[la.resultPrefix]],
IO.rope[la.interfaceName]
]
};
RederiveLupine: PROC [a: MakeDo.Action] RETURNS [from: MakeDo.From, cmd: ROPE] --MakeDo.RederiveProc-- = {
la: LupineAction ← NARROW[a.PublicPartsOfAction[].foundData];
from ← DeriveFrom[la];
cmd ← DeriveCmd[la];
};
FindLatestIngredient: PROC [a: MakeDo.Action] RETURNS [someIngredientsExist: BOOLFALSE, missingIngredient, latestIngredientNode: MakeDo.Node ← NIL, latestIngredientTime: MakeDo.Time ← BasicTime.earliestGMT] = {
PerSource: PROC [n: MakeDo.Node, which: MakeDo.ActionDep, optional: BOOL] = {
fromTime: BasicTime.GMT ← MakeDo.InnerGetCreated[n];
IF fromTime = MakeDo.notExistTime THEN {IF NOT optional THEN missingIngredient ← n}
ELSE {someIngredientsExist ← TRUE;
IF latestIngredientTime.Period[fromTime] > 0 THEN {
latestIngredientTime ← fromTime;
latestIngredientNode ← n;
};
};
};
MakeDo.InnerEnumerateSources[a, data, PerSource];
RETURN};
CheckLupineConsistency: PROC [a: MakeDo.Action, result: MakeDo.Node] RETURNS [consistent: BOOL, reason: ROPE] --MakeDo.ConsistencyChecker-- =
BEGIN
resultTime: MakeDo.Time = result.InnerGetCreated[];
resultName: ROPE = result.PublicPartsOfNode[].name;
resultExists: BOOL ~ resultTime # MakeDo.notExistTime;
someIngredientsExist: BOOL;
missingIngredient, latestIngredientNode: MakeDo.Node;
latestIngredientTime: MakeDo.Time;
[someIngredientsExist, missingIngredient, latestIngredientNode, latestIngredientTime] ← FindLatestIngredient[a];
IF NOT someIngredientsExist THEN RETURN [TRUE, "no ingredients exist to indicate inconsistency"];
IF NOT resultExists THEN RETURN [FALSE, "some inputs but no outputs exist"];
IF latestIngredientTime.Period[resultTime] < 0 THEN RETURN [
FALSE,
IO.PutFR[
"result %g (of %g) predates ingredient %g (of %g)",
[rope[resultName]],
[time[resultTime]],
[rope[latestIngredientNode.PublicPartsOfNode[].name]],
[time[latestIngredientTime]]
]];
RETURN [TRUE, "result dated later than any existing ingredient"];
END;
MakeDo.AddFinder[["Lupine", LupineFind], back];
END.