CDGenerate.mesa (part of ChipNDale)
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, June 5, 1985 8:02:35 pm PDT
Last edited by: Christian Jacobi, October 20, 1986 12:48:33 pm PDT
DIRECTORY
CD, Rope, SymTab;
CDGenerate: CEDAR DEFINITIONS =
BEGIN
Common interface for object generators.
A Context is a name space of object generators.
Contexts may or may not cache the generated objects.
Caching genenerated objects: to avoid multiple generation of aequivalent objects.
The user assumes that he might reuse an object instead of creating a new object,
whenever he uses the caching scheme.
Context: TYPE = REF --READONLY-- ContextRep;
ContextRep: TYPE = RECORD [rep: PRIVATE REF, case: BOOL, cache: BOOL];
GeneratorProc: TYPE = PROC [design: CD.Design, key: Rope.ROPE, context: Context, data: REF] RETURNS [ob: CD.Object←NIL];
Create: PROC [case: BOOLTRUE, cache: BOOLTRUE] RETURNS [Context];
--creates a new, empty context
--cache: whether this context tries to cache generated objects
Clear: PROC [context: Context];
--undo all registrations in this context
Register: PROC[context: Context, key: Rope.ROPE, generator: GeneratorProc, cache: BOOLTRUE, data: REFNIL] RETURNS [first: BOOL];
--first: TRUE if key did not already exist
--cache: tries to cache the result; works only if context itself is willing to cache
--data: passed through to FetchNCall calling generator
FetchRegistration: PROC[context: Context, key: Rope.ROPE] RETURNS [generator: GeneratorProc, cache: BOOL, data: REF];
--fetch the registration of a generator key
--generator NIL if not found
FetchCached: PROC[context: Context, design: CD.Design, key: Rope.ROPE] RETURNS [CD.Object];
--fetch a generated object if it is cached.
--returns NIL if not found, not cached or looks different
FetchNCall: PROC[context: Context, design: CD.Design, key: Rope.ROPE, cache: BOOLTRUE] RETURNS [CD.Object];
--fetch a generator and invoke it
--returns NIL if not found or generated
--caching only if generator and this call want caching
Flush: PROC [context: Context, design: CD.Design, key: Rope.ROPE];
--Removes this entry from the cache
FlushAll: PROC [context: Context, design: CD.Design];
--Removes all entries from the cache
--convenient procedures
SelectOneOf: PROC [context: Context, label: Rope.ROPE] RETURNS [key: Rope.ROPE];
--Interactive selection of a generator from a context
--NIL if discarded
AssertContext: PROC [project: Rope.ROPE] RETURNS [Context];
--Fetches a context; if not done then create one and store it for next call of AssertTable.
--This context can be imported by lots of unknown applications...
END.