DIRECTORY Asserting, AssertingIO, Atom, Basics, Convert, FS, IO, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, RoseCreate, RoseTypes, ViewerOps, ViewRec; RoseDeciders: CEDAR PROGRAM IMPORTS Asserting, 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 _ Expand]; expandFirst: PUBLIC ExpandDeciderClosure _ PickInOrder[LIST[Expand, Leaf]]; leafFirst: PUBLIC ExpandDeciderClosure _ PickInOrder[LIST[Leaf, Expand]]; 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, relativeTo: Cell _ NIL] RETURNS [name: ROPE] = { name _ Rope.Cat[ IF n.cellIn = relativeTo THEN NIL ELSE IF n.cellIn # NIL THEN LongCellName[n.cellIn, relativeTo].Cat["."] ELSE "??.", n.name]; }; LongCellName: PUBLIC PROC [c: Cell, relativeTo: Cell _ NIL] RETURNS [name: ROPE] = { IF c = relativeTo THEN ERROR; name _ c.name; FOR c _ c.parent, c.parent WHILE c # relativeTo DO name _ c.name.Cat[".", name] ENDLOOP}; LongPortName: PUBLIC PROC [c: REF ANY--UNION[CellType, Cell]--, pi: PortIndex _ nilPortIndex, epi: EffectivePortIndex _ nilEffectivePortIndex] RETURNS [name: ROPE] = { SELECT TRUE FROM pi # nilPortIndex AND epi = nilEffectivePortIndex => { ports: Ports _ NIL; cName: ROPE _ "??"; WITH c SELECT FROM ct: CellType => {ports _ ct.ports; cName _ ct.name}; cell: Cell => {ports _ cell.type.ports; cName _ LongCellName[cell]}; ENDCASE => ERROR; name _ cName.Cat[".", ports[pi].name]; }; pi = nilPortIndex AND epi # nilEffectivePortIndex => { cell: Cell _ NARROW[c]; name _ LongCellName[cell].Cat[".", cell.realCellStuff.effectivePorts[epi].name]; }; ENDCASE => ERROR; }; LowestCommonAncestor: PUBLIC PROC [c1, c2: Cell] RETURNS [lca: Cell] = { tag: REF ANY; IF c1 = c2 THEN RETURN [c1]; FOR c: Cell _ c1.parent, c.parent WHILE c # NIL DO IF c = c2 THEN RETURN [c]; ENDLOOP; FOR c: Cell _ c2.parent, c.parent WHILE c # NIL DO IF c = c1 THEN RETURN [c]; ENDLOOP; tag _ NEW [Cell _ c1]; FOR c: Cell _ c1.parent, c.parent WHILE c # NIL DO c.other _ Asserting.AssertFn1[$LCASearch, tag, c.other]; ENDLOOP; FOR c: Cell _ c2.parent, c.parent WHILE c # NIL DO t2: REF ANY _ Asserting.FnVal[$LCASearch, c.other]; IF t2 = tag THEN RETURN [c]; ENDLOOP; lca _ NIL}; DepthChoices: TYPE = REF DepthChoicesRep; DepthChoicesRep: TYPE = RECORD [ shallow, deep: ExpandDeciderClosure, boundary: INT]; ByDepth: PUBLIC PROC [shallow: ExpandDeciderClosure, boundary: INT, deep: ExpandDeciderClosure] RETURNS [edc: ExpandDeciderClosure] = { edc _ NEW [ExpandDeciderClosureRep _ [ DecideByDepth, NEW [DepthChoicesRep _ [shallow, deep, boundary]] ]]; }; DecideByDepth: PROC [cell: Cell, otherData: REF ANY] RETURNS [ed: ExpandDecision] = { dc: DepthChoices _ NARROW[otherData]; depth: INT _ Depth[cell]; edc: ExpandDeciderClosure _ IF depth <= dc.boundary THEN dc.shallow ELSE dc.deep; ed _ edc.Decide[cell: cell, otherData: edc.otherData]; }; Depth: PROC [cell: Cell] RETURNS [depth: INT] = { depth _ IF cell.parent # NIL THEN (Depth[cell.parent]+1) ELSE 0; }; PickInOrder: PUBLIC PROC [bestFirst: --earlier=better--ExpandDecisionList] RETURNS [edc: ExpandDeciderClosure] = { edc _ NEW [ExpandDeciderClosureRep _ [DecideFromList, bestFirst]]; }; DecideFromList: PROC [cell: Cell, otherData: REF ANY] RETURNS [ed: ExpandDecision] = { bestFirst: ExpandDecisionList _ NARROW[otherData]; FOR bestFirst: ExpandDecisionList _ NARROW[otherData], bestFirst.rest WHILE bestFirst # NIL DO IF Possible[cell, bestFirst.first] THEN RETURN [bestFirst.first]; ENDLOOP; ERROR Error[IO.PutFR["No possible expand decision for %g", IO.refAny[LongCellName[cell]]], cell]; }; 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: $E, prop: decisionProp, val: NEW [ExpandDecision _ Expand]]; 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; ROPEToRef: TYPE = REF ROPEToRefRep; ROPEToRefRep: TYPE = RECORD [from: ROPE, to: REF ANY]; ROPEToST: TYPE = REF ROPEToSTRep; ROPEToSTRep: TYPE = RECORD [from: ROPE, to: SymbolTable]; CompareROPEToRefs: PROC [r1, r2: REF ANY] RETURNS [Basics.Comparison] = { Key: PROC [k: REF ANY] RETURNS [r: ROPE] = { WITH k SELECT FROM roap: ROPE => r _ roap; rr: ROPEToRef => r _ rr.from; ENDCASE => ERROR}; RETURN [Key[r1].Compare[Key[r2]]]}; CompareROPEToSTs: PROC [r1, r2: REF ANY] RETURNS [Basics.Comparison] = { Key: PROC [k: REF ANY] RETURNS [r: ROPE] = { WITH k SELECT FROM roap: ROPE => r _ roap; rr: ROPEToST => r _ rr.from; ENDCASE => ERROR}; RETURN [Key[r1].Compare[Key[r2]]]}; GetOtherss: PUBLIC PROC [fileName: ROPE] RETURNS [otherss: SymbolTable] = { in: IO.STREAM _ FS.StreamOpen[fileName]; otherss _ OrderedSymbolTableRef.CreateTable[CompareROPEToSTs]; DO cellTypeName: ROPE; cellST: SymbolTable; cellMap: ROPEToST; [] _ in.SkipWhitespace[]; IF in.EndOf[] THEN EXIT; cellTypeName _ in.GetRopeLiteral[]; cellST _ OrderedSymbolTableRef.CreateTable[CompareROPEToRefs]; cellMap _ NEW [ROPEToSTRep _ [cellTypeName, cellST]]; DO partName: ROPE; partAssertions: Assertions; partMap: ROPEToRef; [] _ in.SkipWhitespace[]; IF in.PeekChar[] = '. THEN {IF in.GetChar[] # '. THEN ERROR; EXIT}; partName _ in.GetRopeLiteral[]; partAssertions _ AssertingIO.Read[in]; partMap _ NEW [ROPEToRefRep _ [partName, partAssertions]]; cellST.Insert[partMap]; ENDLOOP; otherss.Insert[cellMap]; ENDLOOP; in.Close[]; }; GetOthers: PUBLIC PROC [otherss: SymbolTable, cellTypeName: ROPE] RETURNS [others: SymbolTable] = { rr: ROPEToST _ NARROW[otherss.Lookup[cellTypeName]]; others _ IF rr # NIL THEN rr.to ELSE NIL; }; GetOther: PUBLIC PROC [others: SymbolTable, partName: ROPE] RETURNS [assertions: Assertions] = { rr: ROPEToRef _ IF others # NIL THEN NARROW[others.Lookup[partName]] ELSE NIL; assertions _ IF rr # NIL THEN NARROW[rr.to] ELSE NIL }; Setup[]; END. ภRoseDeciders.Mesa Last Edited by: Spreitzer, April 29, 1985 12:23:38 pm PDT Last Edited by: Gasbarro, August 16, 1984 4:53:51 pm PDT Last Edited by: Barth, June 17, 1985 8:15:01 pm PDT สฎ– "cedar" style˜Icode™J™9J™8J™3K˜Kšฯk œ0œœa˜ K˜šะbx œœ˜Kšœ(œœ`˜•Kšœ ˜—K˜Kšœœ˜!K˜Kš œœœœœ˜Kš œœœœœœ˜Kšœœœ˜-K˜Kšœœ6˜HK˜Kšœ œœ˜'šœœœ˜Kšœœœ˜#Kšœ#˜#—K˜Kšœ œ$œ˜KKšœ œ$œ˜IK˜Kšœœ˜Kšœœ˜,K˜Kšœœ˜K˜š ฯnœœœ œœ˜SKš˜Kšœœœ˜'K˜$K˜ Kšœ˜—K˜šŸ œœœœœœœœœ˜XKš˜Kš œœœœœ˜Kšœ ˜ šœœ˜šœœœ œ˜(Kšœœ˜ Kšœœœ˜%Kšœœ˜—Kš œ œœœœœ!˜Sšœœ˜Kš œœ œmœœ˜—Kšœœ˜K˜K˜ Kšœ˜—Kšœ˜—K˜šŸ œœœœœœœœœ˜XKš˜Kš œœœœœ˜K˜šœœ˜šœœœ œ˜(Kšœœ˜ Kšœœœ˜%Kšœœ˜—Kšœ ˜ Kšœ œœœ˜Kš˜Kšœœ˜ Kšœœ˜ š œœœœœ˜'Kš˜KšœCœ˜IKšœœ˜Kšœ˜—Kšœœ˜š'œœœœœœœ œœœœœœ œœœœ œœ˜Kš˜KšœCœ˜IKšœœ˜Kšœ˜—šœœ œ˜Kšœœ˜ Kšœœ˜Kšœœ˜—Kšœ%œ˜3Kšœ˜—šœœ˜Kšœœ˜ šœœœœœœ œœ˜Kšœœ˜ Kšœ˜—K˜Kšœœ ˜Kšœ˜—Kšœ˜ Kšœ˜—K˜šŸœ˜)Kš˜Kšœ˜Kšœoœ œ˜…Kšœœ˜Kšœ˜—K˜šŸœœ˜ Kš˜Kšœ0œ˜OKšœ0œ˜M˜Kšœ˜K˜Kšœœ'˜@—K˜Kšœ˜—K˜Kšœ œœ˜#Kš œœœœœœ˜6K˜Kšœ œœ ˜!Kšœ œœœ˜9K˜š Ÿœœ œœœ˜Iš Ÿœœœœœœ˜,šœœ˜Kšœœ ˜Kšœ˜Kšœœ˜——Kšœ˜#—K˜š Ÿœœ œœœ˜Hš Ÿœœœœœœ˜,šœœ˜Kšœœ ˜Kšœ˜Kšœœ˜——Kšœ˜#—K˜š Ÿ œœœ œœ˜KKšœœœœ˜(K˜>š˜Kšœœ˜Kšœ˜Kšœ˜K˜Kšœ œœ˜K˜#Kšœ>˜>Kšœ œ(˜5š˜Kšœ œ˜K˜Kšœ˜K˜Kš œœœœœœ˜CKšœ˜K˜&Kšœ œ-˜:Kšœ˜Kšœ˜—K˜Kšœ˜—K˜ K˜—K˜š Ÿ œœœ&œœ˜cKšœœ˜4Kš œ œœœœœ˜)K˜—K˜š Ÿœœœ!œœ˜`Kš œœ œœœœœ˜NKš œ œœœœœ˜4K˜—K˜K˜K˜Kšœ˜—…—+ =