FileDocCategorySizeDatePackage
SymbolTable.javaAPI DocGlassfish v2 API6021Fri May 04 22:35:08 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.query.util.scope

SymbolTable

public class SymbolTable extends Object
The symbol table handling declared identifies.
author
Michael Bouschen
version
0.1

Fields Summary
protected int
actualScope
The actual scope level.
protected Stack
nestings
Stack of old definitions.
protected Hashtable
symbols
The table of declared identifier (symbols).
Constructors Summary
Methods Summary
public Definitiondeclare(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.

param
ident identifier to be declared
param
definition new definition of identifier
return
the old definition if the identifier was already declared in the actual scope; null otherwise

        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 voidenterScope()
Opens a new scope. Prepare everything to handle old definitions when a identifier declaration is hidden.


                           
      
    
        actualScope++;
        nestings.push(new Nesting());
    
protected voidforgetNesting(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.

param
nesting list of hidden definitions

        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 intgetActualScope()
Returns the level of the actual scope.

return
actual scope level.

		return actualScope;
	
public DefinitiongetDefinition(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.

param
ident the name of identifier
return
the actual definition of ident is declared; null otherise.

        return (Definition)symbols.get(ident);
    
public booleanisDeclared(java.lang.String ident)
Checks whether the specified identifier is declared.

param
ident the name of identifier to be tested
return
true if the identifier is declared; false otherwise.

        return (getDefinition(ident) != null);
    
public voidleaveScope()
Closes the actual scope. Hidden definitions are reinstalled.

        forgetNesting((Nesting)nestings.pop());
        actualScope--;