soot
Class Body

java.lang.Object
  |
  +--soot.Body
Direct Known Subclasses:
BafBody, StmtBody

public abstract class Body
extends java.lang.Object

Abstract base class that models the body (code attribute) of a Java method. Classes that implement an Intermediate Representation for a method body should subclass it. In particular the classes GrimpBody, JimpleBody and BafBody all extend this class. This class provides methods that are common to any IR, such as methods to get the body's units (statements), traps, and locals.

See Also:
GrimpBody, JimpleBody, BafBody

Field Summary
protected  Chain localChain
          The chain of locals for this Body.
protected  SootMethod method
          The method associated with this Body.
protected  Chain trapChain
          The chain of traps for this Body.
protected  PatchingChain unitChain
          The chain of units for this Body.
 
Constructor Summary
protected Body()
          Creates an extremely empty Body.
protected Body(SootMethod m)
          Creates a Body associated to the given method.
 
Method Summary
abstract  java.lang.Object clone()
          Creates a deep copy of this Body.
 java.util.List getDefBoxes()
          Returns the result of iterating through all Units in this body and querying them for ValueBoxes defined.
 int getLocalCount()
          Returns the number of locals declared in this body.
 Chain getLocals()
          Returns a backed chain of the locals declared in this Body.
 SootMethod getMethod()
          Returns the method associated with this Body.
 Chain getTraps()
          Returns a backed view of the traps found in this Body.
 java.util.List getUnitBoxes()
          Returns the result of iterating through all Units in this body and querying them for their UnitBoxes.
 PatchingChain getUnits()
          Returns the Chain of Units that make up this body.
 java.util.List getUseAndDefBoxes()
          Returns a list of boxes corresponding to Values either used or defined in any unit of this Body.
 java.util.List getUseBoxes()
          Returns the result of iterating through all Units in this body and querying them for ValueBoxes used.
 void importBodyContentsFrom(Body b)
          Copies the contents of the given Body into this one.
 void printDebugTo(java.io.PrintWriter out, int printBodyOptions)
          Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body.
 void printTo(java.io.PrintWriter out)
          Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body.
 void printTo(java.io.PrintWriter out, int printBodyOptions)
          Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body.
 void setMethod(SootMethod method)
          Sets the method associated with this Body.
 void validate()
          Verifies a few sanity conditions on the contents on this body.
 void validateLocals()
          Verifies that each Local of getUseAndDefBoxes() is in this body's locals Chain.
 void validateTraps()
          Verifies that the begin, end and handler units of each trap are in this body.
 void validateUnitBoxes()
          Verifies that the UnitBoxes of this Body all point to a Unit contained within this body.
 void validateUses()
          Verifies that each use in this Body has a def.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

method

protected SootMethod method
The method associated with this Body.

localChain

protected Chain localChain
The chain of locals for this Body.

trapChain

protected Chain trapChain
The chain of traps for this Body.

unitChain

protected PatchingChain unitChain
The chain of units for this Body.
Constructor Detail

Body

protected Body(SootMethod m)
Creates a Body associated to the given method. Used by subclasses during initialization. Creation of a Body is triggered by e.g. Jimple.v().newBody(options).

Body

protected Body()
Creates an extremely empty Body. The Body is not associated to any method.
Method Detail

clone

public abstract java.lang.Object clone()
Creates a deep copy of this Body.
Overrides:
clone in class java.lang.Object

getMethod

public SootMethod getMethod()
Returns the method associated with this Body.
Returns:
the method that owns this body.

setMethod

public void setMethod(SootMethod method)
Sets the method associated with this Body.
Parameters:
method - the method that owns this body.

getLocalCount

public int getLocalCount()
Returns the number of locals declared in this body.

importBodyContentsFrom

public void importBodyContentsFrom(Body b)
Copies the contents of the given Body into this one.

validate

public void validate()
Verifies a few sanity conditions on the contents on this body.

validateLocals

public void validateLocals()
Verifies that each Local of getUseAndDefBoxes() is in this body's locals Chain.

validateTraps

public void validateTraps()
Verifies that the begin, end and handler units of each trap are in this body.

validateUnitBoxes

public void validateUnitBoxes()
Verifies that the UnitBoxes of this Body all point to a Unit contained within this body.

validateUses

public void validateUses()
Verifies that each use in this Body has a def.

getLocals

public Chain getLocals()
Returns a backed chain of the locals declared in this Body.

getTraps

public Chain getTraps()
Returns a backed view of the traps found in this Body.

getUnits

public PatchingChain getUnits()
Returns the Chain of Units that make up this body. The units are returned as a PatchingChain. The client can then manipulate the chain, adding and removing units, and the changes will be reflected in the body. Since a PatchingChain is returned the client need not worry about removing exception boundary units or otherwise corrupting the chain.
Returns:
the units in this Body
See Also:
PatchingChain, Unit

getUnitBoxes

public java.util.List getUnitBoxes()
Returns the result of iterating through all Units in this body and querying them for their UnitBoxes. All UnitBoxes thus found are returned. Only branching Units will have UnitBoxes; a UnitBox contains a Unit that is a target of a branch.
Returns:
a list of all the UnitBoxes held by this body's units.
See Also:
UnitBox, Unit.getUnitBoxes()

getUseBoxes

public java.util.List getUseBoxes()
Returns the result of iterating through all Units in this body and querying them for ValueBoxes used. All of the ValueBoxes found are then returned as a List.
Returns:
a list of all the ValueBoxes for the Values used this body's units.
See Also:
Value, Unit.getUseBoxes(), ValueBox, Value

getDefBoxes

public java.util.List getDefBoxes()
Returns the result of iterating through all Units in this body and querying them for ValueBoxes defined. All of the ValueBoxes found are then returned as a List.
Returns:
a list of all the ValueBoxes for Values defined by this body's units.
See Also:
Value, Unit.getDefBoxes(), ValueBox, Value

getUseAndDefBoxes

public java.util.List getUseAndDefBoxes()
Returns a list of boxes corresponding to Values either used or defined in any unit of this Body.
Returns:
a list of ValueBoxes for held by the body's Units.
See Also:
Value, Unit.getUseAndDefBoxes(), ValueBox, Value

printTo

public void printTo(java.io.PrintWriter out)
Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body. Default printBodyOptions are used.
Parameters:
out - a PrintWriter instance to print to.

printTo

public void printTo(java.io.PrintWriter out,
                    int printBodyOptions)
Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body.
Parameters:
out - a PrintWriter instance to print to.
printBodyOptions - options for printing.
See Also:
PrintJimpleBodyOption

printDebugTo

public void printDebugTo(java.io.PrintWriter out,
                         int printBodyOptions)
Prints out the method corresponding to this Body, (declaration and body), in the textual format corresponding to the IR used to encode this body. Includes extra debugging information.
Parameters:
out - a PrintWriter instance to print to.
printBodyOptions - options for printing.
See Also:
PrintJimpleBodyOption