<> <> <> DIRECTORY AssertingIO, Atom, Convert, FS, IO, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, RoseCreate, RoseTypes, ViewerOps, ViewRec; RoseDeciders: CEDAR PROGRAM IMPORTS AssertingIO, Atom, Convert, FS, IO, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, RoseCreate, RoseTypes, ViewerOps, ViewRec EXPORTS RoseCreate = BEGIN OPEN RoseCreate, RoseTypes; Name: TYPE = LIST OF ROPE; LORA: TYPE = LIST OF REF ANY; ExpandDecisionRef: TYPE = REF ExpandDecision; decisionProp: ATOM _ Atom.MakeAtom["Spreitzer January 6, 1984 8:33 pm"]; ExpandQuery: TYPE = REF ExpandQueryRep; ExpandQueryRep: TYPE = RECORD [ instanceName, typeName: ROPE _ NIL, whatToDo: ExpandDecision _ Nested]; qp: Pausers.Pauser _ NIL; eq: ExpandQuery _ NEW [ExpandQueryRep _ []]; qerv: ViewRec.RecordViewer; qv: ViewRec.Viewer _ NIL; AssertionsFromFile: PUBLIC PROC [fileName: ROPE] RETURNS [assertions: Assertions] = BEGIN from: STREAM _ FS.StreamOpen[fileName]; assertions _ AssertingIO.Read[from]; <> <> <> <> <> <> from.Close[]; END; LookupCell: PUBLIC PROC [path: LIST OF REF ANY, from: Cell _ NIL] RETURNS [cell: Cell] = BEGIN sofar: LIST OF ROPE _ NIL; cell _ from; WHILE path # NIL DO link: ROPE _ WITH path.first SELECT FROM r: ROPE => r, rt: REF TEXT => Rope.FromRefText[rt], ENDCASE => ERROR; next: Cell _ NARROW[(IF cell = NIL THEN roots ELSE cell.components). Lookup[link]]; IF next = NIL THEN {SIGNAL Warning[IO.PutFR["Not found: %g %g %g", IO.refAny[sofar], IO.rope[Convert.RopeFromRope[link]], IO.refAny[path.rest]]]; RETURN [NIL]}; sofar _ CONS[link, sofar]; path _ path.rest; cell _ next; ENDLOOP; END; LookupNode: PUBLIC PROC [path: LIST OF REF ANY, from: Cell _ NIL] RETURNS [node: Node] = BEGIN sofar: LIST OF ROPE _ NIL; cell: Cell _ from; WHILE path # NIL DO link: ROPE _ WITH path.first SELECT FROM r: ROPE => r, rt: REF TEXT => Rope.FromRefText[rt], ENDCASE => ERROR; next: Cell; IF path.rest = NIL THEN RETURN [LookupCellNode[cell, link]]; next _ NARROW[(IF cell = NIL THEN roots ELSE cell.components). Lookup[link]]; IF next = NIL THEN {SIGNAL Warning[IO.PutFR["Not found: %g %g %g", IO.refAny[sofar], IO.rope[Convert.RopeFromRope[link]], IO.refAny[path.rest]]]; RETURN [NIL]}; sofar _ CONS[link, sofar]; path _ path.rest; cell _ next; ENDLOOP; ERROR; END; LookupCellNode: PUBLIC PROC [cell: Cell, name: ROPE] RETURNS [node: Node] = BEGIN index: CARDINAL; IF (node _ NARROW[cell.internalNodes.Lookup[name]]) # NIL THEN RETURN [node]; IF (index _ GetIndex[cell.type.ports, name]) # notFound THEN RETURN [cell.interfaceNodes[index]]; node _ NIL; END; LongNodeName: PUBLIC PROC [n: Node] RETURNS [name: ROPE] = {name _ LongCellName[n.cellIn].Cat[".", n.name]}; LongCellName: PUBLIC PROC [c: Cell] RETURNS [name: ROPE] = { name _ c.name; FOR c _ c.parent, c.parent WHILE c # NIL DO name _ c.name.Cat[".", name] ENDLOOP}; DecideFromFile: PUBLIC PROC [fileName: ROPE] RETURNS [dff: ExpandDeciderClosure] = BEGIN file: IO.STREAM _ NIL; top: LORA; file _ FS.StreamOpen[fileName: fileName]; top _ LIST[NIL, NIL, IO.GetRefAny[file]]; file.Close[]; dff _ NEW [ExpandDeciderClosureRep _ [Decide: DecideByName, otherData: top]]; END; Ask: ExpandDecider --PROC [cell: Cell, otherData: REF ANY] RETURNS [ExpandDecision]-- = BEGIN first: BOOLEAN _ TRUE; eq.instanceName _ cell.name; eq.typeName _ cell.type.name; IF qv # NIL AND qv.iconic THEN ViewerOps.OpenIcon[qv]; WHILE first OR NOT Possible[cell, eq.whatToDo] DO qp.Pause[]; first _ FALSE ENDLOOP; RETURN [eq.whatToDo]; END; DecideByName: ExpandDecider = BEGIN Yelp: PROC [problem: ROPE] RETURNS [ExpandDecision] = TRUSTED BEGIN RETURN [Ask[cell, problem]]; END; decisionsByName: LORA _ NARROW[otherData]; name: Name _ GetName[cell]; descr: LORA _ GetDescr[name, decisionsByName]; decAt: ATOM; asAny: REF ANY; IF descr = NIL THEN RETURN [Yelp["no decision given"]]; IF descr.rest = NIL THEN BEGIN IF Possible[cell, Leaf] THEN RETURN [Leaf]; RETURN [Yelp["cant make it a Leaf"]]; END; IF NOT ISTYPE[descr.rest.first, ATOM] THEN RETURN [Yelp["decision not an Atom"]]; IF (asAny _ Atom.GetProp[atom: (decAt _ NARROW[descr.rest.first]), prop: decisionProp]) = NIL THEN RETURN [Yelp["atom not a decision"]]; IF (IF asAny = NIL THEN TRUE ELSE NOT ISTYPE[asAny, ExpandDecisionRef]) THEN RETURN [Yelp["atom not a decision"]]; RETURN [NARROW[asAny, ExpandDecisionRef]^]; END; GetName: PROC [cell: Cell] RETURNS [name: Name] = BEGIN name _ NIL; WHILE cell # NIL DO name _ CONS[cell.name, name]; cell _ cell.parent; ENDLOOP; END; GetDescr: PROC [name: Name, dbn: LORA] RETURNS [LORA] = BEGIN Matches: PROC [name: ROPE, asAny: REF ANY] RETURNS [BOOLEAN] = BEGIN dbn: LORA; s2: ROPE; IF NOT ISTYPE[asAny, LORA] THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [FALSE]; END; dbn _ NARROW[asAny]; IF (IF dbn = NIL THEN TRUE ELSE (IF dbn.first = NIL THEN TRUE ELSE (NOT ISTYPE[dbn.first, ROPE] AND NOT ISTYPE[dbn.first, ATOM]))) THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [FALSE]; END; s2 _ WITH dbn.first SELECT FROM r: ROPE => r, a: ATOM => Atom.GetPName[a], ENDCASE => ERROR; RETURN [Rope.Equal[s1: name, s2: s2, case: FALSE]]; END; WHILE name # NIL DO tail: LORA; IF (IF dbn = NIL THEN TRUE ELSE dbn.rest = NIL) THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [NIL]; END; FOR tail _ dbn.rest.rest, tail.rest WHILE tail # NIL DO IF Matches[name.first, tail.first] THEN EXIT; ENDLOOP; IF tail = NIL THEN TRUSTED BEGIN MessageWindow.Append[message: "No decsion", clearFirst: TRUE]; RETURN [NIL]; END; name _ name.rest; dbn _ NARROW[tail.first]; ENDLOOP; RETURN [dbn]; END; MakeQueryPauser: ViewRec.OtherStuffProc = BEGIN v: ViewRec.Viewer; [qp, v] _ Pausers.CreatePauser[enabledName: "Answer Query", disabledName: "", viewerInit: [parent: in, border: FALSE], paint: FALSE]; RETURN [LIST[v]]; END; Setup: PROC = BEGIN Atom.PutProp[atom: $N, prop: decisionProp, val: NEW [ExpandDecision _ Nested]]; Atom.PutProp[atom: $I, prop: decisionProp, val: NEW [ExpandDecision _ Inline]]; Atom.PutProp[atom: $L, prop: decisionProp, val: NEW [ExpandDecision _ Leaf]]; qerv _ ViewRec.ViewRef[ agg: eq, otherStuff: MakeQueryPauser, viewerInit: [iconic: TRUE, column: right, name: "ExpandQuery"]]; qv _ qerv.RVQuaViewer[]; END; Setup[]; END.