CDImports.mesa (part of ChipNDale)
Copyright © 1984, 1985, 1986 1987 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, March 20, 1984 5:50:51 pm PST
Last edited by: Christian Jacobi, March 30, 1987 11:27:32 am PST
DIRECTORY
BasicTime, CD, Rope, SymTab;
CDImports: CEDAR DEFINITIONS =
BEGIN
Objects which reference Objects in other designs are called imports.
Imports are mutable! It is possible to re-bind Imports to a different source object.
Warning: don't make circular imports.
IsImport: PROC [ob: CD.Object] RETURNS [BOOL] = INLINE {
RETURN [ISTYPE[ob.specific, ImportSpecific] AND ob.class=importsClass]
};
importsClass: READONLY CD.ObjectClass; --refered record readonly too
ImportSpecific: TYPE = REF ImportRep;
ImportRep: TYPE = RECORD [ --consider all fields READONLY
boundOb: CD.Object ← NIL, -- NIL if not yet bound
boundDesign: CD.Design ← NIL,
ir: CD.Rect ← [0, 0, -1, -1],
objectName: Rope.ROPENIL,
designName: Rope.ROPENIL
];
BoolOrInteractive: TYPE = {true, false, interactive};
--creation and caching of imports
-- Designs have a cache for imported designs and imported objects
-- Caching is done by checking the cache without enumerating instances
FetchImport: PROC [into: CD.Design, objectName, importeeName: Rope.ROPE] RETURNS [ob: CD.Object];
--Returns an import object if object found in cache or NIL if none found.
CreateImportFromCache: PROC [into: CD.Design, objectName, importeeName: Rope.ROPE, load: BOOLFALSE] RETURNS [ob: CD.Object];
--Creates an import object; NIL if not done.
--load: load and cache design first if not already cached.
--If object not cached, requires design importeeName to be loaded (to know size of ob)
--Might return a cached object. Returned object is included in cache.
CreateImportWithoutSource: PROC [into: CD.Design, objectName, importeeName: Rope.ROPE, ir, bbox: CD.Rect, exact: BoolOrInteractive�lse] RETURNS [ob: CD.Object];
--Creates an import object; NIL if not done.
--Design importeeName need not be loaded nor will it be loaded.
--exact: in case a cached object is found but data is wrong a new object is created.
--Might return a cached object. Returned object is included in cache.
CreateImportWithSource: PROC [into: CD.Design, objectName: Rope.ROPE, source: CD.Design, exact: BOOLFALSE] RETURNS [ob: CD.Object];
--Creates an import object; NIL if not done.
--exact: in case a cached object is found but source is wrong a new object is created
--Design might or might not be included in cache. Returned object is included in cache.
--operation with imports
HasUnloadedImports: PROC [design: CD.Design←NIL, object: CD.Object←NIL, recurse: BOOLTRUE] RETURNS [yes: BOOLFALSE, where: LIST OF CD.Object←NIL];
-- Checks both, whether design or object has unloaded imports.
-- recurse: check whether imports depend on unloaded imports recursively
-- yes: whether some unloaded import is found
-- where: nesting where some unloaded import is found; #NIL if ~yes
MergeInImports: PROC [into: CD.Design, importeeName: Rope.ROPE];
--Includes all the imported and loaded objects from design importeeName (including
--their transitive closure; but not indirect imports) into the design "into".
LocalCopy: PROC [into: CD.Design, import: CD.Object] RETURNS [CD.Object];
--Makes a local copy of an import object; Children are copied over or replaced by imports.
--import is an import object from any source imported into into
--[Repeated LocalCopy might produce less good caching than calling MergeInImports]
LoadAndBindAll: PROC [into: CD.Design, allowConflicts: BoolOrInteractive←true, forceBind: BOOLFALSE] RETURNS [done: BOOL];
--Binds and caches all imported objects in into.
--allowConflicts: If conflicts are disabled, objects with size conflict will not be bound.
--forceBind: If objects are already bound, but to different source: Re-bind it.
--Takes designs from cache, unless not found then read file.
--Procedure talks to TerminalIO.
LoadAndBindDesign: PROC [into: CD.Design, importeeName: Rope.ROPE, allowConflicts: BoolOrInteractive←true, forceBind: BOOLFALSE, useCache: BOOLFALSE, fileName: Rope.ROPENIL, forceFile: BOOLFALSE] RETURNS [done: BOOL];
--Binds and caches all imported objects from design importeeName in into.
--allowConflicts: If conflicts are disabled, objects with size conflict will not be bound.
--forceBind: If objects are already bound, but to different source: Re-bind it.
--useCache: Take design from cache instead of reading in file.
--fileName: Optional; used in case a file is accessed.
--forceFile: Loads new file into design cache, even if already cached.
--done: On a coarse design basis; does not mean each object is bound.
--Procedure talks to TerminalIO.
ReBindObject: PROC [design: CD.Design, ob: CD.Object, importee: CD.Design, allowSizeConflicts: BoolOrInteractive ← true] RETURNS [ok: BOOL];
--Redo binding of an import object
--design: design where import object ob is included
--importee: design from where remote object shall be used
--Cache is not involved.
OccursInDrawing: PROC [x: CD.Object, in: CD.Object] RETURNS [BOOL];
--Recursivity test
--Check whether drawing of "in" would draw "x"
The following cacheing procedures and types are hints only.
Found cached objects must be validated before use; not a client function.
CacheList: TYPE = PRIVATE REF CacheListRec;
CacheListRec: TYPE = RECORD [list: LIST OF Cache]; -- READONLY to clients
--describes all the caching for imports of a design
Cache: TYPE = PRIVATE REF CacheRec;
CacheRec: TYPE = RECORD[ -- READONLY to clients
importeeName: Rope.ROPENIL,
importee: CD.Design ← NIL,
objects: SymTab.Ref ← NIL, --objects do not need to be included in importee !
data: REFNIL
];
GetCacheList: PRIVATE PROC [design: CD.Design] RETURNS [CacheList];
-- Returns the caches considered for imports into design.
-- Consider the list and its entries READONLY.
GetCache: PRIVATE PROC [into: CD.Design, importeeName: Rope.ROPE, createIfNotFound: BoolOrInteractive�lse] RETURNS [Cache];
-- Returns a cache for a particular import.
-- Consider the returned record READONLY
-- NIL if not found and not created.
DoCacheDesign: PRIVATE PROC [into: CD.Design, importee: CD.Design];
-- Caches a design.
-- importee must be readonly.
FindCachedDesign: PRIVATE PROC [designName: Rope.ROPE, fileName: Rope.ROPENIL, createdTime: BasicTime.GMT ← BasicTime.nullGMT, checkUnloadedImps: BOOLFALSE] RETURNS [found: CD.Design←NIL];
-- Tries hard to find a cached design and returns it, or NIL if not found.
-- Expect the cached design to be readonly.
-- fileName: checks that cached design really comes from this file.
-- checkUnloadedImps: returns cached design only if it has no indirect unloaded imports.
END.