jreversepro.runtime
Class JRunTimeContext

java.lang.Object
  extended by jreversepro.runtime.JRunTimeContext
All Implemented Interfaces:
KeyWords, BranchConstants

public class JRunTimeContext
extends java.lang.Object
implements KeyWords, BranchConstants

This contains the RunTime context.

Author:
Karthik Kumar

Field Summary
 
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
 
Fields inherited from interface jreversepro.revengine.BranchConstants
TYPE_BRANCH, TYPE_CASE, TYPE_CATCH, TYPE_CATCH_ANY, TYPE_DO_WHILE, TYPE_ELSE, TYPE_ELSE_IF, TYPE_GOTO, TYPE_IF, TYPE_INVALID, TYPE_JSR, TYPE_RET, TYPE_SWITCH, TYPE_SYNC, TYPE_TRY, TYPE_TRY_ANY, TYPE_WHILE
 
Constructor Summary
JRunTimeContext(JDecompiler decomp, JMethod meth, JRunTimeFrame rtf, JOperandStack jos, JBranchTable branches)
           
 
Method Summary
 void addCode(int sOffset, int eOffset, int fromPos, int toPos)
          Adds a line of code with byteoffset information
 void addCode(int sOffset, int eOffset, int fromPos, int toPos, java.lang.String type)
          Adds a line of code with byteoffset information
 void addTextCode(java.lang.String txt)
          Add text line to output code with indenting.
 void executeInstruction(JInstruction ins)
          Process JVM instruction.
 void getBeginStmt(java.util.List<JBranchEntry> listBranches, int insIndex, JSymbolTable symTable)
           
 void getEndStmt(int insIndex)
          Close current branch block regularly.
 void getFinalBlockStmt()
          After all the processing of the method is over, this code generated the final block statement, if any.
 JBranchEntry getImmediateOuterLoop()
          At any given stage this method returns the reference to while/ do..while/ switch statement that enclosed this, to the outermost reference.
 JOperandStack getOperandStack()
          Get JVM Operand stack.
 void processBreakContinue(int startPc, int targetPc)
           
 void pushControlEntry(JBranchEntry newent)
           
 void setBlockWrittenFlag()
          In case a statement has been identified for writing for the current topmost block then that is set the written flag.
 java.lang.String toString()
           
 void validatePairings(JBranchEntry ent)
          Check correct branch pairings for IF/ELSEIF/ELSE/TRY/CATCH/FINALLY.
 void writeVariableDeclarations(JBranchEntry ent, JSymbolTable symTable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JRunTimeContext

public JRunTimeContext(JDecompiler decomp,
                       JMethod meth,
                       JRunTimeFrame rtf,
                       JOperandStack jos,
                       JBranchTable branches)
Parameters:
meth - Method reference.
decomp - Decompiler reference.
rtf - RuntimeFrame input
jos - OperandStack reference
branches - BranchReference.
Method Detail

getOperandStack

public JOperandStack getOperandStack()
Get JVM Operand stack.

Returns:
Returns Operand Stack.

executeInstruction

public void executeInstruction(JInstruction ins)
                        throws RevEngineException
Process JVM instruction.

Parameters:
ins - Instruction that is to be executed.
Throws:
RevEngineException - thrown in case any problem occurs while executing the instruction.

getFinalBlockStmt

public void getFinalBlockStmt()
After all the processing of the method is over, this code generated the final block statement, if any.


getEndStmt

public void getEndStmt(int insIndex)
                throws RevEngineException
Close current branch block regularly. For a given end-point of one or more control-blocks, this appends the End-Of-Block statements.

Parameters:
insIndex - Instruction Index.
Throws:
RevEngineException - Encountered while trying to find the end statement.

getBeginStmt

public void getBeginStmt(java.util.List<JBranchEntry> listBranches,
                         int insIndex,
                         JSymbolTable symTable)
                  throws RevEngineException
Parameters:
listBranches - List of branches
insIndex - Instruction Index
symTable - SymbolTable.
Throws:
RevEngineException - thrown while generating the beginning statement for the given block.

getImmediateOuterLoop

public JBranchEntry getImmediateOuterLoop()
At any given stage this method returns the reference to while/ do..while/ switch statement that enclosed this, to the outermost reference. This method is mainly useful in case of break and continue.. statements.

Returns:
Returns a reference to control block of outermost loop.

pushControlEntry

public void pushControlEntry(JBranchEntry newent)
                      throws RevEngineException
Parameters:
newent - NewEntry of the control block that is to be pushed onto the stack.
Throws:
RevEngineException - thrown if the end block of the entry of the content to be pushed overlaps with the end of the entry existing already on top of control block stack.

writeVariableDeclarations

public void writeVariableDeclarations(JBranchEntry ent,
                                      JSymbolTable symTable)
                               throws RevEngineException
Parameters:
ent - Entry ( Control Block ) for which all the variable declarations are supposed to be in place.
symTable - Reference to symbol table that is necessary to get to know the names and datatypes of variables.
Throws:
RevEngineException - Thrown in case of any problem writing variable names in the table.

processBreakContinue

public void processBreakContinue(int startPc,
                                 int targetPc)
Parameters:
startPc - Startpc
targetPc - TargetPc

validatePairings

public void validatePairings(JBranchEntry ent)
                      throws RevEngineException
Check correct branch pairings for IF/ELSEIF/ELSE/TRY/CATCH/FINALLY.

Parameters:
ent - This is the entry that needs to be evaluated. If a branch of type TYPE_ELSE / TYPE_ELSE_IF is to be ended then the last ended must be TYPE_IF. If a branch ent is of type TYPE_CATCH then last poppped entry must be TYPE_TRY.
Throws:
RevEngineException - Thrown if these validations are not satisfied.

addCode

public void addCode(int sOffset,
                    int eOffset,
                    int fromPos,
                    int toPos,
                    java.lang.String type)
Adds a line of code with byteoffset information

Parameters:
sOffset - Offset information
eOffset - ??? Extended offset
fromPos - FromPosition
toPos - To Position
type - ?? type.

addCode

public void addCode(int sOffset,
                    int eOffset,
                    int fromPos,
                    int toPos)
Adds a line of code with byteoffset information

Parameters:
sOffset - Offset information
eOffset - ??? Extended offset
fromPos - FromPosition
toPos - To Position

addTextCode

public void addTextCode(java.lang.String txt)
Add text line to output code with indenting.

Parameters:
txt - Text to be added.

setBlockWrittenFlag

public void setBlockWrittenFlag()
In case a statement has been identified for writing for the current topmost block then that is set the written flag.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String representation of the class.


Submit Feedback to akkumar@users.sourceforge.net