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, February 21, 1986 7:13:24 pm PST
DIRECTORY
CD,
CDGenerate,
CDGenerateBackdoor,
CDGenerateImports,
CDImports,
RefTab,
Rope,
SymTab,
TerminalIO;
CDGenerateImportsImpl:
CEDAR
PROGRAM
IMPORTS CDGenerate, CDGenerateBackdoor, 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[" 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];
IF Rope.IsEmpty[importeeName]
THEN {
TerminalIO.WriteRope["**generate with bad importee name\n"];
RETURN
};
ob ← CDImports.CreateImport[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
done: BOOL ← FALSE;
done ← CDImports.Load[into: importer, importeeName: importeeName, overload: 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.