CDImportCommands.mesa (part of Chipndale)
Copyright © 1984 by Xerox Corporation. All rights reserved.
by Christian Jacobi March 20, 1984 5:50:51 pm PST
last edited Christian Jacobi August 15, 1984 12:49:50 pm PDT
DIRECTORY
CD,
CDCallSpecific,
CDDirectory,
CDImports,
CDIO,
CDOps,
CDProperties,
CDSequencer,
Rope,
TerminalIO;
CDImportCommands:
CEDAR
PROGRAM
IMPORTS CDDirectory, CDImports, CDIO, CDOps, CDSequencer, Rope, TerminalIO =
BEGIN
ReferencePtr: TYPE = CDImports.ReferencePtr;
ReferenceRep: TYPE = CDImports.ReferenceRep;
ImportList: TYPE = CDImports.ImportList;
Import: TYPE = CDImports.Import;
GetImportedEntryCommand:
PROC [comm: CDSequencer.Command] =
BEGIN
importeeName, objectName: Rope.ROPE;
referenceOb, referedOb: CD.ObPtr;
found: BOOLEAN;
import: REF Import;
TerminalIO.WriteRope["Include referenced entry; "];
importeeName ← TerminalIO.RequestRope["design > "! TerminalIO.UserAbort => {GOTO aborted}];
IF Rope.IsEmpty[importeeName]
THEN {
TerminalIO.WriteRope[" empty name; not done\n"];
RETURN
};
import ← CDImports.GetImport[design: comm.design, importeeName: importeeName, createIfNotFound: false];
IF import=
NIL
OR import.importee=
NIL
THEN {
TerminalIO.WriteRope["design "];
TerminalIO.WriteRope[importeeName];
TerminalIO.WriteRope[" not yet imported; not done\n"];
RETURN
};
objectName ← TerminalIO.RequestRope["entry > "! TerminalIO.UserAbort => {GOTO aborted}];
[found, referedOb] ← CDDirectory.Fetch[import.importee, objectName];
IF
NOT found
THEN {
TerminalIO.WriteRope[objectName];
TerminalIO.WriteRope[" not found in design "];
TerminalIO.WriteRope[importeeName];
TerminalIO.WriteRope["; not done\n"];
RETURN
};
referenceOb ← CDImports.GetReference[design: comm.design, objectName: objectName, importeeName: importeeName];
CDOps.AddAnObject[design: comm.design, ob: referenceOb, location: comm.pos];
END;
DisplayImports:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope[comm.design.name];
TerminalIO.WriteRope["'s import list: "];
TerminalIO.WriteRope[comm.design.name];
TerminalIO.WriteRope["\n"];
FOR list:
LIST
OF
REF Import ← CDImports.GetImportList[comm.design]^, list.rest
WHILE list#
NIL
DO
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[list.first.importeeName];
TerminalIO.WriteRope[IF list.first.importee=NIL THEN " -\n" ELSE " +\n"];
ENDLOOP;
TerminalIO.WriteRope["---\n"]
END;
DisplayImportedEntries:
PROC [comm: CDSequencer.Command] =
BEGIN
hasNotBound: BOOL ← FALSE; -- if importee loaded
importeeName: Rope.ROPE;
mdata: REF Import;
TerminalIO.WriteRope["display used entries of imported design\n"];
importeeName ← TerminalIO.RequestRope["design > "];
mdata ← CDImports.GetImport[comm.design, importeeName, false];
TerminalIO.WriteRope[importeeName];
IF mdata=
NIL
THEN {
TerminalIO.WriteRope[" not imported\n"];
RETURN
}
ELSE {
IF mdata.importee#NIL THEN TerminalIO.WriteRope[" already loaded\n"]
ELSE TerminalIO.WriteRope[" not yet loaded\n"];
FOR list:
LIST
OF
CD.ObPtr ← mdata.referenceList, list.rest
WHILE list#
NIL
DO
rp: ReferencePtr ~ NARROW[list.first.specificRef];
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[CDDirectory.Name[list.first]];
TerminalIO.WriteRope[" ("];
TerminalIO.WriteRope[rp.objectName];
TerminalIO.WriteRope[")"];
IF rp.boundApp=
NIL
AND mdata.importee#
NIL
THEN {
hasNotBound←TRUE;
TerminalIO.WriteRope[" not bound"];
};
TerminalIO.WriteRope["\n"];
ENDLOOP;
TerminalIO.WriteRope["---"];
IF hasNotBound
THEN {
TerminalIO.WriteRope[" has not bound entries"];
RETURN
};
TerminalIO.WriteRope["\n"]
};
END;
ImportReadCommand:
PROC [comm: CDSequencer.Command] =
BEGIN
Check:
PROC [design:
CD.Design]
RETURNS [ok:
BOOL] =
BEGIN
ok ← design.technology=comm.design.technology;
IF
NOT ok
THEN {
TerminalIO.WriteRope["Technology missmatch: includee is "];
TerminalIO.WriteRope[design.technology.name];
TerminalIO.WriteRope["\n"];
RETURN
};
ok ← NOT Rope.Equal[comm.design.name, CDIO.DesignInReadOperation[].name];
IF
NOT ok
THEN {
TerminalIO.WriteRope["design can not be imported, it has same name\n"];
};
END;
done: BOOL ← FALSE;
design: CD.Design;
TerminalIO.WriteRope["import the directory of an input design\n"];
[] ← CDIO.UseWorkingDirectory[comm.design];
design ← CDIO.ReadDesign[NIL, Check];
IF design#
NIL
THEN {
done ← CDImports.DoImport[design: comm.design, importee: design, allowOverload: interactive, allowConflicts: interactive];
};
TerminalIO.WriteRope[IF done THEN "include done\n" ELSE "include not done\n"];
END;
MerginImportCommand:
PROC [comm: CDSequencer.Command] =
BEGIN
importeeName: Rope.ROPE;
mdata: REF Import;
TerminalIO.WriteRope["merge imports into the design\n"];
importeeName ← TerminalIO.RequestRope["imported design > "];
mdata ← CDImports.GetImport[comm.design, importeeName, false];
IF mdata=
NIL
THEN {
TerminalIO.WriteRope[importeeName];
TerminalIO.WriteRope[" not imported; not done\n"];
RETURN
}
ELSE
IF mdata.importee=
NIL
THEN {
TerminalIO.WriteRope[importeeName];
TerminalIO.WriteRope[" is not yet bound; not done\n"];
RETURN
};
CDImports.MergeInImport[design: comm.design, importeeName: importeeName];
TerminalIO.WriteRope["end merge\n"];
END;
--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--multi-design-copy feature
selectedDesign: CD.Design ← NIL;
SelectADesign:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["select "];
TerminalIO.WriteRope[comm.design.name];
TerminalIO.WriteRope[" for inter-design source\n"];
selectedDesign ← comm.design;
END;
GlobalSelection:
PROC [expectedTechnology:
CD.Technology]
RETURNS [foundNamed:
BOOL←
FALSE, foundWithoutChildren:
BOOL←
FALSE, moduleName: Rope.
ROPE←
NIL, objectName: Rope.
ROPE←
NIL, object:
CD.ObPtr←
NIL, orient:
CD.Orientation←
CD.original] =
--never returns with both foundNamed and foundWithoutChildren set to true
--if not found then message to TerminalIO
--if foundNamed then both, moduleName, objectName # NIL
BEGIN
Out: PROC [t: Rope.ROPE] = {TerminalIO.WriteRope[t]};
from: CD.Design = selectedDesign; -- so it does not change
IF from=NIL THEN Out[" no selected design"]
ELSE {
fromName: Rope.ROPE = from.name; -- so it does not change
IF Rope.IsEmpty[fromName] THEN Out[" selected design has no name"]
ELSE
IF expectedTechnology#from.technology
AND expectedTechnology#
NIL
THEN
Out[" different technologies"]
ELSE {
ap: CD.ApplicationPtr; -- the referred application to support the name
multiple: BOOLEAN;
[ap, multiple] ← CDOps.SelectedApplication[from];
IF multiple THEN Out[" multiple selection"]
ELSE IF ap=NIL THEN Out[" no selection"]
ELSE {
orient ← ap.orientation;
IF
NOT ap.ob.p.inDirectory
THEN {
object ← ap.ob;
foundWithoutChildren ← TRUE;
}
ELSE {
entryName: Rope.ROPE = CDDirectory.Name[ap.ob];
IF Rope.IsEmpty[entryName] THEN Out[" object has no name"]
ELSE {
moduleName ← fromName;
objectName ← entryName;
foundNamed ← TRUE;
}
}
}
}
}
END;
DrawImportedCopy:
PROC [comm: CDSequencer.Command] =
BEGIN
foundNamed: BOOL;
foundWithoutChildren: BOOL;
moduleName: Rope.ROPE;
objectName: Rope.ROPE;
referenceOb, referedOb: CD.ObPtr;
orient: CD.Orientation;
TerminalIO.WriteRope["create corresponding object; "];
[foundNamed: foundNamed, foundWithoutChildren: foundWithoutChildren, moduleName: moduleName, objectName: objectName, object: referedOb, orient: orient] ← GlobalSelection[comm.design.technology];
IF foundNamed
THEN {
import: REF Import ~ CDImports.GetImport[design: comm.design, importeeName: moduleName, createIfNotFound: false];
IF Rope.Equal[moduleName, comm.design.name]
THEN {
TerminalIO.WriteRope[" don't refer itself; not done\n "];
RETURN
};
IF import=
NIL
OR import.importee=
NIL
THEN {
TerminalIO.WriteRope[" design "];
TerminalIO.WriteRope[moduleName];
TerminalIO.WriteRope[" not yet imported; not done\n"];
RETURN
};
[foundNamed, referedOb] ← CDDirectory.Fetch[import.importee, objectName];
IF
NOT foundNamed
THEN {
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[objectName];
TerminalIO.WriteRope[" not found in imported design "];
TerminalIO.WriteRope[moduleName];
TerminalIO.WriteRope["; not done\n"];
RETURN
};
referenceOb ← CDImports.GetReference[design: comm.design, objectName: objectName, importeeName: moduleName];
IF referenceOb=
NIL
THEN {
TerminalIO.WriteRope[" NIL object; not done\n"];
RETURN
};
CDOps.AddAnObject[design: comm.design, ob: referenceOb, location: comm.pos, orientation: orient];
TerminalIO.WriteRope[CDOps.Info[referenceOb]];
TerminalIO.WriteRope[" included\n"];
}
ELSE
IF foundWithoutChildren
THEN {
CDOps.AddAnObject[design: comm.design, ob: referedOb, location: comm.pos, orientation: orient];
TerminalIO.WriteRope[CDOps.Info[referedOb]];
TerminalIO.WriteRope[" copied\n"];
}
ELSE TerminalIO.WriteRope["; not done\n"];
END;
CDSequencer.ImplementCommand[$DrawImported, GetImportedEntryCommand];
CDSequencer.ImplementCommand[$DisplayImports, DisplayImports,, doQueue];
CDSequencer.ImplementCommand[$DisplayImportedEntries, DisplayImportedEntries,, doQueue];
CDSequencer.ImplementCommand[$ImportADesign, ImportReadCommand];
CDSequencer.ImplementCommand[$SelectADesign, SelectADesign,, doQueue];
CDSequencer.ImplementCommand[$DrawCorrespondingObject, DrawImportedCopy];
CDSequencer.ImplementCommand[$MerginImport, MerginImportCommand];
END.