Package soot
Class Body
- java.lang.Object
-
- soot.tagkit.AbstractHost
-
- soot.Body
-
- All Implemented Interfaces:
Serializable,Host
public abstract class Body extends AbstractHost implements Serializable
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, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Chain<Local>localChainThe chain of locals for this Body.protected SootMethodmethodThe method associated with this Body.protected Chain<Trap>trapChainThe chain of traps for this Body.protected UnitPatchingChainunitChainThe chain of units for this Body.-
Fields inherited from class soot.tagkit.AbstractHost
col, line, mTagList
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBody()Creates an extremely empty Body.protectedBody(SootMethod m)Creates a Body associated to the given method.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckInit()Objectclone()Creates a deep copy of this Body.abstract Objectclone(boolean noLocalsClone)List<UnitBox>getAllUnitBoxes()Returns the result of iterating through all Units in this body and querying them for their UnitBoxes.List<ValueBox>getDefBoxes()Returns the result of iterating through all Units in this body and querying them for ValueBoxes defined.intgetLocalCount()Returns the number of locals declared in this body.Chain<Local>getLocals()Returns a backed chain of the locals declared in this Body.SootMethodgetMethod()Returns the method associated with this Body.SootMethodgetMethodUnsafe()Returns the method associated with this Body.longgetModificationCount()LocalgetParameterLocal(int i)Return LHS of the first identity stmt assigning from \@parameter i.List<Local>getParameterLocals()Get all the LHS of the identity statements assigning from parameter references.List<Value>getParameterRefs()Returns the list of parameter references used in this body.LocalgetThisLocal()Return LHS of the first identity stmt assigning from \@this.UnitgetThisUnit()Return unit containing the \@this-assignmentChain<Trap>getTraps()Returns a backed view of the traps found in this Body.List<UnitBox>getUnitBoxes(boolean branchTarget)If branchTarget is true, returns the result of iterating through all branching Units in this body and querying them for their UnitBoxes.UnitPatchingChaingetUnits()Returns the Chain of Units that make up this body.List<ValueBox>getUseAndDefBoxes()Returns a list of boxes corresponding to Values either used or defined in any unit of this Body.List<ValueBox>getUseBoxes()Returns the result of iterating through all Units in this body and querying them for ValueBoxes used.Map<Object,Object>importBodyContentsFrom(Body b)Copies the contents of the given Body into this one.Map<Object,Object>importBodyContentsFrom(Body b, boolean noLocalsClone)Copies the contents of the given Body into this one.protected voidrunValidation(BodyValidator validator)voidsetMethod(SootMethod method)Sets the method associated with this Body.StringtoString()voidvalidate()Verifies a few sanity conditions on the contents on this body.voidvalidate(List<ValidationException> exceptionList)Validates the jimple body and saves a list of all validation errorsvoidvalidateLocals()Verifies that each Local ofgetUseAndDefBoxes()is in this body's locals Chain.voidvalidateTraps()Verifies that the begin, end and handler units of each trap are in this body.voidvalidateUnitBoxes()Verifies that the UnitBoxes of this Body all point to a Unit contained within this body.voidvalidateUses()Verifies that each use in this Body has a def.voidvalidateValueBoxes()Verifies that a ValueBox is not used in more than one place.-
Methods inherited from class soot.tagkit.AbstractHost
addAllTagsOf, addTag, getJavaSourceStartColumnNumber, getJavaSourceStartLineNumber, getTag, getTags, hasTag, removeAllTags, removeTag
-
-
-
-
Field Detail
-
method
protected transient SootMethod method
The method associated with this Body.
-
unitChain
protected UnitPatchingChain 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).- Parameters:
m-
-
Body
protected Body()
Creates an extremely empty Body. The Body is not associated to any method.
-
-
Method Detail
-
clone
public Object clone()
Creates a deep copy of this Body.
-
clone
public abstract Object clone(boolean noLocalsClone)
-
getMethod
public SootMethod getMethod()
Returns the method associated with this Body.- Returns:
- the method that owns this body.
-
getMethodUnsafe
public SootMethod getMethodUnsafe()
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.- Returns:
-
importBodyContentsFrom
public Map<Object,Object> importBodyContentsFrom(Body b)
Copies the contents of the given Body into this one.- Parameters:
b-- Returns:
-
importBodyContentsFrom
public Map<Object,Object> importBodyContentsFrom(Body b, boolean noLocalsClone)
Copies the contents of the given Body into this one. If bool set true, no clone for locals- Parameters:
b- body to clonenoLocalsClone- if true the locals are not cloned, only referenced- Returns:
- cloned body
-
runValidation
protected void runValidation(BodyValidator validator)
-
validate
public void validate()
Verifies a few sanity conditions on the contents on this body.
-
validate
public void validate(List<ValidationException> exceptionList)
Validates the jimple body and saves a list of all validation errors- Parameters:
exceptionList- the list of validation errors
-
validateValueBoxes
public void validateValueBoxes()
Verifies that a ValueBox is not used in more than one place.
-
validateLocals
public void validateLocals()
Verifies that each Local ofgetUseAndDefBoxes()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.
-
checkInit
public void checkInit()
-
getLocals
public Chain<Local> getLocals()
Returns a backed chain of the locals declared in this Body.- Returns:
-
getTraps
public Chain<Trap> getTraps()
Returns a backed view of the traps found in this Body.- Returns:
-
getThisUnit
public Unit getThisUnit()
Return unit containing the \@this-assignment- Returns:
-
getThisLocal
public Local getThisLocal()
Return LHS of the first identity stmt assigning from \@this.- Returns:
-
getParameterLocal
public Local getParameterLocal(int i)
Return LHS of the first identity stmt assigning from \@parameter i.- Parameters:
i-- Returns:
-
getParameterLocals
public List<Local> getParameterLocals()
Get all the LHS of the identity statements assigning from parameter references.- Returns:
- a list of size as per
getMethod().getParameterCount()with all elements ordered as per the parameter index. - Throws:
RuntimeException- if a parameterref is missing
-
getParameterRefs
public List<Value> getParameterRefs()
Returns the list of parameter references used in this body. The list is as long as the number of parameters declared in the associated method's signature. The list may havenullentries for parameters not referenced in the body. The returned list is of fixed size.- Returns:
-
getUnits
public UnitPatchingChain 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
-
getAllUnitBoxes
public List<UnitBox> getAllUnitBoxes()
Returns the result of iterating through all Units in this body and querying them for their UnitBoxes. All UnitBoxes thus found are returned. Branching Units and statements which use PhiExpr will have UnitBoxes; a UnitBox contains a Unit that is either a target of a branch or is being used as a pointer to the end of a CFG block.This method is typically used for pointer patching, eg when the unit chain is cloned.
- Returns:
- A list of all the UnitBoxes held by this body's units.
- See Also:
UnitBox,getUnitBoxes(boolean),Unit.getUnitBoxes(),UnitBoxOwner.getUnitBoxes()
-
getUnitBoxes
public List<UnitBox> getUnitBoxes(boolean branchTarget)
If branchTarget is true, returns the result of iterating through all branching Units in this body and querying them for their UnitBoxes. These UnitBoxes contain Units that are the target of a branch. This is useful for, say, labeling blocks or updating the targets of branching statements.If branchTarget is false, returns the result of iterating through the non-branching Units in this body and querying them for their UnitBoxes. Any such UnitBoxes (typically from PhiExpr) contain a Unit that indicates the end of a CFG block.
- Parameters:
branchTarget-- Returns:
- a list of all the UnitBoxes held by this body's branching units.
- See Also:
UnitBox,getAllUnitBoxes(),Unit.getUnitBoxes(),UnitBoxOwner.getUnitBoxes()
-
getUseBoxes
public List<ValueBox> 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 List<ValueBox> 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 List<ValueBox> 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
-
getModificationCount
public long getModificationCount()
-
-