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
Last Edited by: Jacobi July 23, 1986 3:00:29 pm PDT
DIRECTORY
CD,
CDGenerate,
CDGenerateBackdoor,
CDGenerateImports,
CDImports,
FileNames,
RefTab,
Rope,
SymTab,
TerminalIO;
CDGenerateImportsImpl:
CEDAR
PROGRAM
IMPORTS CDGenerate, CDGenerateBackdoor, CDImports, FileNames, 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.object] >"];
END;
Selector: CDGenerateBackdoor.SelectorProc = {
dName: Rope.ROPE = ImporteeName[table];
key ← TerminalIO.RequestRope[Rope.Cat[label, " import object 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
dotIndex: INT; importeeName, objectName: Rope.ROPE ← NIL;
name: Rope.ROPE ← FileNames.GetShortName[key];
dotIndex ← Rope.Index[name, 0, "."]; --the first dot! multiple dots belong to the object name
IF dotIndex<Rope.Length[name]
THEN {
objectName ← Rope.Substr[name, dotIndex+1];
importeeName ← Rope.Substr[name, 0, dotIndex]
};
IF ~Rope.IsEmpty[importeeName]
AND ~Rope.IsEmpty[objectName]
THEN {
table: CDGenerate.Table ← GetImportTable[importeeName];
ob ← CDGenerate.FetchNCall[table, design, objectName];
}
ELSE TerminalIO.WriteRopes["**tried to import with bad syntax; [", key, "]\n"];
END;
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.