CDGenerateImportsImpl.mesa (part of ChipNDale)
Copyright © 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, June 5, 1985 8:02:35 pm PDT
Last Edited by Christian Jacobi, August 29, 1985 4:36:31 pm PDT
DIRECTORY
CD,
CDGenerate,
CDGenerateBackdoor,
CDGenerateImports,
CDIO,
CDImports,
RefTab,
Rope,
SymTab,
TerminalIO;
CDGenerateImportsImpl:
CEDAR
PROGRAM
IMPORTS CDGenerate, CDGenerateBackdoor, CDIO, CDImports, RefTab, Rope, SymTab, TerminalIO
EXPORTS CDGenerateImports =
BEGIN
dummy: CDGenerate.Table ← CDGenerate.Create[];
tableToName: RefTab.Ref ← RefTab.Create[];
nameToTable: SymTab.Ref ← SymTab.Create[];
UnspecSelector: CDGenerateBackdoor.SelectorProc =
BEGIN
key ← TerminalIO.RequestRope[label, " import [design.oject] >"];
END;
Selector: CDGenerateBackdoor.SelectorProc = {
dName: Rope.ROPE = ImporteeName[table];
key ← TerminalIO.RequestRope[Rope.Cat[label, " import oject from ", dName, " >"]];
};
ImportIGenerator: CDGenerateBackdoor.IGeneratorProc =
BEGIN
importeeName: Rope.ROPE ← ImporteeName[realTable];
imp: REF CDImports.Import;
IF Rope.IsEmpty[importeeName]
THEN {
TerminalIO.WriteRope["**generate with bad importee name\n"];
RETURN
};
imp ← CDImports.GetImport[design, importeeName];
IF imp=NIL OR imp.importee=NIL THEN DoImport[design, importeeName];
ob ← CDImports.GetReference[design, key, importeeName];
END;
UnspecImportIGenerator: CDGenerateBackdoor.IGeneratorProc =
BEGIN
dot: INT = TrailingDot[key];
importeeName: Rope.ROPE←NIL;
objectName: Rope.ROPE←NIL;
table: CDGenerate.Table;
IF dot < Rope.Length[key]
THEN {
objectName ← Rope.Substr[key, dot+1];
importeeName ← Rope.Substr[key, 0, dot]
};
IF ~Rope.IsEmpty[importeeName]
AND ~Rope.IsEmpty[objectName]
THEN {
table ← GetImportTable[importeeName];
ob ← CDGenerate.FetchNCall[table, design, objectName];
}
ELSE TerminalIO.WriteRope["**tried to import with bad syntax\n"];
END;
TrailingDot:
PROC [base: Rope.
ROPE]
RETURNS [
INT] = {
--position of last dot
len: INT ← Rope.Length[base];
pos: INT ← len;
WHILE pos > 0
DO
SELECT Rope.Fetch[base, pos ← pos - 1]
FROM
'. => RETURN [pos];
'!, '], '>, '/ => EXIT;
ENDCASE;
ENDLOOP;
RETURN [len];
};
ImporteeName:
PUBLIC
PROC [table: CDGenerate.Table]
RETURNS [r: Rope.
ROPE←
NIL] =
TRUSTED BEGIN
WITH tableToName.Fetch[
LOOPHOLE[table]].val
SELECT
FROM
n: Rope.ROPE => r ← n
ENDCASE => {
table ← CDGenerateBackdoor.Indiretee[table];
IF table#NIL THEN RETURN[ImporteeName[table]]
};
END;
GetImportTable:
PUBLIC PROC [designName: Rope.
ROPE]
RETURNS [table: CDGenerate.Table←
NIL] =
TRUSTED BEGIN
WITH nameToTable.Fetch[designName].val
SELECT
FROM
t: CDGenerate.Table => RETURN [t]
ENDCASE => NULL;
table ← CDGenerateBackdoor.CreateIndirect[onTopOf: dummy, iGenerator: ImportIGenerator,
selector: Selector, cache: TRUE, flushThrough: FALSE, clearThrough: FALSE, registerThrough: FALSE];
[] ← tableToName.Insert[LOOPHOLE[table], designName];
IF nameToTable.Insert[designName, LOOPHOLE[table]] THEN RETURN;
RETURN [GetImportTable[designName]] --indirection for concurrency problems
END;
DoImport:
PROC [importer:
CD.Design, importeeName: Rope.
ROPE] =
BEGIN
Check:
PROC [design:
CD.Design]
RETURNS [ok:
BOOL] =
BEGIN
ok ← design.technology=importer.technology;
IF
NOT ok
THEN {
TerminalIO.WriteRope["Technology missmatch: includee is "];
TerminalIO.WriteRope[design.technology.name];
TerminalIO.WriteRope["\n"];
RETURN
};
ok ← Rope.Equal[importeeName, CDIO.DesignInReadOperation[].name];
IF
NOT ok
THEN {
TerminalIO.WriteRope["import failed, file has design with different name\n"];
};
END;
done: BOOL ← FALSE;
design: CD.Design;
TerminalIO.WriteRope["load a design to generate imports\n"];
[] ← CDIO.UseWorkingDirectory[importer];
design ←
CDIO.ReadDesign[
CDIO.MakeName[
base: importeeName, ext: "dale", wDir: CDIO.GetWorkingDirectory[importer]], Check];
IF design#
NIL
THEN {
done ← CDImports.DoImport[design: importer, importee: design, allowOverload: interactive, allowConflicts: interactive];
};
TerminalIO.WriteRope[IF done THEN "import done\n" ELSE "import not done\n"];
END;
unspecImportTable: CDGenerate.Table ← CDGenerateBackdoor.CreateIndirect[
onTopOf: dummy,
iGenerator: UnspecImportIGenerator,
selector: UnspecSelector
];
TRUSTED {
[] ← SymTab.Insert[CDGenerateBackdoor.publicTables, "IMPORT", LOOPHOLE[unspecImportTable]];
};
END.