public class SymbolTable extends Object
HashMap
associating names with their types. This class
also assumes responsibility for determining type information for externally defined names.
The global symbol table also keeps track of package
and import
declarations so that when a name cannot be found otherwise, it is searched for in the imported
packages.
Constructor and Description |
---|
SymbolTable()
Initializes the member variables.
|
SymbolTable(SymbolTable p)
Initializes the member variables.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(SymbolTable s)
Adds a child to this table.
|
void |
addImported(String name)
Adds a name to the list of imported names in the top level table.
|
Class<?> |
classForName(ClassifierName name)
Attempts to locate the named class in the current package and any imported packages.
|
Class<?> |
classForName(Name name)
Attempts to locate the named class in the current package and any imported packages.
|
Class<?> |
classForName(String name)
Attempts to locate the named class in the current package and any imported packages.
|
boolean |
containsKey(ClassifierName key)
Determines whether the specified name has been used as a key in this table or any of its
parents.
|
boolean |
containsKey(Name key)
Determines whether the specified name has been used as a key in this table or any of its
parents.
|
boolean |
containsKey(String key)
Determines whether the specified name has been used as a key in this table or any of its
parents.
|
protected static File |
findFile(String name,
String extension,
String path)
Given the name of a class, which may or may not be fully qualified, this method returns the
absolute path to the file with the same name and the given extension.
|
void |
generateHeader(PrintStream out)
Generates
package and import statements from the names in the
member variable imported . |
Type |
get(ClassifierName name)
Retrieves the type associated with the given name.
|
Type |
get(Name name)
Retrieves the type associated with the given name.
|
Type |
get(String name)
Retrieves the type associated with the given name.
|
String |
getPackage()
Gets the package name.
|
SymbolTable |
getParent()
Retrieves the parent of this table.
|
String[] |
getSymbols()
Returns the names of the symbols in this (local) table.
|
int |
importedSize()
Returns the size of the list of imported items.
|
boolean |
localContainsKey(ClassifierName key)
Determines whether the specified name has been used as a key in this table.
|
boolean |
localContainsKey(Name key)
Determines whether the specified name has been used as a key in this table.
|
boolean |
localContainsKey(String key)
Determines whether the specified name has been used as a key in this table.
|
void |
print()
Prints this table and all its children recursively to
STDOUT . |
void |
print(String indent)
Prints this table and all its children recursively to
STDOUT . |
Type |
put(Argument a)
Adds a new entry to the table.
|
Type |
put(ClassifierName name,
Type type)
Adds a new entry to the table.
|
Type |
put(Name name,
Type type)
Adds a new entry to the table.
|
Type |
put(String name,
Type type)
Adds a new entry to the table.
|
void |
setPackage(String name)
Sets the package name in the top level table.
|
public SymbolTable()
public SymbolTable(SymbolTable p)
p
- The parent of this table.protected static File findFile(String name, String extension, String path)
name
- The name of the class.extension
- The extension of the file to search for.path
- Paths in which to search for name.extension.null
if it can't be located.public SymbolTable getParent()
public void addChild(SymbolTable s)
s
- The child to add.public Type put(Argument a)
a
- An argument containing the name its associated type.null
if no type
was previously associated with it.public Type put(ClassifierName name, Type type)
name
- The name to add to the table.type
- The type to associate with the given name.null
if no type
was previously associated with it.public Type put(Name name, Type type)
name
- The name to add to the table.type
- The type to associate with the given name.null
if no type
was previously associated with it.public Type put(String name, Type type)
name
- The name to add to the table.type
- The type to associate with the given name.null
if no type
was previously associated with it.public Type get(ClassifierName name)
name
- The name to retrieve type information for.null
if no type information
could be found.public Type get(Name name)
name
- The name to retrieve type information for.null
if no type information
could be found.public Type get(String name)
name
- The name to retrieve type information for.null
if no type information
could be found.public Class<?> classForName(ClassifierName name)
null
is returned.name
- The name of the class to search for.Class
object representing that class.public Class<?> classForName(String name)
null
is returned.name
- The name of the class to search for.Class
object representing that class.public Class<?> classForName(Name name)
null
is returned.name
- The name of the class to search for.Class
object representing that class.public boolean containsKey(ClassifierName key)
key
- The name.true
iff key
is already a key in this table or any of its
parents.public boolean containsKey(Name key)
key
- The name.true
iff key
is already a key in this table or any of its
parents.public boolean containsKey(String key)
key
- The name.true
iff key
is already a key in this table or any of its
parents.public boolean localContainsKey(ClassifierName key)
key
- The name.true
iff key
is already a key in this table.public boolean localContainsKey(Name key)
key
- The name.true
iff key
is already a key in this table.public boolean localContainsKey(String key)
key
- The name.true
iff key
is already a key in this table.public void addImported(String name)
name
- The name of a new imported package.public int importedSize()
public void setPackage(String name)
name
- The package name.public String getPackage()
public void generateHeader(PrintStream out)
package
and import
statements from the names in the
member variable imported
.out
- The stream to write to.public String[] getSymbols()
public void print()
STDOUT
.public void print(String indent)
STDOUT
.indent
- The level of indentation.Copyright © 2016. All rights reserved.