jreversepro.runtime
Class JSymbolTable

java.lang.Object
  extended by jreversepro.runtime.JSymbolTable
All Implemented Interfaces:
KeyWords

public class JSymbolTable
extends java.lang.Object
implements KeyWords

JSymbolTable - Symbol Table of a method containing local variables only.

Author:
Karthik Kumar

Field Summary
static int ARG_INDEX
          Index of the argument into the symbol table.
 
Fields inherited from interface jreversepro.common.KeyWords
ANY, BOOLEAN, BREAK, BYTE, CASE, CHAR, CLASS, CLASS_STRING, CLINIT, CLOSE_BRACKET, COND_AND, COND_NOT, COND_OR, CONTINUE, DEFAULT, DEFAULT_PACKAGE, DOUBLE, EQUALTO, FALSE, FLOAT, FOREIGN_CLASS, FOREIGN_OBJ, GOTO, INIT, INSTANCEOF, INT, INTERFACE, JVM_BOOLEAN, JVM_CHAR, JVM_VOID, LANG_OBJECT, LENGTH, LONG, NEW, NULL, OPEN_BRACKET, OPR_EQ, OPR_GE, OPR_GT, OPR_LE, OPR_LT, OPR_NE, OPR_NOT, REFERENCE, RET_ADDR, RETURN, SHORT, SPACE, STATIC, SUPER, SWITCH, THIS, THISCLASS, THROW, TRUE, VOID
 
Constructor Summary
JSymbolTable(JMethod rhsMethod, JImport imports)
           
 
Method Summary
 void addReference(int aVarIndex, java.lang.String aDatatype, int aIndex)
          This method primarily keeps track of the last line that references the variable represented by aVarIndex and the datatype aDataType.
 void assignDataType(int aVarIndex, java.lang.String aDatatype, int aVarStore, boolean aDeclared)
          Adds a new datatype to the symboltable dynamically .
 java.lang.String declare(int aVarIndex, int aInsIndex)
          Declares a variable represented by aVarIndex and aInsIndex and returns its datatype.
 java.util.List<java.lang.String> defineVariable(int endOfBranch)
          Given the endOfBranch of a branch, this method returns a List of strings, of the form They represent the variables that are to be declared before we enter into the branch whose endOfBranch is given as argument.
 java.lang.String getDataType(int aVarIndex, int aInsIndex)
           
static java.util.List<java.lang.String> getKeyWordsList()
           
 int getMaxSymbols()
           
 java.lang.String getName(int aVarIndex, int aInsIndex)
           
 java.lang.String toString()
           
 void touchVariable(java.lang.String aVarName, java.lang.String aNewType)
          Touch variable is basically assigning a new datatype in place of the old one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ARG_INDEX

public static final int ARG_INDEX
Index of the argument into the symbol table.

See Also:
Constant Field Values
Constructor Detail

JSymbolTable

public JSymbolTable(JMethod rhsMethod,
                    JImport imports)
Parameters:
rhsMethod - Method for which this symbol table is generated and used.
imports - ImportedClasses by this class.
Method Detail

getMaxSymbols

public int getMaxSymbols()
Returns:
Get the maximum number of symbols available in the scope of the current method.

assignDataType

public void assignDataType(int aVarIndex,
                           java.lang.String aDatatype,
                           int aVarStore,
                           boolean aDeclared)
Adds a new datatype to the symboltable dynamically . Parameters required are the

Parameters:
aVarIndex - variable index ,
aDatatype - Datatype
aVarStore - variable store index.
aDeclared - If variable is declared.

addReference

public void addReference(int aVarIndex,
                         java.lang.String aDatatype,
                         int aIndex)
This method primarily keeps track of the last line that references the variable represented by aVarIndex and the datatype aDataType. Please note that this referencing is essential to define the variables correctly, neither too early, nor too late. Also this is not necessary for arguments, but more necessary for localvariables whose declarations are inside the method code block.

Parameters:
aVarIndex - variable index ,
aDatatype - Datatype
aIndex - Refernced index.

defineVariable

public java.util.List<java.lang.String> defineVariable(int endOfBranch)
Given the endOfBranch of a branch, this method returns a List of strings, of the form They represent the variables that are to be declared before we enter into the branch whose endOfBranch is given as argument.

Parameters:
endOfBranch - PC when branch ends.
Returns:
Returns a List containing Strings in the above mentioned format.

touchVariable

public void touchVariable(java.lang.String aVarName,
                          java.lang.String aNewType)
Touch variable is basically assigning a new datatype in place of the old one. This arises especially in the following case: Say, we see List list = new Vector(); list.add("sz"); On seeing new Vector() we conclude the var type is of type Vector. On seeing list.add("sz") we 'touch' it saying that the type is now List and not Vector.

Parameters:
aVarName - Variable name
aNewType - New Datatype

getName

public java.lang.String getName(int aVarIndex,
                                int aInsIndex)
                         throws RevEngineException
Parameters:
aVarIndex - Index of local variable into symbol table.
aInsIndex - Index of instruction into bytecode array of method.
Returns:
Returns a name of the variable given the variable index and the instruction index.
Throws:
RevEngineException - Thrown in case of any problem.

getDataType

public java.lang.String getDataType(int aVarIndex,
                                    int aInsIndex)
                             throws RevEngineException
Parameters:
aVarIndex - Index of local variable into symbol table.
aInsIndex - Index of instruction into bytecode array of method.
Returns:
Returns a dataType of the variable given the variable index and the instruction index.
Throws:
RevEngineException - Thrown in case of any problem.

declare

public final java.lang.String declare(int aVarIndex,
                                      int aInsIndex)
                               throws RevEngineException
Declares a variable represented by aVarIndex and aInsIndex and returns its datatype.

Parameters:
aVarIndex - Index of local variable into symbol table.
aInsIndex - Index of instruction into bytecode array of method.
Returns:
Returns a String containing type.
Throws:
RevEngineException - Thrown in case of any problem.

getKeyWordsList

public static java.util.List<java.lang.String> getKeyWordsList()
Returns:
Returns a list containing the keywords of the java language. All the individual members are String.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns Stringified form of this class


Submit Feedback to akkumar@users.sourceforge.net