CDImportCommands.mesa (part of ChipNDale)
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, March 20, 1984 5:50:51 pm PST
last edited Christian Jacobi, June 5, 1985 12:32:38 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.Object;
found: BOOLEAN;
import: REF Import;
TerminalIO.WriteRope["draw object of imported design; "];
importeeName ← TerminalIO.RequestRope["design > "! TerminalIO.UserAbort => {GOTO aborted}];
IF Rope.IsEmpty[importeeName] THEN CDSequencer.QuitCommand[" empty name; not done"];
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 loaded; 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 CDSequencer.QuitCommand[" not imported"]
ELSE {
IF mdata.importee#NIL THEN TerminalIO.WriteRope[" already loaded\n"]
ELSE TerminalIO.WriteRope[" not yet loaded\n"];
FOR list:
LIST
OF
CD.Object ← 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.boundInstance=
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"];
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["load a design for import\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 "done\n" ELSE "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 loaded; 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.Object←
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.Instance; -- the referred application to support the name
multiple: BOOLEAN;
[ap, multiple] ← CDOps.SelectedInstance[from];
IF multiple THEN Out[" multiple selection"]
ELSE IF ap=NIL THEN Out[" no selection"]
ELSE {
orient ← ap.orientation;
IF
NOT ap.ob.class.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.Object;
orient: CD.Orientation;
TerminalIO.WriteRope["draw corresponding object (import); "];
[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 loaded; 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.