jparse
Class SymbolTable

java.lang.Object
  extended byjparse.SymbolTable

public final class SymbolTable
extends Object

A mapping from names to definitions of those names (AST nodes)

Author:
Jerry James

Field Summary
private  HashMap labelMap
          The mapping from label names to AST nodes representing the labeled statement
private  MethAST[] methods
          An alphabetical list of methods (methods with the same name are in no particular order)
(package private)  SymbolTable parent
          The symbol table for the enclosing scope
private  TypeAST type
          The type (class or interface) in which the symbols in this table are defined
private  HashMap varMap
          The mapping from variable names to AST nodes representing the definitions of those variables
 
Constructor Summary
SymbolTable()
          Create a new SymbolTable
 
Method Summary
 void addLabel(String label, JavaAST stmt)
          Add a labeled statement to the symbol table
 void addMeth(MethAST meth)
          Add a method symbol to the symbol table
 void addVar(VarAST ast)
          Add a variable symbol to the symbol table
 StatementAST getLabel(String label)
          Find a labeled statement in the symbol table
 Method getMeth(String name, Type[] params, Type caller)
          Find a method symbol in the symbol table
 Method[] getMeths()
          Retrieve all methods defined by this symbol table
 Method[] getMeths(String name, Type[] params, Type caller)
          Retrieve all matching methods
 VarAST getVar(String name)
          Find a variable symbol in the symbol table
(package private)  void setEnclosingType(TypeAST enclosingType)
          Set the enclosing type for this symbol table
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

final SymbolTable parent
The symbol table for the enclosing scope


type

private TypeAST type
The type (class or interface) in which the symbols in this table are defined


varMap

private final HashMap varMap
The mapping from variable names to AST nodes representing the definitions of those variables


methods

private MethAST[] methods
An alphabetical list of methods (methods with the same name are in no particular order)


labelMap

private final HashMap labelMap
The mapping from label names to AST nodes representing the labeled statement

Constructor Detail

SymbolTable

public SymbolTable()
Create a new SymbolTable

Method Detail

setEnclosingType

void setEnclosingType(TypeAST enclosingType)
Set the enclosing type for this symbol table

Parameters:
enclosingType - the enclosing type for this symbol table

addVar

public void addVar(VarAST ast)
Add a variable symbol to the symbol table

Parameters:
ast - the AST node defining the variable

getVar

public VarAST getVar(String name)
Find a variable symbol in the symbol table

Parameters:
name - the name of the variable to look up
Returns:
the AST defining name, or null if it cannot be found

addMeth

public void addMeth(MethAST meth)
Add a method symbol to the symbol table

Parameters:
meth - the AST node describing the method

getMeth

public Method getMeth(String name,
                      Type[] params,
                      Type caller)
Find a method symbol in the symbol table

Parameters:
name - the name of the method to look up
params - the types of the parameters to the method
caller - the type of the caller
Returns:
the most closely matching method, or null if one could not be found

getMeths

public Method[] getMeths(String name,
                         Type[] params,
                         Type caller)
Retrieve all matching methods

Parameters:
name - the name of the method to look up
params - the types of the parameters to the method
caller - the type of the caller
Returns:
an array containing all matching methods. If no matching methods are found, an array of length 0 will be returned.

getMeths

public Method[] getMeths()
Retrieve all methods defined by this symbol table

Returns:
an array of methods. If no methods are defined in this symbol table, an array of length 0 is returned.

addLabel

public void addLabel(String label,
                     JavaAST stmt)
Add a labeled statement to the symbol table

Parameters:
label - the label on the statement
stmt - the AST node for the labeled statement

getLabel

public StatementAST getLabel(String label)
Find a labeled statement in the symbol table

Parameters:
label - the label to look up
Returns:
the AST for the statement with label label, or null if it cannot be found

toString

public String toString()