Class AndroidModelParameterManager
This class comes in handy if you want to use loops or mix a return value of a function into the parameter of a later function. It supports multiple levels of cascading code blocks and delivers information which SSA-Value is the latest to use or which aught to be combined using a Phi-Statement.
However it does no allocations or Phi-Statements on its own. It just juggles with the numbers.
- Since:
- 2013-09-19
TODO:
- Track if a variable has been refered to to be able to prune unused Phi-Instructions later
- Trim Memory consumption? The whole class should not be in * memory for long time so this might be not neccessary.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAndroidModelParameterManager(com.ibm.wala.core.util.ssa.ParameterAccessor acc) Setting the behaviour may be handy in the later model.AndroidModelParameterManager(com.ibm.wala.types.MethodReference mRef, boolean isStatic) -
Method Summary
Modifier and TypeMethodDescriptiongetAllForPhi(com.ibm.wala.types.TypeReference type) intgetCurrent(com.ibm.wala.types.TypeReference type) Retreive the SSA-Number that is valid for a type in the current scope.intgetFree(com.ibm.wala.types.TypeReference type) Returns and registers a free SSA-Number to a Type.intgetSuper(com.ibm.wala.types.TypeReference type) Retreive the SSA-Number that is valid for a type in the super-ordinate scope.intgetUnallocated(com.ibm.wala.types.TypeReference type) Get an unused number to assign to.intRetreive a SSA-Value that is not under management.voidinvalidate(com.ibm.wala.types.TypeReference type) booleanisCreate(com.ibm.wala.types.TypeReference type) Shorthand for not(isReuse(TypeReference).booleanisReuse(com.ibm.wala.types.TypeReference type) Handed through to an IInstantiationBehavior if set in the constructor.booleanisSeen(com.ibm.wala.types.TypeReference type) booleanisSeen(com.ibm.wala.types.TypeReference type, boolean withSuper) Return if the type is managed by this class.booleanneedsAllocation(com.ibm.wala.types.TypeReference type) Returns if an instance for that type needs to be allocated.booleanneedsPhi(com.ibm.wala.types.TypeReference type) Returns if a PhiInstruction (still) has to be added.intscopeDown(boolean doesLoop) Enter a subordinate scope.intscopeUp()Leave a subordinate scope.voidsetAllocation(com.ibm.wala.core.util.ssa.SSAValue val) voidsetAllocation(com.ibm.wala.types.TypeReference type, int ssaValue) voidsetAllocation(com.ibm.wala.types.TypeReference type, int ssaValue, com.ibm.wala.ssa.SSAInstruction setBy) Register a variable _after_ allocation.voidsetPhi(com.ibm.wala.types.TypeReference type, int ssaValue, com.ibm.wala.ssa.SSAInstruction setBy) Register a Phi-Instruction _after_ added to the model.toString()
-
Constructor Details
-
AndroidModelParameterManager
Setting the behaviour may be handy in the later model.However it brings no benefit to the AndroidModelParameterManager.
-
AndroidModelParameterManager
public AndroidModelParameterManager(com.ibm.wala.types.MethodReference mRef, boolean isStatic) -
AndroidModelParameterManager
public AndroidModelParameterManager(com.ibm.wala.core.util.ssa.ParameterAccessor acc)
-
-
Method Details
-
setAllocation
public void setAllocation(com.ibm.wala.types.TypeReference type, int ssaValue, com.ibm.wala.ssa.SSAInstruction setBy) Register a variable _after_ allocation.The proper way to add an allocation is to get a Variable using
getUnallocated(com.ibm.wala.types.TypeReference). Then assign it a value. And at last call this function.You can however directly call the function if the type has not been seen before.
- Parameters:
type- The type allocatedssaValue- an unallocated SSA-Variable to assign the allocation tosetBy- The instruction that set the value- Throws:
IllegalStateException- if you set more than one allocation for that type (TODO better check!)IllegalArgumentException- if type is null or ssaValue is zero or negative
-
setAllocation
public void setAllocation(com.ibm.wala.types.TypeReference type, int ssaValue) -
setAllocation
public void setAllocation(com.ibm.wala.core.util.ssa.SSAValue val) -
setPhi
public void setPhi(com.ibm.wala.types.TypeReference type, int ssaValue, com.ibm.wala.ssa.SSAInstruction setBy) Register a Phi-Instruction _after_ added to the model.- Parameters:
type- the type the Phi-Instruction setsssaValue- the number the SSA-Instruction assignes tosetBy- the Phi-Instruction itself - may be null- Throws:
IllegalArgumentException- if you assign to a number requested usinggetFree(TypeReference)but types mismach.IllegalStateException- if you forgot to close some Phis
-
getFree
public int getFree(com.ibm.wala.types.TypeReference type) Returns and registers a free SSA-Number to a Type.You have to set the type using a Phi-Instruction. Also you don't have to add that instruction immediatly it is required that it is added before the Model gets finished.
You can request the List of unmet Phi-Instructions by using XXX
- Returns:
- an unused SSA-Number
- Throws:
IllegalArgumentException- if type is null
-
getUnallocated
public int getUnallocated(com.ibm.wala.types.TypeReference type) Get an unused number to assign to.There may only be one unallocated value for each type at a time. XXX: Really?
- Returns:
- SSA-Variable
- Throws:
IllegalStateException- if there is already an unallocated variable of that typeIllegalArgumentException- if type is null
-
getUnmanaged
public int getUnmanaged()Retreive a SSA-Value that is not under management.Use instead of 'nextLocal++', else SSA-Values will clash!
- Returns:
- SSA-Variable
-
getCurrent
public int getCurrent(com.ibm.wala.types.TypeReference type) Retreive the SSA-Number that is valid for a type in the current scope.Either that number origins from an allocation or a PhiInstruction (to be).
- Returns:
- a ssa number
- Throws:
IllegalStateException- if no number is assignableIllegalArgumentException- if type was not seen before or is null
-
getSuper
public int getSuper(com.ibm.wala.types.TypeReference type) Retreive the SSA-Number that is valid for a type in the super-ordinate scope.Either that number origins from an allocation or a PhiInstruction (to be).
- Returns:
- a ssa number
- Throws:
IllegalStateException- if no number is assignableIllegalArgumentException- if type was not seen before or is null
-
getAllForPhi
- Throws:
IllegalArgumentException- if type was not seen before or is null
-
isSeen
public boolean isSeen(com.ibm.wala.types.TypeReference type, boolean withSuper) Return if the type is managed by this class.- Parameters:
withSuper- when true return true if a managed key may be cast to type, when false type has to match exactlytype- the type in question- Throws:
IllegalArgumentException- if type is null
-
isSeen
public boolean isSeen(com.ibm.wala.types.TypeReference type) -
needsAllocation
public boolean needsAllocation(com.ibm.wala.types.TypeReference type) Returns if an instance for that type needs to be allocated.However this function does not respect weather a PhiInstruction is needed.
- Throws:
IllegalArgumentException- if type is null
-
needsPhi
public boolean needsPhi(com.ibm.wala.types.TypeReference type) Returns if a PhiInstruction (still) has to be added.This is true if the Value has changed in a deeper scope, has been invalidated or requested using getFree
- Throws:
IllegalArgumentException- if type is null or has not been seen before
-
invalidate
public void invalidate(com.ibm.wala.types.TypeReference type) - Throws:
IllegalArgumentException- if type was not seen before or is null
-
scopeDown
public int scopeDown(boolean doesLoop) Enter a subordinate scope.Call this whenever a new code block starts i.e. when ever you would have to put a left curly-bracket in yout java code.
This function influences the placement of Phi-Functions. Thus if you don't change values you don't have to call it.
- Parameters:
doesLoop- set to true if the scope is introduced for a loop- Returns:
- The depth
-
scopeUp
public int scopeUp()Leave a subordinate scope.All changes are marked invalid thus to be expected to be collected by a PhiInstruction.
- Throws:
IllegalStateException- if already at top level
-
isReuse
public boolean isReuse(com.ibm.wala.types.TypeReference type) Handed through to an IInstantiationBehavior if set in the constructor.- Returns:
- true if Type is a REUSE type
- Throws:
IllegalStateException- if AndroidModelParameterManager was constructed without an IInstanciationBehavior
-
isCreate
public boolean isCreate(com.ibm.wala.types.TypeReference type) Shorthand for not(isReuse(TypeReference).- Returns:
- true if type is a CREATE-Type
- Throws:
IllegalStateException- if AndroidModelParameterManager was constructed without an IInstanciationBehavior
-
toString
-