Methods Summary |
---|
public Definition | declare(java.lang.String ident, Definition def)Add identifier to the actual scope.
If the identifier was already declared in the actual
scope the symbol table is NOT changed and the old definition
is returned. Otherwise a possible definition of a lower
level scope is saved in the actual nesting and the new definition
is stored in the symbol table. This allows to reinstall the old
definition when the sctaul scope is closed.
Definition old = (Definition)symbols.get(ident);
def.setScope(actualScope);
if ((old == null) || (old.getScope() < actualScope))
{
Nesting nest = (Nesting)nestings.peek();
nest.add(ident, old); // save old definition in nesting
symbols.put(ident, def); // install new definition as actual definition
return null;
}
else
{
return old;
}
|
public void | enterScope()Opens a new scope.
Prepare everything to handle old definitions when
a identifier declaration is hidden.
actualScope++;
nestings.push(new Nesting());
|
protected void | forgetNesting(Nesting nesting)Internal method to reinstall the old definitions.
The method is called when a scope is closed.
For all identifier that were declared in the
closed scope their former definition (that was hidden)
is reinstalled.
String ident = null;
Definition hidden = null;
Iterator idents = nesting.getIdents();
Iterator hiddenDefs = nesting.getHiddenDefinitions();
while (idents.hasNext())
{
ident = (String) idents.next();
hidden = (Definition) hiddenDefs.next();
if (hidden == null)
{
symbols.remove(ident);
}
else
{
symbols.put(ident, hidden);
}
}
|
public int | getActualScope()Returns the level of the actual scope.
return actualScope;
|
public Definition | getDefinition(java.lang.String ident)Checks the symbol table for the actual definition
of the specified identifier. If the identifier is
declared the definition is returned, otherwise null.
return (Definition)symbols.get(ident);
|
public boolean | isDeclared(java.lang.String ident)Checks whether the specified identifier is declared.
return (getDefinition(ident) != null);
|
public void | leaveScope()Closes the actual scope.
Hidden definitions are reinstalled.
forgetNesting((Nesting)nestings.pop());
actualScope--;
|