LichenNavigationImpl.mesa
Last tweaked by Mike Spreitzer on April 13, 1987 8:28:32 am PDT
DIRECTORY Asserting, LichenDataStructure, LichenNavigation, LichenSetTheory, RegularExpression, Rope;
LichenNavigationImpl:
CEDAR
PROGRAM
IMPORTS Asserting, LichenDataStructure, LichenSetTheory, RegularExpression, Rope
EXPORTS LichenNavigation
=
BEGIN OPEN LichenSetTheory, LichenDataStructure, LichenNavigation;
CTByName:
PUBLIC
PROC [d: Design, name:
ROPE]
RETURNS [ans: CellType ←
NIL] ~ {
TestCT:
PROC [ra:
REF
ANY] ~ {
ct: CellType ~ NARROW[ra];
IF HasName[ct.otherPublic, name] THEN ans ← ct;
};
d.cellTypes.Enumerate[TestCT];
};
CTsByName:
PUBLIC
PROC [d: Design, pattern:
ROPE, case:
BOOL ←
TRUE]
RETURNS [Set
--of CellType--] ~ {
f: RegularExpression.Finder ~ RegularExpression.CreateFromRope[
pattern: pattern,
ignoreCase: NOT case,
addBounds: TRUE];
ans: Set--of CellType-- ~ CreateHashSet[];
TestCT:
PROC [ra:
REF
ANY] ~ {
ct: CellType ~ NARROW[ra];
IF HasMatchingName[ct.otherPublic, f] AND NOT ans.UnionSingleton[ct] THEN ERROR;
};
d.cellTypes.Enumerate[TestCT];
RETURN [ans];
};
ChildByName:
PUBLIC
PROC [ct: CellType, name:
ROPE]
RETURNS [ans: Vertex ←
NIL] ~ {
TestV:
PROC [ra:
REF
ANY] ~ {
v: Vertex ~ NARROW[ra];
IF HasName[v.other, name] THEN ans ← v;
};
ct.asUnorganized.containedInstances.Enumerate[TestV];
};
ChildrenByName:
PUBLIC
PROC [ct: CellType, pattern:
ROPE, case:
BOOL ←
TRUE]
RETURNS [Set
--of CellType--] ~ {
f: RegularExpression.Finder ~ RegularExpression.CreateFromRope[
pattern: pattern,
ignoreCase: NOT case,
addBounds: TRUE];
ans: Set--of CellType-- ~ CreateHashSet[];
TestV:
PROC [ra:
REF
ANY] ~ {
v: Vertex ~ NARROW[ra];
IF HasMatchingName[v.other, f] AND NOT ans.UnionSingleton[v] THEN ERROR;
};
ct.asUnorganized.containedInstances.Enumerate[TestV];
RETURN [ans];
};
ChildByType:
PUBLIC
PROC [parent, type: CellType]
RETURNS [ans: CellInstance ←
NIL] ~ {
TestV:
PROC [ra:
REF
ANY] ~ {
ci: CellInstance ~ NARROW[ra];
IF ci.type=type THEN ans ← ci;
};
parent.asUnorganized.containedInstances.Enumerate[TestV];
};
ChildrenByType:
PUBLIC
PROC [parent, type: CellType]
RETURNS [ans: Set
--of CellInstance--] ~ {
TestV:
PROC [ra:
REF
ANY] ~ {
ci: CellInstance ~ NARROW[ra];
IF ci.type=type AND NOT ans.UnionSingleton[ci] THEN ERROR;
};
ans ← CreateHashSet[];
parent.asUnorganized.containedInstances.Enumerate[TestV];
};
PortByName:
PUBLIC
PROC [root: Port, name:
ROPE]
RETURNS [Port] ~ {
stack: PortList ← LIST[root];
WHILE stack#
NIL
DO
p: Port ~ stack.first;
IF HasName[p.other, name] THEN RETURN [p];
stack ← stack.rest;
IF p.firstChild#NIL THEN stack ← CONS[p.firstChild, stack];
IF p.next#NIL THEN stack ← CONS[p.next, stack];
ENDLOOP;
RETURN [NIL];
};
PortsByName:
PUBLIC
PROC [root: Port, pattern:
ROPE, case:
BOOL ←
TRUE]
RETURNS [ans: Set
--of Port--] ~ {
f: RegularExpression.Finder ~ RegularExpression.CreateFromRope[
pattern: pattern,
ignoreCase: NOT case,
addBounds: TRUE];
stack: PortList ← LIST[root];
ans ← CreateHashSet[];
WHILE stack#
NIL
DO
p: Port ~ stack.first;
IF HasMatchingName[p.other, f] AND NOT ans.UnionSingleton[p] THEN ERROR;
stack ← stack.rest;
IF p.firstChild#NIL THEN stack ← CONS[p.firstChild, stack];
IF p.next#NIL THEN stack ← CONS[p.next, stack];
ENDLOOP;
RETURN [NIL];
};
Quit: ERROR ~ CODE;
HasName:
PROC [assns: Assertions, name:
ROPE]
RETURNS [
BOOL] ~ {
TestName:
PROC [assertion: Assertion] ~ {
terms: LORA ~ Asserting.TermsOf[assertion];
thisN: ROPE ~ NARROW[terms.first];
IF terms.rest#NIL THEN ERROR;
IF name.Equal[thisN] THEN Quit;
};
Asserting.EnumerateAssertionsAbout[nameReln, assns, TestName !Quit => GOTO Has];
RETURN [FALSE];
EXITS Has => RETURN [TRUE];
};
HasMatchingName:
PROC [assns: Assertions, f: RegularExpression.Finder]
RETURNS [
BOOL] ~ {
TestName:
PROC [assertion: Assertion] ~ {
terms: LORA ~ Asserting.TermsOf[assertion];
thisN: ROPE ~ NARROW[terms.first];
IF terms.rest#NIL THEN ERROR;
IF f.SearchRope[thisN].found THEN Quit;
};
Asserting.EnumerateAssertionsAbout[nameReln, assns, TestName !Quit => GOTO Has];
RETURN [FALSE];
EXITS Has => RETURN [TRUE];
};
FilterSet:
PUBLIC
PROC [big: Set,
Test:
PROC [ra:
REF
ANY]
RETURNS [passes:
BOOL]]
RETURNS [filtered: Set] ~ {
MaybePass:
PROC [ra:
REF
ANY] ~ {
IF Test[ra] AND NOT filtered.UnionSingleton[ra] THEN ERROR;
};
filtered ← CreateHashSet[];
big.Enumerate[MaybePass];
big ← big;
};
END.