public class ParameterAccessor
extends java.lang.Object
Depending on the representation of a method (IMethod, MethodReference) parameters are placed at a different position. Functions furthermore may have an implicit this-pointer which alters the positions again.
Accessing parameters of these functions by their numbers only is error prone and leads to confusion. This class tries to leverage parameter-access.
You can use this class using now numbers at all. However if you choose to use numbers this class has yet another numbering convention (jupeee): 1 is the first parameter appearing in the Selector, no matter if the Method has an implicit this. It is not zero as Java initializes new integer-arrays with zero.
If you want to alter the values of the incoming parameters you may also want to use the ParameterManager which tracks the changes.
| Modifier and Type | Class and Description |
|---|---|
static class |
ParameterAccessor.BasedOn
The Constructor used to create ParameterAccessor influences the parameter-offset.
|
static class |
ParameterAccessor.ParamerterDisposition
The kind of parameter.
|
static class |
ParameterAccessor.Parameter
The representation of a Parameter handled using a ParameterAccessor.
|
static class |
ParameterAccessor.ParameterKey
This key is identified by type and parameter number.
|
| Constructor and Description |
|---|
ParameterAccessor(IMethod method)
Read the parameters from an IMethod.
|
ParameterAccessor(MethodReference mRef,
boolean hasImplicitThis)
Reads the parameters of a MethodReference CAUTION:.
|
ParameterAccessor(MethodReference mRef,
IClassHierarchy cha)
Reads the parameters of a MethodReference CAUTION:.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.List<ParameterAccessor.Parameter> |
all()
This list _excludes_ the implicit this-pointer (if any).
|
java.util.List<ParameterAccessor.Parameter> |
allExtend(TypeName tName,
IClassHierarchy cha)
All parameters in the selector that are a subclass of tName (slow).
|
java.util.List<ParameterAccessor.Parameter> |
allExtend(TypeReference tRef,
IClassHierarchy cha)
All parameters in the selector that are a subclass of tRef (slow).
|
java.util.List<SSAValue> |
connectThrough(ParameterAccessor callee,
java.util.Set<? extends SSAValue> overrides,
java.util.Set<? extends SSAValue> defaults,
IClassHierarchy cha)
Assign parameters to a call based on their type.
|
java.util.List<SSAValue> |
connectThrough(ParameterAccessor callee,
java.util.Set<? extends SSAValue> overrides,
java.util.Set<? extends SSAValue> defaults,
IClassHierarchy cha,
IInstantiator instantiator,
java.lang.Object... instantiatorArgs)
Connects though parameters from the calling function (overridable) - CAUTION:.
|
java.lang.String |
dump()
Extensive output for debugging purposes.
|
ParameterAccessor.Parameter |
firstExtends(TypeName tName,
IClassHierarchy cha)
First parameter in the selector that is a subclass of tName (slow).
|
ParameterAccessor.Parameter |
firstExtends(TypeReference tRef,
IClassHierarchy cha)
First parameter in the selector that is a subclass of tRef (slow).
|
int |
firstInSelector()
The SSA-Value to acces the parameter appearing first in the Descriptor with.
|
ParameterAccessor.Parameter |
firstOf(TypeName tName)
First parameter in the selector that matches _exactly_.
|
ParameterAccessor.Parameter |
firstOf(TypeReference tRef)
First parameter in the selector that matches _exactly_.
|
int[] |
forInvokeStatic(java.util.List<? extends ParameterAccessor.Parameter> args,
MethodReference target,
IClassHierarchy cha)
Shorthand for forInvokeStatic(final List<? extends Parameter> args, final
ParameterAccessor target, final IClassHierarchy cha).
|
int[] |
forInvokeStatic(java.util.List<? extends SSAValue> args)
Generate the params-param for an InvokeIstruction w/o type checking.
|
int[] |
forInvokeStatic(java.util.List<? extends SSAValue> args,
ParameterAccessor target,
IClassHierarchy cha)
Generate the params-param for an InvokeIstruction with type checking.
|
int[] |
forInvokeVirtual(int self,
java.util.List<? extends ParameterAccessor.Parameter> args,
MethodReference target,
IClassHierarchy cha)
Shorthand for forInvokeVirtual(final int self, final List<? extends Parameter> args,
final ParameterAccessor target, final IClassHierarchy cha).
|
int[] |
forInvokeVirtual(int self,
java.util.List<? extends SSAValue> args)
Generate the params-param for an InvokeIstruction w/o type checking.
|
int[] |
forInvokeVirtual(int self,
java.util.List<? extends SSAValue> args,
ParameterAccessor target,
IClassHierarchy cha)
Generate the params-param for an InvokeIstruction with type checking.
|
MethodReference |
forMethod()
The method this accessor reads the parameters from.
|
int |
getFirstAfter()
The first SSA-Number after the parameters.
|
int |
getNumberOfParameters()
Number of parameters _excluding_ implicit this
|
ParameterAccessor.Parameter |
getParameter(int no)
Make an Parameter Object using a Descriptor-based numbering (starting with 1).
|
int |
getParameterNo(int no)
Return the SSA-Value to access a parameter using a Descriptor-based numbering (starting with
1).
|
int |
getParameterNo(ParameterAccessor.Parameter param)
Same as Parameter.getNumber().
|
TypeReference |
getParameterType(int no)
Prefer: getParameter(int no) or all().
|
TypeReference |
getReturnType()
Handed through to the IMethod / MethodReference
|
ParameterAccessor.Parameter |
getThis()
Return the implicit this-pointer (or throw).
|
ParameterAccessor.Parameter |
getThisAs(TypeReference asType)
Return the implicit this-pointer as a supertype.
|
int |
getThisNo()
Return the SSA-Value of the implicit this-pointer (or throw).
|
boolean |
hasImplicitThis()
If the method has an implicit this parameter.
|
boolean |
hasReturn()
If the method returns a value eg is non-void.
|
protected boolean |
isAssignable(SSAValue from,
SSAValue to,
IClassHierarchy cha)
Does "to x := from" hold?.
|
static boolean |
isAssignable(TypeReference from,
TypeReference to,
IClassHierarchy cha)
Does "to x := from" hold?.
|
static boolean |
isSubclassOf(TypeReference sub,
TypeReference superC,
IClassHierarchy cha)
Is sub a subclass of superC (or the same).
|
ParameterAccessor.Parameter |
makeReturn(int ssa)
Create a "Parameter" containing the Return-Type w/o Type-checking.
|
ParameterAccessor.Parameter |
makeReturn(int ssa,
TypeReference type,
IClassHierarchy cha)
Create a "Parameter" containing the Return-Type with Type-checking.
|
java.lang.String |
toString() |
public ParameterAccessor(MethodReference mRef, IClassHierarchy cha)
Do _not_ use ParameterAceesor(IMethod.getReference()), but ParameterAceesor(IMehod)!
Using this Constructor influences the SSA-Values returned later. The cha is needed to
determine whether mRef is static. If this is already known one should prefer the faster ParameterAccessor(MethodReference, boolean).
mRef - The method to read the parameters from.public ParameterAccessor(MethodReference mRef, boolean hasImplicitThis)
Do _not_ use ParameterAceesor(IMethod.getReference()), but ParameterAceesor(IMehod)!
This constructor is faster than ParameterAccessor(MethodReference,
IClassHierarchy).
mRef - The method to read the parameters from.public ParameterAccessor(IMethod method)
Using this Constructor influences the SSA-Values returned later.
method - The method to read the parameters from.public ParameterAccessor.Parameter getParameter(int no)
Number 1 is the first parameter in the methods Selector. No matter if the function has an implicit this pointer.
If the Function has an implicit this-pointer you can access it using getThis().
no - the number in the Selectorjava.lang.IllegalArgumentException - if the parameter is zerojava.lang.ArrayIndexOutOfBoundsException - if no is not within bounds [1 to numberOfParameters]public int getParameterNo(int no)
Number 1 is the first parameter in the methods Selector. No matter if the function has an implicit this pointer.
If the Function has an implicit this-pointer you can acess it using getThisNo().
no - the number in the Selectorjava.lang.IllegalArgumentException - if the parameter is zerojava.lang.ArrayIndexOutOfBoundsException - if no is not within bounds [1 to numberOfParameters]public int getParameterNo(ParameterAccessor.Parameter param)
public java.util.List<ParameterAccessor.Parameter> all()
If you want the implicit this-pointer use getThis().
public ParameterAccessor.Parameter getThis()
This obviously only works on non-static methods. You probably want to check if the method has such an implicit this using hasImplicitThis() as this method will throw if there is none.
If you only want the number use the more lightweight getThisNo().
java.lang.IllegalStateException - if the function has no implicit thispublic ParameterAccessor.Parameter getThisAs(TypeReference asType)
asType - A type of a super-class of thispublic int getThisNo()
This obviously only works on non-static methods. You probably want to check if the method has such an implicit this using hasImplicitThis() as this method will throw if there is none.
java.lang.IllegalStateException - if the function has no implicit this.public boolean hasImplicitThis()
public ParameterAccessor.Parameter makeReturn(int ssa)
This should be of rather theoretical use.
java.lang.IllegalStateException - if used on a void-Functionpublic ParameterAccessor.Parameter makeReturn(int ssa, TypeReference type, IClassHierarchy cha)
ssa - The value to returntype - The type of ssacha - The ClassHierarchy to use for the assignability testjava.lang.IllegalStateException - if used on a void-Functionpublic int firstInSelector()
java.lang.IllegalArgumentException - if the method has no parameters in its Descriptor.public TypeReference getParameterType(int no)
Get the type of the parameter (not this) using a fixed numbering.
Number 1 is the first parameter in the methods Selector. No matter if the function has an implicit this pointer.
Use all() if you want to get all parameter-types.
no - the number in the Selectorpublic ParameterAccessor.Parameter firstOf(TypeName tName)
java.lang.IllegalArgumentException - if searching for void or nullpublic ParameterAccessor.Parameter firstOf(TypeReference tRef)
java.lang.IllegalArgumentException - if searching for void or nullpublic java.util.List<ParameterAccessor.Parameter> allExtend(TypeName tName, IClassHierarchy cha)
TypeNames have to be looked up first, do prefer the variant with the TypeReference if one is available.
java.lang.IllegalArgumentException - if searching for void or nullpublic java.util.List<ParameterAccessor.Parameter> allExtend(TypeReference tRef, IClassHierarchy cha)
java.lang.IllegalArgumentException - if searching for void or nullpublic ParameterAccessor.Parameter firstExtends(TypeName tName, IClassHierarchy cha)
TypeNames have to be lloked up first, do prefer the variant with the TypeReference if one is available.
java.lang.IllegalArgumentException - if searching for void or nullpublic ParameterAccessor.Parameter firstExtends(TypeReference tRef, IClassHierarchy cha)
java.lang.IllegalArgumentException - if searching for void or nullpublic int getFirstAfter()
This is useful for making synthetic methods.
public int[] forInvokeStatic(java.util.List<? extends SSAValue> args)
args - list to build the arguments from - without implicit thispublic int[] forInvokeStatic(java.util.List<? extends SSAValue> args, ParameterAccessor target, IClassHierarchy cha)
args - list to build the arguments from - without implicit thistarget - the method to be called - for type checking onlycha - if types don't match exactly needed for the assignability check (may be null if that
check is not wanted)java.lang.IllegalArgumentException - if you call this method on a target that needs an implicit
thisjava.lang.IllegalArgumentException - if args length does not match the targets param-lengthjava.lang.IllegalArgumentException - if a parameter is unassignablepublic int[] forInvokeVirtual(int self,
java.util.List<? extends SSAValue> args)
self - the this-pointer to useargs - the rest of the arguments. Be shure it does not start with a this pointer. This is
_not_ checked so you can use a this-pointer as an argument. However a warning is issued.java.lang.IllegalArgumentException - if the value of self is to small in the current methodpublic int[] forInvokeVirtual(int self,
java.util.List<? extends SSAValue> args,
ParameterAccessor target,
IClassHierarchy cha)
self - the this-pointer to useargs - list to build the arguments from - without implicit thistarget - the method to be called - for type checking onlycha - if types don't match exactly needed for the assignability check (may be null if that
check is not wanted)java.lang.IllegalArgumentException - if you call this method on a target that needs an implicit
thisjava.lang.IllegalArgumentException - if args length does not match the targets param-lengthjava.lang.IllegalArgumentException - if a parameter is unassignablepublic java.util.List<SSAValue> connectThrough(ParameterAccessor callee, java.util.Set<? extends SSAValue> overrides, java.util.Set<? extends SSAValue> defaults, IClassHierarchy cha, IInstantiator instantiator, java.lang.Object... instantiatorArgs)
This functions makes is decisions based on Type-Referes only so if a TypeReference occurs multiple times in the caller or callee it may make surprising connections.
The List of Parameters is generated based on the overrides, than parameters in 'this' are searched, finally we'll fall back to defaults. A "perfect match" is searched.
If a parameter was not assigned yet these three sources are considdered again but cha.isAssignableFrom is used.
If the parameter was still not found a value of 'null' is used.
This funktion is useful when generating wrapper-functions.
callee - The function to generate the parameter-list foroverrides - If a parameter occurs here, it is preferred over the ones present in thisdefaults - If a parameter is not present in this or the overrides, defaults are searched.
If the parameter is not present there null is assigned.cha - Optional class hierarchy for testing assignabilitypublic static boolean isAssignable(TypeReference from, TypeReference to, IClassHierarchy cha)
public static boolean isSubclassOf(TypeReference sub, TypeReference superC, IClassHierarchy cha) throws ClassLookupException
ClassLookupExceptionpublic MethodReference forMethod()
protected boolean isAssignable(SSAValue from, SSAValue to, IClassHierarchy cha)
public int[] forInvokeStatic(java.util.List<? extends ParameterAccessor.Parameter> args, MethodReference target, IClassHierarchy cha)
Generates a new ParameterAccessor for target and hands the call through.
public int[] forInvokeVirtual(int self,
java.util.List<? extends ParameterAccessor.Parameter> args,
MethodReference target,
IClassHierarchy cha)
Generates a new ParameterAccessor for target and hands the call through.
public boolean hasReturn()
public java.util.List<SSAValue> connectThrough(ParameterAccessor callee, java.util.Set<? extends SSAValue> overrides, java.util.Set<? extends SSAValue> defaults, IClassHierarchy cha)
this variant of connectThrough cannot create new instances if needed.
callee - The function to generate the parameter-list foroverrides - If a parameter occurs here, it is preferred over the ones present in thisdefaults - If a parameter is not present in this or the overrides, defaults are searched.
If the parameter is not present there null is assigned.cha - Optional class hierarchy for testing assignabilitypublic TypeReference getReturnType()
public int getNumberOfParameters()
public java.lang.String dump()
public java.lang.String toString()
toString in class java.lang.Object