|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.dexmaker.Code
public final class Code
Builds a sequence of instructions.
getParameter(int, com.google.dexmaker.TypeId)
. Non-static
methods and constructors also have a this
parameter; it's available
as getThis(com.google.dexmaker.TypeId)
. Allocate a new local variable using newLocal(com.google.dexmaker.TypeId)
,
and assign a default value to it with loadConstant(com.google.dexmaker.Local, T)
. Every local
variable has a fixed type. This is either a primitive type (of any size) or a
reference type. This class emits instructions appropriate to the types they
operate on. Not all operations are local on all types; attempting to emit
such an operation will fail with an unchecked exception.
op(UnaryOp,Local,Local)
. Transform two values into a third value using
op(BinaryOp,Local,Local,Local)
. In either overload the first Local
parameter is where the result will be sent; the other Local
parameters are the inputs.
compareLongs(Local,Local,Local)
compares two locals each
containing a long
primitive. This is the only operation that
can compare longs. The result of the comparison is written to another
int
local.compareFloatingPoint(Local,Local,Local,int)
compares two
locals; both float
primitives or both double
primitives. This is the only operation that can compare floating
point values. This comparison takes an extra parameter that sets
the desired result if either parameter is NaN
. The result of
the comparison is wrtten to another int
local.
compare(Comparison,Label,Local,Local)
compares two locals.
The Comparison.EQ
and Comparison.NE
options compare
either int
primitives or references. The other options
compare only int
primitives. This comparison takes a Label
that will be jumped to if the comparison is true. If the
comparison is false the next instruction in sequence will be
executed.
new Label()
, and mark it using mark(com.google.dexmaker.Label)
.
All jumps to a label will execute instructions starting from that label. You
can jump to a label that hasn't yet been marked (jumping forward) or to a
label that has already been marked (jumping backward). Jump unconditionally
with jump(com.google.dexmaker.Label)
or conditionally based on a comparison using compare(Comparison,Label,Local,Local)
.
Most methods should contain either a return instruction. Void methods
should use returnVoid()
; non-void methods should use returnValue(com.google.dexmaker.Local>)
with a local whose return type matches the method's return
type. Constructors are considered void methods and should call returnVoid()
. Methods may make multiple returns. Methods containing no
return statements must either loop infinitely or throw unconditionally; it is
not legal to end a sequence of instructions without a jump, return or throw.
addCatchClause(com.google.dexmaker.TypeId>, com.google.dexmaker.Label)
to register the target label and throwable class. All
statements that follow will jump to that catch clause if they throw a Throwable
assignable to that type. Use removeCatchClause(com.google.dexmaker.TypeId>)
to
unregister the throwable class.
Throw an throwable by first assigning it to a local and then calling
throwValue(com.google.dexmaker.Local>)
. Control flow will jump to the nearest label assigned to
a type assignable to the thrown type. In this context, "nearest" means the
label requiring the fewest stack frames to be popped.
TypeId.getMethod(com.google.dexmaker.TypeId, java.lang.String, com.google.dexmaker.TypeId>...)
. This is more
onerous than Java language invokes, which can infer the target method using
the target object and parameters. There are four invoke kinds:
invokeStatic(com.google.dexmaker.MethodId, R>, com.google.dexmaker.Local super R>, com.google.dexmaker.Local>...)
is used for static methods.invokeDirect(com.google.dexmaker.MethodId, com.google.dexmaker.Local super R>, com.google.dexmaker.Local extends D>, com.google.dexmaker.Local>...)
is used for private instance methods and
constructorsinvokeInterface(com.google.dexmaker.MethodId, com.google.dexmaker.Local super R>, com.google.dexmaker.Local extends D>, com.google.dexmaker.Local>...)
is used to invoke a method whose declaring
type is an interface.invokeVirtual(com.google.dexmaker.MethodId, com.google.dexmaker.Local super R>, com.google.dexmaker.Local extends D>, com.google.dexmaker.Local>...)
is used to invoke any other method. The target
must not be static, private, a constructor method, or an interface
method.invokeSuper(com.google.dexmaker.MethodId, com.google.dexmaker.Local super R>, com.google.dexmaker.Local extends D>, com.google.dexmaker.Local>...)
is used to invoke the closest superclass's
virtual method. The target must not be static, private, a constructor
method, or an interface method.newInstance(com.google.dexmaker.Local, com.google.dexmaker.MethodId, com.google.dexmaker.Local>...)
is used to invoke a constructor.sget(com.google.dexmaker.FieldId, V>, com.google.dexmaker.Local)
; write them using sput(com.google.dexmaker.FieldId, V>, com.google.dexmaker.Local)
. For
instance values you'll need to specify the declaring instance; use getThis(com.google.dexmaker.TypeId)
in an instance method to use this
. Read instance values
using iget(com.google.dexmaker.FieldId, com.google.dexmaker.Local, com.google.dexmaker.Local)
and write them with iput(com.google.dexmaker.FieldId, com.google.dexmaker.Local, com.google.dexmaker.Local)
.
newArray(com.google.dexmaker.Local, com.google.dexmaker.Local)
. Read an array's length with arrayLength(com.google.dexmaker.Local, com.google.dexmaker.Local)
and its elements with aget(com.google.dexmaker.Local>, com.google.dexmaker.Local>, com.google.dexmaker.Local)
. Write an array's elements
with aput(com.google.dexmaker.Local>, com.google.dexmaker.Local, com.google.dexmaker.Local>)
.
cast(com.google.dexmaker.Local>, com.google.dexmaker.Local>)
to perform either a numeric cast or a
type cast. Interrogate the type of a value in a local using
instanceOfType(com.google.dexmaker.Local>, com.google.dexmaker.Local>, com.google.dexmaker.TypeId>)
.
Method Summary | ||
---|---|---|
void |
addCatchClause(TypeId<?> throwable,
Label catchClause)
|
|
void |
aget(Local<?> target,
Local<?> array,
Local<java.lang.Integer> index)
|
|
void |
aput(Local<?> array,
Local<java.lang.Integer> index,
Local<?> source)
|
|
|
arrayLength(Local<java.lang.Integer> target,
Local<T> array)
|
|
void |
cast(Local<?> target,
Local<?> source)
Performs either a numeric cast or a type cast. |
|
|
compare(Comparison comparison,
Label trueLabel,
Local<T> a,
Local<T> b)
Compare ints or references. |
|
|
compareFloatingPoint(Local<java.lang.Integer> target,
Local<T> a,
Local<T> b,
int nanValue)
Compare floats or doubles. |
|
void |
compareLongs(Local<java.lang.Integer> target,
Local<java.lang.Long> a,
Local<java.lang.Long> b)
Compare longs. |
|
|
getParameter(int index,
TypeId<T> type)
|
|
|
getThis(TypeId<T> type)
|
|
|
iget(FieldId<D,V> fieldId,
Local<V> target,
Local<D> instance)
|
|
void |
instanceOfType(Local<?> target,
Local<?> source,
TypeId<?> type)
|
|
|
invokeDirect(MethodId<D,R> method,
Local<? super R> target,
Local<? extends D> object,
Local<?>... args)
|
|
|
invokeInterface(MethodId<D,R> method,
Local<? super R> target,
Local<? extends D> object,
Local<?>... args)
|
|
|
invokeStatic(MethodId<?,R> method,
Local<? super R> target,
Local<?>... args)
|
|
|
invokeSuper(MethodId<D,R> method,
Local<? super R> target,
Local<? extends D> object,
Local<?>... args)
|
|
|
invokeVirtual(MethodId<D,R> method,
Local<? super R> target,
Local<? extends D> object,
Local<?>... args)
|
|
|
iput(FieldId<D,V> fieldId,
Local<D> instance,
Local<V> source)
|
|
void |
jump(Label target)
|
|
|
loadConstant(Local<T> target,
T value)
|
|
void |
mark(Label label)
Start defining instructions for the named label. |
|
|
newArray(Local<T> target,
Local<java.lang.Integer> length)
|
|
|
newInstance(Local<T> target,
MethodId<T,java.lang.Void> constructor,
Local<?>... args)
|
|
|
newLocal(TypeId<T> type)
|
|
|
op(BinaryOp op,
Local<T> target,
Local<T> a,
Local<T> b)
|
|
|
op(UnaryOp op,
Local<T> target,
Local<T> source)
|
|
Label |
removeCatchClause(TypeId<?> throwable)
|
|
void |
returnValue(Local<?> result)
|
|
void |
returnVoid()
|
|
|
sget(FieldId<?,V> fieldId,
Local<V> target)
|
|
|
sput(FieldId<?,V> fieldId,
Local<V> source)
|
|
void |
throwValue(Local<?> throwable)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public <T> Local<T> newLocal(TypeId<T> type)
public <T> Local<T> getParameter(int index, TypeId<T> type)
public <T> Local<T> getThis(TypeId<T> type)
public void mark(Label label)
public void jump(Label target)
public void addCatchClause(TypeId<?> throwable, Label catchClause)
public Label removeCatchClause(TypeId<?> throwable)
public void throwValue(Local<?> throwable)
public <T> void loadConstant(Local<T> target, T value)
public <T> void op(UnaryOp op, Local<T> target, Local<T> source)
public <T> void op(BinaryOp op, Local<T> target, Local<T> a, Local<T> b)
public <T> void compare(Comparison comparison, Label trueLabel, Local<T> a, Local<T> b)
trueLabel
. If it is false, execution continues to the next
instruction.
public <T extends java.lang.Number> void compareFloatingPoint(Local<java.lang.Integer> target, Local<T> a, Local<T> b, int nanValue)
public void compareLongs(Local<java.lang.Integer> target, Local<java.lang.Long> a, Local<java.lang.Long> b)
public <D,V> void iget(FieldId<D,V> fieldId, Local<V> target, Local<D> instance)
public <D,V> void iput(FieldId<D,V> fieldId, Local<D> instance, Local<V> source)
public <V> void sget(FieldId<?,V> fieldId, Local<V> target)
public <V> void sput(FieldId<?,V> fieldId, Local<V> source)
public <T> void newInstance(Local<T> target, MethodId<T,java.lang.Void> constructor, Local<?>... args)
public <R> void invokeStatic(MethodId<?,R> method, Local<? super R> target, Local<?>... args)
public <D,R> void invokeVirtual(MethodId<D,R> method, Local<? super R> target, Local<? extends D> object, Local<?>... args)
public <D,R> void invokeDirect(MethodId<D,R> method, Local<? super R> target, Local<? extends D> object, Local<?>... args)
public <D,R> void invokeSuper(MethodId<D,R> method, Local<? super R> target, Local<? extends D> object, Local<?>... args)
public <D,R> void invokeInterface(MethodId<D,R> method, Local<? super R> target, Local<? extends D> object, Local<?>... args)
public void instanceOfType(Local<?> target, Local<?> source, TypeId<?> type)
public void cast(Local<?> target, Local<?> source)
1.8d
to an integer
yields 1
, losing the fractional part. Converting the integer
0x12345678
to a short yields 0x5678
, losing the high
bytes. The following numeric casts are supported:
From | To |
---|---|
int | byte, char, short, long, float, double |
long | int, float, double |
float | int, long, double |
double | int, long, float |
For some primitive conversions it will be necessary to chain multiple cast operations. For example, to go from float to short one would first cast float to int and then int to short.
Numeric casts never throw ClassCastException
.
ClassCastException
is thrown.
public <T> void arrayLength(Local<java.lang.Integer> target, Local<T> array)
public <T> void newArray(Local<T> target, Local<java.lang.Integer> length)
public void aget(Local<?> target, Local<?> array, Local<java.lang.Integer> index)
public void aput(Local<?> array, Local<java.lang.Integer> index, Local<?> source)
public void returnVoid()
public void returnValue(Local<?> result)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |