gov.llnl.babel.symbols
Class SymbolTable

java.lang.Object
  extended by gov.llnl.babel.symbols.SymbolTable
All Implemented Interfaces:
SymbolResolver

public class SymbolTable
extends java.lang.Object
implements SymbolResolver

SymbolTable is a singleton class that represents the locally cached SIDL symbols used during the parse of a SIDL file or XML type descriptions. Only one version of a particular symbol may exist in the table, although different versions may exist in the resolver search path. A symbol may not be added to the table if it already exists in the table. A symbol may not be added to the table if already exists in the SymbolResolver search path with the same version. The symbol table keeps a list of modified symbols that must be written to a database at the end of the parsing.


Constructor Summary
SymbolTable()
          Create a new instance of a symbol table.
 
Method Summary
 void addSymbolResolver(SymbolResolver resolver)
          Add a new symbol resolver to the end of the list of current resolvers.
 boolean conflictingSymbols(SymbolID s1, SymbolID s2)
           
 void freezeAll()
           
 java.util.Set generateDependencies(java.util.Set symbols)
          Generate dependencies for the symbols in the input Set.
 java.util.Set getModifiedSymbolNames()
          Return the set of symbol names in the symbol table that are new or modified.
 java.util.Set getSymbolNames()
          Return the set of symbol names in the symbol table.
 java.util.Map getTable()
          Return the current symbol table as a Map.
 Symbol lookupSymbol(java.lang.String fqn)
          Look up a symbol in the symbol table based on the fully qualified name.
 Symbol lookupSymbol(SymbolID id)
          Look up a symbol in the symbol table based on the fully qualified name and the version number.
 void markSymbolAsModified(SymbolID id)
          Mark a symbol in the symbol table as modified.
 void putSymbol(Symbol symbol)
          Add a new symbol to the symbol table.
 void removeSymbolResolver(SymbolResolver resolver)
           
 void resolveAllParents()
          Resolve all external symbol references for all parents of symbols in the symbol table.
 void resolveAllReferences()
          Resolve all external symbol references for all symbols in the symbol table.
 Symbol resolveSymbol(java.lang.String fqn)
          Resolve the specified symbol by fully qualified name and cache the symbol in the symbol table.
 Symbol resolveSymbol(SymbolID id)
          Resolve the specified symbol by fully qualified name and version number and cache the symbol in the symbol table.
 void setInputFromSIDL()
           
 void setTargetIsXML(boolean value)
           
 void validateContracts()
          Verify that any and all contracts that can be checked at this time are valid.
 void verifyReferences()
          Verify that all references in the table have been satisfied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
Create a new instance of a symbol table. Although singleton classes do not typically define a public constructor, this implementation does so to support multiple symbol tables in the same application. Most implementations, however, will not directly create a symbol table through the constructor and will instead use the one available in the Context.

Method Detail

getTable

public java.util.Map getTable()
Return the current symbol table as a Map. The keys for the hash table are of type SymbolID and the values are of type Symbol.


getSymbolNames

public java.util.Set getSymbolNames()
Return the set of symbol names in the symbol table. The set contains the keys for the hash table as objects of type SymbolID.


getModifiedSymbolNames

public java.util.Set getModifiedSymbolNames()
Return the set of symbol names in the symbol table that are new or modified. The set contains the symbol names as objects of type SymbolID.


markSymbolAsModified

public void markSymbolAsModified(SymbolID id)
Mark a symbol in the symbol table as modified. If the specified symbol identifier does not exist in the symbol table, then this routine does nothing.


lookupSymbol

public Symbol lookupSymbol(java.lang.String fqn)
Look up a symbol in the symbol table based on the fully qualified name. If the symbol does not exist in the symbol table, then null is returned.

Specified by:
lookupSymbol in interface SymbolResolver

lookupSymbol

public Symbol lookupSymbol(SymbolID id)
Look up a symbol in the symbol table based on the fully qualified name and the version number. If the symbol does not exist in the table with the same version number, then null is returned.

Specified by:
lookupSymbol in interface SymbolResolver

addSymbolResolver

public void addSymbolResolver(SymbolResolver resolver)
Add a new symbol resolver to the end of the list of current resolvers. The symbol resolvers will be searched in order of addition to the symbol table resolver list.


removeSymbolResolver

public void removeSymbolResolver(SymbolResolver resolver)

resolveSymbol

public Symbol resolveSymbol(java.lang.String fqn)
Resolve the specified symbol by fully qualified name and cache the symbol in the symbol table. This method will return the symbol with the specified name if it already exists in the symbol table. If the symbol does not exist in the symbol table, then this method will search through the resolver list for the symbol with the most recent version number. If no symbol is found, then null is returned.


resolveSymbol

public Symbol resolveSymbol(SymbolID id)
                     throws SymbolRedefinitionException
Resolve the specified symbol by fully qualified name and version number and cache the symbol in the symbol table. This method will return the symbol with the specified ID if it already exists in the symbol table. If a symbol exists in the symbol table with the same name but different version, then a SymbolRedefinitionException is thrown. If the symbol does not exist in the symbol table, then this method will search through the resolver list for the symbol with the matching version number. If no symbol is found, then null is returned.

Throws:
SymbolRedefinitionException

putSymbol

public void putSymbol(Symbol symbol)
               throws SymbolRedefinitionException
Add a new symbol to the symbol table. This method will throw a SymbolRedefinitionException if the symbol already exists in the symbol table with the same name or if the symbol exists in the resolver search path with the same name and version. This symbol is also placed on the new or modified symbol list.

Throws:
SymbolRedefinitionException

generateDependencies

public java.util.Set generateDependencies(java.util.Set symbols)
                                   throws SymbolNotFoundException,
                                          SymbolRedefinitionException
Generate dependencies for the symbols in the input Set. The input set contains a set of SymbolID symbol names. All dependencies will be loaded into the symbol table and their SymbolID names will be returned in the Set return argument. If the input argument is null or if there are no dependencies, then the return argument will be null.

Throws:
SymbolNotFoundException
SymbolRedefinitionException

resolveAllReferences

public void resolveAllReferences()
                          throws SymbolNotFoundException,
                                 SymbolRedefinitionException
Resolve all external symbol references for all symbols in the symbol table. If a symbol reference is not found, then an exception of the type SymbolNotFoundException is thrown. If a symbol reference redefines a symbol with a different version number, then a SymbolRedefinitionException is thrown.

Throws:
SymbolNotFoundException
SymbolRedefinitionException

resolveAllParents

public void resolveAllParents()
                       throws SymbolNotFoundException
Resolve all external symbol references for all parents of symbols in the symbol table.

Throws:
SymbolNotFoundException

validateContracts

public void validateContracts()
                       throws AssertionException,
                              CodeGenerationException
Verify that any and all contracts that can be checked at this time are valid.

Throws:
AssertionException
CodeGenerationException

verifyReferences

public void verifyReferences()
                      throws SymbolNotFoundException
Verify that all references in the table have been satisfied. If a symbol reference is not defined, then a symbol not found exception is thrown.

Throws:
SymbolNotFoundException

conflictingSymbols

public boolean conflictingSymbols(SymbolID s1,
                                  SymbolID s2)

setInputFromSIDL

public void setInputFromSIDL()

setTargetIsXML

public void setTargetIsXML(boolean value)

freezeAll

public void freezeAll()