Library Reference
This module implements a standard contour model for name analysis. The
data structure is a tree of scopes, each of which can contain an
arbitrary number of definitions. A definition is a binding of an
identifier to an object in the definition table (see PDL Reference Manual);
the definition does not carry any other
information itself. The environment module provides operations for
building scope trees, adding definitions to specific scopes, and
searching individual scopes or sequences of scopes for the definition of
a particular identifier.
The module is capable of building multiple trees of scopes, and it
places no constraints on the sequence of construction, definition and
lookup operations.
#include "envmod.h"
Environment NewEnv ();
Environment NewScope (/* Environment e */);
int AddIdn (/* Environment e, int i, DefTableKey k */);
DefTableKey DefineIdn (/* Environment e, int i */);
DefTableKey KeyInScope (/* Environment e, int i */);
DefTableKey KeyInEnv (/* Environment e; int i */);
The type Environment is a pointer to the data structure representing the
tree of scopes. Identifiers are represented by integers.
The bindings contained in a scope are between integers and arbitrary
pointers.
These arbitrary pointers are all obtained via two operations external to
the environment module:
DefTableKey NoKey
- Returns the same value on every invocation.
DefTableKey NewKey()
- Returns a different value on each invocation.
The value returned by
NoKey is never returned by NewKey .
NoKey and NewKey may be supplied by the user of Eli, or they
may be exported by a generated definition table module
(see Keys of PDL Reference Manual).
NewEnv creates a new tree consisting of a single, empty scope and
returns a reference to that empty scope. NewScope creates a new
empty scope as a child of the scope referenced by its argument and
returns a reference to that empty scope.
AddIdn checks the scope referenced by its e argument for a
definition of the identifier specified by its i argument. If no
such definition is found, a definition binding the identifier i
to the definition table object specified by k is added to scope
e . AddIdn returns the value 0 if a definition
for i already exists, and returns 1 otherwise.
DefineIdn behaves exactly like AddIdn , except that if the
referenced scope contains no definition of i then DefineIdn
obtains a value from NewKey and binds i to that value
in scope e . In addition, DefineIdn always returns the
definition table key associated with i .
KeyInScope checks the scope referenced by its e argument
for a definition of the identifier specified by its i argument.
If no such definition is found, NoKey is returned. If a
definition is found, the definition table object bound to i is
returned.
KeyInEnv behaves the same way as KeyInScope except that
if no definition for i is found in scope e then the search
continues through successive ancestors of e .
If no definition for i is found in e or any of its ancestors,
NoKey is returned. Otherwise the definition table object bound
to i is returned.
If any function is invoked with an invalid environment argument
((ENVIRONMENT *) 0) , a deadly error ("CurrEnv: no
environment" ) is reported (see Error Reporting for a discussion of deadly errors).
|