xtc.util
Class SymbolTable.Scope

java.lang.Object
  extended by xtc.util.SymbolTable.Scope
Enclosing class:
SymbolTable

public static class SymbolTable.Scope
extends java.lang.Object

A symbol table scope. A scope has a name and may have a parent (unless it is the root scope), one or more nested scopes, and one or more definitions.


Method Summary
 void addDefinition(java.lang.String symbol, java.lang.Object value)
          Add the specified value to the specified symbol's values in this scope.
 void define(java.lang.String symbol, java.lang.Object value)
          Set the specified symbol's value to the specified value in this scope.
 void dump(Printer printer)
          Dump the contents of this scope.
 java.lang.String getName()
          Get this scope's unqualfied name.
 SymbolTable.Scope getNested(java.lang.String name)
          Get the nested scope with the specified unqualified name.
 SymbolTable.Scope getParent()
          Get this scope's parent.
 java.lang.String getQualifiedName()
          Get this scope's qualified name.
 boolean hasNested()
          Determine whether this scope has any nested scopes.
 boolean hasNested(java.lang.String name)
          Determine whether this scope has the specified unqualified nested scope.
 boolean hasSymbols()
          Determine whether this scope has any local definitions.
 boolean isDefined(java.lang.String symbol)
          Determine whether the specified unqualified symbol is defined in this scope or any of its ancestors.
 boolean isDefinedLocally(java.lang.String symbol)
          Determine whether the specified symbol is defined in this scope.
 boolean isDefinedMultiply(java.lang.String symbol)
          Determine whether the specified symbol is defined multiple times in this scope or any of its ancestors.
 boolean isMergeable(java.lang.String name)
          Determine whether the scope with the specified unqualified name can be merged into this scope.
 boolean isRoot()
          Determine whether this scope is the root scope.
 java.lang.Object lookup(java.lang.String symbol)
          Get the value for the specified unqualified symbol.
 SymbolTable.Scope lookupBoundScope(java.lang.String symbol)
          Get the scope named by the specified unqualified symbol, which is nested in the scope defining the symbol.
 java.lang.Object lookupLocally(java.lang.String symbol)
          Get the local value for the specified unqualified symbol.
 SymbolTable.Scope lookupScope(java.lang.String symbol)
          Get the scope defining the specified unqualified symbol.
 void merge(java.lang.String name)
          Merge the nested scope with the specified unqualified name into this scope.
 java.util.Iterator<java.lang.String> nested()
          Get an iterator over the names of all nested scopes.
 java.lang.String qualify(java.lang.String symbol)
          Qualify the specified unqualified symbol with this scope's name.
 java.util.Iterator<java.lang.String> symbols()
          Get an iterator over the all locally defined symbols.
 void undefine(java.lang.String symbol)
          Undefine the specified unqualified symbol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Get this scope's unqualfied name.

Returns:
This scope's unqualified name.

getQualifiedName

public java.lang.String getQualifiedName()
Get this scope's qualified name.

Returns:
This scope's qualified name.

isRoot

public boolean isRoot()
Determine whether this scope is the root scope.

Returns:
true if this scope is the root scope.

getParent

public SymbolTable.Scope getParent()
Get this scope's parent.

Returns:
This scope's parent scope or null if this scope does not have a parent (i.e., is the root scope).

hasNested

public boolean hasNested()
Determine whether this scope has any nested scopes.

Returns:
true if this scope has any nested scopes.

nested

public java.util.Iterator<java.lang.String> nested()
Get an iterator over the names of all nested scopes.

Returns:
An iterator over the nested scopes.

hasNested

public boolean hasNested(java.lang.String name)
Determine whether this scope has the specified unqualified nested scope.

Parameters:
name - The nested scope's unqualified name.
Returns:
true if the corresponding scope exists.

getNested

public SymbolTable.Scope getNested(java.lang.String name)
Get the nested scope with the specified unqualified name.

Parameters:
name - The nested scope's unqualified name.
Returns:
The corresponding scope or null if there is no such scope.

isMergeable

public boolean isMergeable(java.lang.String name)
Determine whether the scope with the specified unqualified name can be merged into this scope. A nested scope can be merged if it (1) does not contain any bindings with the same names as this scope's bindings and (2) does not have any children with the same names as this scope's children.

Parameters:
name - The nested scope's unqualified name.
Returns:
true if the scope can be merged.
Throws:
java.lang.IllegalArgumentException - Signals that this scope does not have a nested scope with the specified name.

merge

public void merge(java.lang.String name)
Merge the nested scope with the specified unqualified name into this scope.

Parameters:
name - The nested scope's unqualified name.
Throws:
java.lang.IllegalArgumentException - Signals that (1) this scope does not have a nested scope with the specified name, (2) any of the nested scope's children has the same name as one of this scope's children, or (3) any of the nested scope's bindings has the same name as one of this scope's bindings.

hasSymbols

public boolean hasSymbols()
Determine whether this scope has any local definitions.

Returns:
true if this scope has any local definitions.

symbols

public java.util.Iterator<java.lang.String> symbols()
Get an iterator over the all locally defined symbols.

Returns:
An iterator over the locally defined symbols.

isDefinedLocally

public boolean isDefinedLocally(java.lang.String symbol)
Determine whether the specified symbol is defined in this scope.

Parameters:
symbol - The unqualified symbol.
Returns:
true if the symbol is defined in this scope.

isDefined

public boolean isDefined(java.lang.String symbol)
Determine whether the specified unqualified symbol is defined in this scope or any of its ancestors.

Parameters:
symbol - The unqualified symbol.
Returns:
true if the symbol is defined in this scope or any of its ancestors.

isDefinedMultiply

public boolean isDefinedMultiply(java.lang.String symbol)
Determine whether the specified symbol is defined multiple times in this scope or any of its ancestors.

Parameters:
symbol - The unqualified symbol.
Returns:
true if the symbol is defined multiple times.

lookupScope

public SymbolTable.Scope lookupScope(java.lang.String symbol)
Get the scope defining the specified unqualified symbol. This method searches this scope and all its ancestors, returning the first defining scope.

Parameters:
symbol - The unqualified symbol.
Returns:
The definining scope or null if there is no such scope.

lookup

public java.lang.Object lookup(java.lang.String symbol)
Get the value for the specified unqualified symbol. This method searches this scope and all its ancestors, returning the value of the first definition.

Parameters:
symbol - The unqualified symbol.
Returns:
The corresponding value or null if there is no definition.

lookupBoundScope

public SymbolTable.Scope lookupBoundScope(java.lang.String symbol)
Get the scope named by the specified unqualified symbol, which is nested in the scope defining the symbol. This method searches this scope and all its ancestors, up to the first defining scope. It then looks for the nested scope with the same name.

Parameters:
symbol - The unqualified symbol.
Returns:
The bound scope or null if there is no definition or nested scope with the same name.

lookupLocally

public java.lang.Object lookupLocally(java.lang.String symbol)
Get the local value for the specified unqualified symbol.

Parameters:
symbol - The unqualified symbol.
Returns:
The corresponding value or null if there is no local definition.

define

public void define(java.lang.String symbol,
                   java.lang.Object value)
Set the specified symbol's value to the specified value in this scope.

Parameters:
symbol - The unqualified symbol.
value - The value.

addDefinition

public void addDefinition(java.lang.String symbol,
                          java.lang.Object value)
Add the specified value to the specified symbol's values in this scope.

Parameters:
symbol - The unqualified symbol.
value - The value.

undefine

public void undefine(java.lang.String symbol)
Undefine the specified unqualified symbol. If the symbol is defined in this scope, this method removes all its values.

Parameters:
symbol - The unqualified symbol.

qualify

public java.lang.String qualify(java.lang.String symbol)
Qualify the specified unqualified symbol with this scope's name.

Parameters:
symbol - The unqualified symbol.
Returns:
The qualified symbol.

dump

public void dump(Printer printer)
Dump the contents of this scope. This method pretty prints the contents of this scope and all nested scopes with the specified printer. If the printer is registered with a visitor, that visitor is used for formatting any node values.

Parameters:
printer - The printer, which need not be registered with a visitor.


Copyright © 2012. All Rights Reserved.