LichenOtherTransforms.Mesa
Last tweaked by Mike Spreitzer on August 28, 1987 11:18:00 am PDT
DIRECTORY IO, Collections, LichenDataOps, LichenDataStructure, IntFunctions, PairCollections, LichenTransforms, LichenTransformsPrivate;
LichenOtherTransforms:
CEDAR
PROGRAM
IMPORTS IO, Collections, LichenDataOps, LichenDataStructure, IntFunctions, PairCollections, LichenTransforms
EXPORTS LichenTransforms
=
BEGIN OPEN LichenDataStructure, LichenTransforms, LichenDataOps, LichenTransformsPrivate, Colls:Collections, PCs:PairCollections, IntFns:IntFunctions;
CellTypeList: TYPE ~ LIST OF CellType;
GroupUnorganized:
PUBLIC
PROC
[
design: Design,
mapper: ConstFunction--any b Seq (role é sibling: instance of array* of type of newType's roleth child)--]
RETURNS [newType: CellType,
pairs: PCs.ConstOneToOne--domain of mapper é instance of array* of newType--,
gcs: Seq--role é instance in newType--] ~ {
ComputeName:
PROC []
RETURNS [r:
ROPE] ~ {
pair: PCs.Pair ~ mapper.First[].P;
r ← IO.PutFR["#gen%g", [integer[nGen ← nGen+1]]];
RETURN};
newTypeName: ROPE ~ ComputeName[];
pairsV: PCs.OneToOne ~ PCs.CreateHashOTO[];
Seed:
PROC [pair: PCs.Pair] ~ {
l <dom, seq> {ti ← Instantiate[newType, seq[0].parent]; pairs ← pairs + <dom, ti>}
seq: Seq--role é sibling: instance of array* of type of newType's roleth child-- ~ IntFns.DeRef[pair[right]];
ci0: CellInstance ~ NARROW[seq.Apply[0].val];
ti: CellInstance ~ FullyInstantiate[newType, ci0.containingCT];
IF NOT pairsV.Store[[pair[left], ti]] THEN ERROR;
RETURN};
newType ← CreateCellType[design, newTypeName, NIL, TRUE, NIL, NIL];
mapper.Enumerate[Seed];
pairs ← pairsV.Freeze;
gcs ← LowerChildren[design, newType, PCs.Compose[[pairs.Invert, mapper]].AsConst];
RETURN};
nGen: NATURAL ← 0;
SimpleGrouper:
PROC [design: Design, cellTypes: Set
--of CellType--]
RETURNS [grouper: ConstFunction
--any
b Seq (role
é sibling: instance of array
* of cellTypes[role])--] ~ {
roles: NATURAL ~ cellTypes.Size[];
ctSeq: Seq--role é CellType-- ~ IntFns.CreateFromCollection[coll: cellTypes];
grouperV: PCs.OneToOne ~ PCs.CreateHashOTO[];
PerCellType:
PROC [ra:
REF
ANY] ~ {
ct: CellType ~ NARROW[ra];
IF ct.asUnorganized#
NIL
THEN {
sibs: Seq--role é sibling: instance of array* of cellTypes[role]-- ~ CreateSeq[len: roles, oneToOne: TRUE];
PerInstance:
PROC [ra:
REF
ANY] ~ {
ci: CellInstance ~ NARROW[ra];
cit: CellType ← ci.type;
DO
mr: IntFns.MaybeInt ~ ctSeq.InvApply[cit];
IF mr.found
THEN {
role: NAT ~ mr.i;
IF sibs.AddPair[[role, ci], PCs.addIfNew][leftToRight]#new THEN ERROR;
RETURN};
IF cit.asArray=NIL THEN EXIT;
cit ← cit.asArray.eltType;
ENDLOOP;
RETURN};
ct.asUnorganized.containedInstances.Enumerate[PerInstance];
SELECT sibs.Size[]
FROM
0 => NULL;
roles => IF NOT grouperV.Store[[ct, sibs.Freeze.Refify]] THEN ERROR;
ENDCASE => ERROR;
};
RETURN};
design.cellTypes.Enumerate[PerCellType];
grouper ← grouperV.Freeze;
RETURN};
CellTypeListLength:
PROC [cellTypes: CellTypeList]
RETURNS [length:
NATURAL] ~ {
length ← 0;
FOR cellTypes ← cellTypes, cellTypes.rest WHILE cellTypes # NIL DO length ← length + 1 ENDLOOP;
RETURN};
BaseStar:
PROC [ct: CellType]
RETURNS [CellType] ~ {
WHILE ct.asArray#NIL DO ct ← ct.asArray.eltType ENDLOOP;
RETURN [ct]};
END.