edu.ksu.cis.projects.bogor.symboltable
Class SymbolTable

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.symboltable.SymbolTable
All Implemented Interfaces:
Disposable, Serializable

public final class SymbolTable
extends Object
implements Disposable, Serializable

This class is used as a symbol table for a system.

Version:
CVS $Revision: 1.38 $ $Date: 2005/06/09 00:22:02 $
Author:
Robby , Matt Hoosier
See Also:
Serialized Form

Constructor Summary
SymbolTable(String filename, System system)
          Default constructor
 
Method Summary
 void addArrayField(String name, Type type)
          Adds an array field.
 void dispose()
          Removes references to filename, mainThreadName, topRecordName, and clears all tables.
 void finishTypeCheckingDefinitions()
          Sets the symbol table for finishing type checking definitions.
 void finishTypeCheckingFSMHeaders()
          Sets the symbol table for finishing type checking globals.
 void finishTypeCheckingFSMs()
          Sets the symbol table for finishing type checking FSMs.
 void finishTypeCheckingGlobals()
          Sets the symbol table for finishing type checking globals.
 int genLocationDesc()
          Generate a new location descriptor.
 Collection<FileMessage> getAllErrors()
          Gets all the error messages (including FSM errors).
 int getArrayFieldCount()
          Gets the number of array fields.
 int getArrayFieldIndex(String fieldName)
          Gets the index of an array field.
 String getArrayFieldName(int fieldIndex)
          Gets the name of an array field.
 Iterator<String> getArrayFieldNameIterator()
          Gets array field name iterator.
 Type getArrayFieldType(int fieldIndex)
          Gets the type of an array field.
 Type getArrayFieldType(String fieldName)
          Gets the type of an array field.
 Map<ASTType,Type> getASTTypeTypeTable()
          Gets the ast.ASTType to type.Type mapping.
 Map<String,Map<String,Object>> getConstantTable()
          Gets the constant identifier (String) to its constant mapping (Map<String, Integer/Boolean>).
 Map<String,Map<String,Type>> getConstantTypeTable()
          Gets the mapping of a constant set definition's identifier to a table relating each entry in the set to its declared type.
 SystemMember getDeclarationForIdentifier(String id)
           
 Map<String,EnumType> getEnumTable()
          Gets the enum identifier (String) to its type (EnumType).
 boolean getError()
          Gets the error flag.
 List<FileMessage> getErrors()
          Gets the error messages (excluding FSM errors).
 Map<String,Extension> getExpActionExtDefTable()
          Gets the exp or action extension qualified identifier (String) to its declaration (ExpExtension/ActionExtension).
 Map<String,ExtSymbolTable> getExpActionExtTable()
          Gets the exp or action extension qualified identifier (String) to its symbol table (ExtSymbolTable).
 Map<String,ExtensionDefinition> getExtensionDefTable()
          Gets the extension id (String) to its declaration (ExtensionDefinition) mapping.
 Map<String,Field> getFieldDefTable()
          Gets the field qualified name (String) to its definition (Field) mapping.
 String getFilename()
          Gets the filename of the system.
 Map<String,ArrayList<Node>> getForwardRecordTable()
          Gets the record name (String) to its forward references (ArrayList<Node>) mapping.
 FSMSymbolTable getFSMSymbolTable(int locDesc)
          Finds the symbol table of the FSM which owns the specified thread control point.
 Map<String,FSM> getFunctionDefTable()
          Gets the function identifier (String) to its definition (FSM) mapping.
 Map<String,FSMSymbolTable> getFunctionTable()
          Gets the function identifier (String) to its symbol table (FSMSymbolTable) mapping.
 Map<String,Type> getGlobalFunTable()
          Gets the global/fun identifier (String) to its type (Type) mapping.
 ObjectIntTable<String> getGlobalIndexTable()
          Gets the global identifier (String) to its index (int) mapping.
 BitSet getGlobalTransientFlags()
          Gets the mapping from global index (int) to a flag (boolean) indicating whether the variable is declared transient.
 ArrayList<Type> getGlobalTypes()
          Gets the global types (ArrayList<Type>).
 Map<String,SystemMember> getIdentifierDefTable()
          Gets the constant/enum/global identifier (String) to its declaration (ConstantDefinition/EnumDefinition/Global/Fun) mapping.
static String getIdentifierDefTableNamespaces()
          Gets a textual names of all the constructs whose namespaces are managed by the table retrievable from getIdentifierDefTable().
 Location getLocation(int locDesc)
           
 String[] getLocDescFSMIdTable()
          Gets the location desc (int) to its FSM id (String) mapping.
 String[] getLocDescLocIdTable()
          Gets the location desc (int) to its loc id (String) mapping.
 String getMainThreadName()
          Gets the main thread name.
 Map<String,Map<String,String>> getNonEnumVirtualTable()
          Gets the virtual table identifier (String) to function mapping (Map<String, String>) mapping.
 ObjectIntTable<String> getQLocIdLocDescTable()
          Gets the qualified loc id (String) to its location desc (int) mapping.
 Map<String,RecordDefinition> getRecordDefTable()
          Gets the record identifier (String) to its definition (RecordDefinition) mapping.
 Map<String,RecordType> getRecordTable()
          Gets the record identifier (String) to its type (RecordType) mapping.
 Map<String,Set<String>> getSubRecordClosureTable()
          Gets the record (String) to sub-records (Set<String>) mapping.
 Map<String,Set<String>> getSubRecordTable()
          Gets the record (String) to sub-record (Set<String>) mapping.
 Map<String,Set<String>> getSuperRecordClosureTable()
          Gets the record (String) to super-records (Set<String>) mapping.
 Map<String,Set<String>> getSuperRecordTable()
          Gets the record (String) to super-record (String) mapping.
 System getSystem()
          Gets the AST of the system.
 String getSystemMemberType(SystemMember mem)
           
 String getTopRecordName()
          Gets the name of the top record.
 Transformation getTransformation(int locDesc, int transformationIndex)
           
 Map<String,Type> getTypealiasTable()
          Gets the typealias identifier (String) to its type (Type).
 Map<String,TypeExtension> getTypeExtensionDefTable()
          Gets the type extension qualified id (String) to its declaration (TypeExtension) mapping.
 Map<String,Type> getTypeExtensionTable()
          Gets the type extension qualified id (String) to its declaration (TypeExtensionType or PrimitiveTypeExtensionType) mapping.
 TypeFactory getTypeFactory()
          Gets the type factory.
 IntIntTable getTypeIdCreatedTypeIdTable()
          Gets the type id (int) to its created type id (int) mapping.
 IntObjectTable<Type> getTypeIdTypeTable()
          Gets the type id (int) to its type (Type) mapping.
 Map<String,VirtualTableDefinition> getVirtualDefTable()
          Gets the virtual table identifier (String) to its definition (VirtualTableDefinition).
 Map<String,ArrayList<Type>> getVirtualParamTable()
          Gets the virtual table identifier (String) to its parameter types (ArrayList<Type>), excluding the receiver type.
 Map<String,Type> getVirtualReturnTable()
          Gets the virtual table identifier (String) to its return type (Type).
 Map<String,IntObjectTable<String>> getVirtualTable()
          Gets the virtual table identifier (String) to function mapping (Map<Integer, String>) mapping.
 List<FileMessage> getWarnings()
          Gets the warning messages.
 boolean hasArrayField(String fieldName)
          Determines whether a field name is declared in the array.
 void initTypeCheckingDefinitions()
          Sets the symbol table for type checking definitions.
 void initTypeCheckingFSMHeaders()
          Sets the symbol table for type checking FSM headers.
 void initTypeCheckingFSMs()
          Sets the symbol table for type checking FSMs.
 void initTypeCheckingGlobals()
          Sets the symbol table for type checking globals.
 boolean isIdentifierDeclared(String id)
           
 boolean isSubRecord(String recordName1, String recordName2)
          Determines if a record is a sub-record of another record.
 void setASTTypeTypeTable(Map<ASTType,Type> newTypeTypeTable)
          Sets the ast.ASTType to type.Type mapping.
 void setError(boolean newError)
          Sets the error flag
 void setMainThreadName(String newMainThreadName)
          Sets the main thread name.
 void setTopRecordName(String newTopRecordName)
          Sets the top record name.
 String toString()
          Returns the string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable(String filename,
                   System system)
Default constructor

Parameters:
filename - The filename of the BIR system.
system - The AST of the BIR system. Must be non-null.
Method Detail

setASTTypeTypeTable

public void setASTTypeTypeTable(Map<ASTType,Type> newTypeTypeTable)
Sets the ast.ASTType to type.Type mapping.

Parameters:
newTypeTypeTable - The new ast.ASTType to type.Type mapping. Must be non-null. This map is treated as read-only; a snapshot is taken to populate an encapsulated mapping inside this SymbolTable>

getASTTypeTypeTable

public Map<ASTType,Type> getASTTypeTypeTable()
Gets the ast.ASTType to type.Type mapping.

Returns:
The ast.ASTType to type.Type mapping. Non-null (stage >= 8).

getAllErrors

public Collection<FileMessage> getAllErrors()
Gets all the error messages (including FSM errors).

Returns:
The util.FileMessage error messages (including FSM errors). Non-null (stage >= 0).

getArrayFieldCount

public int getArrayFieldCount()
Gets the number of array fields.

Returns:
The number of fields. Greater than or equal to zero.

getArrayFieldIndex

public int getArrayFieldIndex(String fieldName)
Gets the index of an array field.

Parameters:
fieldName - The field name. Must be non-null. Must be a field of this array.
Returns:
The index of the field.

getArrayFieldName

public String getArrayFieldName(int fieldIndex)
Gets the name of an array field.

Parameters:
fieldIndex - The field index. Must be non-null. Must be a field of this array.
Returns:
The name of the field.

getArrayFieldNameIterator

public Iterator<String> getArrayFieldNameIterator()
Gets array field name iterator.

Returns:
The field name iterator. Non-null.

getArrayFieldType

public Type getArrayFieldType(String fieldName)
Gets the type of an array field.

Parameters:
fieldName - The field name. Must be non-null. Must be a field of this array.
Returns:
The type of the field.

getArrayFieldType

public Type getArrayFieldType(int fieldIndex)
Gets the type of an array field.

Parameters:
fieldIndex - The field name. Must be non-null. Must be a field of this array.
Returns:
The type of the field.

getConstantTable

public Map<String,Map<String,Object>> getConstantTable()
Gets the constant identifier (String) to its constant mapping (Map<String, Integer/Boolean>).

Returns:
The constant identifier (String) to its constant mapping (Map<String, Integer/Boolean>). Non-null (stage >= 1).

getConstantTypeTable

public Map<String,Map<String,Type>> getConstantTypeTable()
Gets the mapping of a constant set definition's identifier to a table relating each entry in the set to its declared type.

Returns:
The constant set identifier (String) to individual constant-to-type mapping. Non-null (stage >= 1).

getEnumTable

public Map<String,EnumType> getEnumTable()
Gets the enum identifier (String) to its type (EnumType).

Returns:
The enum identifier (String) to its type (EnumType). Non-null (stage >= 1).

setError

public void setError(boolean newError)
Sets the error flag

Parameters:
newError - The new error flag.

getError

public boolean getError()
Gets the error flag.

Returns:
True, if an error has been occurred. False, otherwise.

getErrors

public List<FileMessage> getErrors()
Gets the error messages (excluding FSM errors).

Returns:
The util.FileMessage error messages (excluding FSM errors). Non-null (stage >= 0).

getExpActionExtDefTable

public Map<String,Extension> getExpActionExtDefTable()
Gets the exp or action extension qualified identifier (String) to its declaration (ExpExtension/ActionExtension).

Returns:
The exp or action extension qualified identifier (String) to its declaration (ExpExtension/ActionExtension). Non-null (stage >= 1).

getExpActionExtTable

public Map<String,ExtSymbolTable> getExpActionExtTable()
Gets the exp or action extension qualified identifier (String) to its symbol table (ExtSymbolTable).

Returns:
The exp or action extension qualified identifier (String) to its symbol table (ExtSymbolTable). Non-null (stage >= 1).

getExtensionDefTable

public Map<String,ExtensionDefinition> getExtensionDefTable()
Gets the extension id (String) to its declaration (ExtensionDefinition) mapping.

Returns:
The extension id (String) to its declaration (ExtensionDefinition) mapping. Non-null (stage >= 1).

getFSMSymbolTable

public FSMSymbolTable getFSMSymbolTable(int locDesc)
Finds the symbol table of the FSM which owns the specified thread control point.

Parameters:
locDesc - Globally unique descriptor of a thread control point.
Returns:
Symbol table of the owning FSM, or null if no such control point exists.

getFieldDefTable

public Map<String,Field> getFieldDefTable()
Gets the field qualified name (String) to its definition (Field) mapping.

Returns:
The field qualified name (String) to its definition (Field) mapping. Non-null (stage >= 1).

getFilename

public String getFilename()
Gets the filename of the system.

Returns:
The filename of the system.

getForwardRecordTable

public Map<String,ArrayList<Node>> getForwardRecordTable()
Gets the record name (String) to its forward references (ArrayList<Node>) mapping.

Returns:
The record name (String) to its forward references (ArrayList<Node>) mapping.

getFunctionDefTable

public Map<String,FSM> getFunctionDefTable()
Gets the function identifier (String) to its definition (FSM) mapping.

Returns:
The function identifier (String) to its definition (FSM) mapping. Non-null (stage >= 5).

getFunctionTable

public Map<String,FSMSymbolTable> getFunctionTable()
Gets the function identifier (String) to its symbol table (FSMSymbolTable) mapping.

Returns:
The function identifier (String) to its symbol table (FSMSymbolTable) mapping. Non-null (stage >= 5).

getGlobalFunTable

public Map<String,Type> getGlobalFunTable()
Gets the global/fun identifier (String) to its type (Type) mapping.

Returns:
The global/fun identifier (String) to its type (Type) mapping. Non-null (stage >= 3).

getGlobalIndexTable

public ObjectIntTable<String> getGlobalIndexTable()
Gets the global identifier (String) to its index (int) mapping.

Returns:
The global identifier (String) to its index (int) mapping. Non-null (stage >= 3).

getGlobalTransientFlags

public BitSet getGlobalTransientFlags()
Gets the mapping from global index (int) to a flag (boolean) indicating whether the variable is declared transient.

Returns:
A BitSet in which get(i) tells whether global variable at index i is transient. Non-null (stage >= 3).

getGlobalTypes

public ArrayList<Type> getGlobalTypes()
Gets the global types (ArrayList<Type>).

Returns:
The global types (ArrayList<Type>). Non-null (stage >= 3).

getIdentifierDefTable

public Map<String,SystemMember> getIdentifierDefTable()
Gets the constant/enum/global identifier (String) to its declaration (ConstantDefinition/EnumDefinition/Global/Fun) mapping.

Returns:
The constant/enum/global identifier (String) to its declaration (ConstantDefinition/EnumDefinition/Global/Fun) mapping. Non-null (stage >= 1).

getIdentifierDefTableNamespaces

public static String getIdentifierDefTableNamespaces()
Gets a textual names of all the constructs whose namespaces are managed by the table retrievable from getIdentifierDefTable().


getLocDescFSMIdTable

public String[] getLocDescFSMIdTable()
Gets the location desc (int) to its FSM id (String) mapping.

Returns:
The location desc (int) to its FSM id (String) mapping. Non-null (stage >= 8).

getLocDescLocIdTable

public String[] getLocDescLocIdTable()
Gets the location desc (int) to its loc id (String) mapping.

Returns:
The location desc (int) to its loc id (String) mapping. Non-null (stage >= 8).

getLocation

public Location getLocation(int locDesc)

setMainThreadName

public void setMainThreadName(String newMainThreadName)
Sets the main thread name.

Parameters:
newMainThreadName - Must be non-null.

getMainThreadName

public String getMainThreadName()
Gets the main thread name.

Returns:
The main thread name. Non-null (stage >= 6).

getQLocIdLocDescTable

public ObjectIntTable<String> getQLocIdLocDescTable()
Gets the qualified loc id (String) to its location desc (int) mapping.

Returns:
The qualified loc id (String) to its location desc (int) mapping. Non-null (state >= 8).

getRecordDefTable

public Map<String,RecordDefinition> getRecordDefTable()
Gets the record identifier (String) to its definition (RecordDefinition) mapping.

Returns:
The record identifier (String) to its definition (RecordDefinition) mapping. Non-null (stage >= 1).

getRecordTable

public Map<String,RecordType> getRecordTable()
Gets the record identifier (String) to its type (RecordType) mapping.

Returns:
The record identifier (String) to type (RecordType) mapping. Non-null (stage >= 1).

isSubRecord

public boolean isSubRecord(String recordName1,
                           String recordName2)
Determines if a record is a sub-record of another record.

Parameters:
recordName1 - The name of the first record. Non-null.
recordName2 - The name of the second record. Non-null.
Returns:
True, if the first record is a sub-record of the second record. False, otherwise.

getSubRecordClosureTable

public Map<String,Set<String>> getSubRecordClosureTable()
Gets the record (String) to sub-records (Set<String>) mapping.

Returns:
The record (String) to sub-records (Set<String>) mapping. Non-null (stage >= 2).

getSubRecordTable

public Map<String,Set<String>> getSubRecordTable()
Gets the record (String) to sub-record (Set<String>) mapping.

Returns:
The record (String) to sub-record (Set<String>) mapping. Non-null (stage >= 2).

getSuperRecordClosureTable

public Map<String,Set<String>> getSuperRecordClosureTable()
Gets the record (String) to super-records (Set<String>) mapping.

Returns:
The record (String) to super-records (Set<String>) mapping. Non-null (stage >= 2).

getSuperRecordTable

public Map<String,Set<String>> getSuperRecordTable()
Gets the record (String) to super-record (String) mapping.

Returns:
The record (String) to super-record (String) mapping. Non-null (stage >= 1).

getSystem

public System getSystem()
Gets the AST of the system.

Returns:
The AST of the system. Non-null.

setTopRecordName

public void setTopRecordName(String newTopRecordName)
Sets the top record name.

Parameters:
newTopRecordName - Must be non-null.

getTopRecordName

public String getTopRecordName()
Gets the name of the top record.

Returns:
The name of the top record.

getTransformation

public Transformation getTransformation(int locDesc,
                                        int transformationIndex)

getTypeExtensionDefTable

public Map<String,TypeExtension> getTypeExtensionDefTable()
Gets the type extension qualified id (String) to its declaration (TypeExtension) mapping.

Returns:
The type extension qualified id (String) to its declaration (TypeExtension) mapping. Non-null (stage >= 1).

getTypeExtensionTable

public Map<String,Type> getTypeExtensionTable()
Gets the type extension qualified id (String) to its declaration (TypeExtensionType or PrimitiveTypeExtensionType) mapping.

Returns:
The type extension qualified id (String) to its declaration (TypeExtensionType or PrimitiveTypeExtensionType) mapping (stage >= 1).

getTypeFactory

public TypeFactory getTypeFactory()
Gets the type factory.

Returns:
The type factory. Non-null (stage >= 1).

getTypeIdCreatedTypeIdTable

public IntIntTable getTypeIdCreatedTypeIdTable()
Gets the type id (int) to its created type id (int) mapping.

Returns:
The type id (int) to its created type id (int) mapping. Non-null (stage >= 7).

getTypeIdTypeTable

public IntObjectTable<Type> getTypeIdTypeTable()
Gets the type id (int) to its type (Type) mapping.

Returns:
The type id (int) to its type (Type) mapping. Non-null (stage >= 8).

getTypealiasTable

public Map<String,Type> getTypealiasTable()
Gets the typealias identifier (String) to its type (Type).

Returns:
The enum identifier (String) to its type (Type). Non-null (stage >= 1).

getVirtualDefTable

public Map<String,VirtualTableDefinition> getVirtualDefTable()
Gets the virtual table identifier (String) to its definition (VirtualTableDefinition).

Returns:
The virtual table identifier (String) to its definition (VirtualTableDefinition). Non-null (stage >= 1).

getVirtualParamTable

public Map<String,ArrayList<Type>> getVirtualParamTable()
Gets the virtual table identifier (String) to its parameter types (ArrayList<Type>), excluding the receiver type.

Returns:
The virtual table identifier (String) to its parameter types (ArrayList<Type>), excluding the receiver type. Non-null (stage >= 3)

getVirtualReturnTable

public Map<String,Type> getVirtualReturnTable()
Gets the virtual table identifier (String) to its return type (Type).

Returns:
The virtual table identifier (String) to its return type (Type). Non-null (stage >= 6).

getVirtualTable

public Map<String,IntObjectTable<String>> getVirtualTable()
Gets the virtual table identifier (String) to function mapping (Map<Integer, String>) mapping.

Returns:
The virtual table identifier (String) to function mapping (Map<Integer, String>) mapping. Non-null (stage >= 1).

getNonEnumVirtualTable

public Map<String,Map<String,String>> getNonEnumVirtualTable()
Gets the virtual table identifier (String) to function mapping (Map<String, String>) mapping.

Returns:
The virtual table identifier (String) to function mapping (Map<String, String>) mapping. Non-null (stage >= 1).

getWarnings

public List<FileMessage> getWarnings()
Gets the warning messages.

Returns:
The util.FileMessage warning messages. Non-null (stage >= 0).

addArrayField

public void addArrayField(String name,
                          Type type)
Adds an array field.

Parameters:
name - The name of the field. Must be non-null. The record must not already contain a field named name.
type - The type of the field. Must be non-null. Must not be instance of VoidType or UnknownType.

dispose

public void dispose()
Removes references to filename, mainThreadName, topRecordName, and clears all tables. Once called, avoid using this object.

Specified by:
dispose in interface Disposable

finishTypeCheckingDefinitions

public void finishTypeCheckingDefinitions()
Sets the symbol table for finishing type checking definitions. stage must be one. errors must be empty.

Generates an error if:


finishTypeCheckingFSMHeaders

public void finishTypeCheckingFSMHeaders()
Sets the symbol table for finishing type checking globals. stage must be five. errors must be empty.

Generates an error if:


finishTypeCheckingFSMs

public void finishTypeCheckingFSMs()
Sets the symbol table for finishing type checking FSMs. stage must be seven. errors must be empty.


finishTypeCheckingGlobals

public void finishTypeCheckingGlobals()
Sets the symbol table for finishing type checking globals. stage must be three. errors must be empty.


genLocationDesc

public int genLocationDesc()
Generate a new location descriptor.

Returns:
A new location descriptor.

hasArrayField

public boolean hasArrayField(String fieldName)
Determines whether a field name is declared in the array.

Parameters:
fieldName - The field name. Must be non-null.
Returns:
True, if the field is declared in the array. False, otherwise.

initTypeCheckingDefinitions

public void initTypeCheckingDefinitions()
Sets the symbol table for type checking definitions. stage must be zero.


initTypeCheckingFSMHeaders

public void initTypeCheckingFSMHeaders()
Sets the symbol table for type checking FSM headers. stage must be four. errors must be empty


initTypeCheckingFSMs

public void initTypeCheckingFSMs()
Sets the symbol table for type checking FSMs. stage must be six. errors must be empty


initTypeCheckingGlobals

public void initTypeCheckingGlobals()
Sets the symbol table for type checking globals. stage must be two. errors must be empty


toString

public String toString()
Returns the string representation of this object.

Overrides:
toString in class Object
Returns:
The string representation of this object.

isIdentifierDeclared

public boolean isIdentifierDeclared(String id)

getDeclarationForIdentifier

public SystemMember getDeclarationForIdentifier(String id)

getSystemMemberType

public String getSystemMemberType(SystemMember mem)