Oberon || Library || Module Index || Search Engine || Definition || Module
TYPE Identifier = ConstStrings.String; TYPE Object = CompilerObjects.Object; TYPE Location = CompilerObjects.Location;
TYPE Scope = POINTER TO ScopeRec; TYPE ScopeRec = RECORD (CompilerObjects.ObjectRec) END;
TYPE OpenProc = PROCEDURE (scope: Scope; VAR innerScope: Scope); TYPE CloseProc = PROCEDURE (scope: Scope); TYPE AddProc = PROCEDURE (scope: Scope; ident: Identifier; loc: Location; object: Object); TYPE UseProc = PROCEDURE (scope: Scope; ident: Identifier; loc: Location; VAR object: Object); TYPE LookupProc = PROCEDURE (scope: Scope; ident: Identifier; VAR object: Object) : BOOLEAN; TYPE LocalLookupProc = PROCEDURE (scope: Scope; ident: Identifier; VAR object: Object) : BOOLEAN; TYPE CutProc = PROCEDURE (scope: Scope); TYPE GetIteratorProc = PROCEDURE (scope: Scope; VAR it: Iterators.Iterator); TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) open: OpenProc; close: CloseProc; add: AddProc; use: UseProc; lookup: LookupProc; localLookup: LocalLookupProc; cut: CutProc; getIterator: GetIteratorProc; END;
PROCEDURE Init(scope: Scope; if: Interface);
PROCEDURE Open(scope: Scope; VAR innerScope: Scope); PROCEDURE Close(scope: Scope); PROCEDURE Cut(scope: Scope);
PROCEDURE Level(scope: Scope) : INTEGER; PROCEDURE Add(scope: Scope; ident: Identifier; loc: Location; object: Object); PROCEDURE Use(scope: Scope; ident: Identifier; loc: Location; VAR object: Object); PROCEDURE Lookup(scope: Scope; ident: Identifier; VAR object: Object) : BOOLEAN; PROCEDURE LocalLookup(scope: Scope; ident: Identifier; VAR object: Object) : BOOLEAN; PROCEDURE GetIterator(scope: Scope; VAR it: Iterators.Iterator);
Init initializes scope and associates it with the given interface if. The interface procedures are expected to meet the specifications following:
PROCEDURE OuterScope; TYPE Outer = INTEGER; PROCEDURE InnerScope; TYPE Inner = Outer; (* using ``Outer'' in inner scope *) TYPE Outer = INTEGER; (* redefining ``Outer'' in inner scope *) END InnerScope; END OuterScope;object must be set to NIL if the lookup was not successful.
Open creates a scope of the same implementation as scope that is nested into it, i.e. lookups that do not succeed in the current scope will be continued in the outer scope. Close freezes and finishes a scope, i.e. further additions of identifiers to scope are no longer permitted and error events will be generated. Cut unties a scope from its outer scope, i.e. lookups will be performed locally on scope only. Note that Cut does not change the nesting level of a scope.
Level returns the nesting level of a scope. Outmost scopes (i.e. those initialized by Init) have a nesting level of 0.
Add inserts object (declared at loc) with name ident into scope. loc may be NIL if not available. An error event is generated immediately or later on Close in case of errors.
Use looks for ident in scope (referenced at loc) and marks it as used. The object, if found, is stored into object; otherwise, it is set to NIL. loc may be NIL if not available. An error event is generated immediately or later on Close in case of errors.
Lookup looks for ident in scope and its associated outer scopes without marking it and without generating any error events. If successful, TRUE is returned and the object is stored into object. LocalLookup works like Lookup but does not consider the outer scopes of scope.
GetIterator returns an iterator in it that allows to iterate through all objects (not names!) added to scope. GetIterator must not be called before Close has been called for scope.
Implementations are free to postpone the generation of error events until Close is called for a scope to allow for enhanced error reports.
Oberon || Library || Module Index || Search Engine || Definition || Module