use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.
the class Code method cast.
/**
* Performs either a numeric cast or a type cast.
*
* <h3>Numeric Casts</h3>
* Converts a primitive to a different representation. Numeric casts may
* be lossy. For example, converting the double {@code 1.8d} to an integer
* yields {@code 1}, losing the fractional part. Converting the integer
* {@code 0x12345678} to a short yields {@code 0x5678}, losing the high
* bytes. The following numeric casts are supported:
*
* <p><table border="1" summary="Supported Numeric Casts">
* <tr><th>From</th><th>To</th></tr>
* <tr><td>int</td><td>byte, char, short, long, float, double</td></tr>
* <tr><td>long</td><td>int, float, double</td></tr>
* <tr><td>float</td><td>int, long, double</td></tr>
* <tr><td>double</td><td>int, long, float</td></tr>
* </table>
*
* <p>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.
*
* <p>Numeric casts never throw {@link ClassCastException}.
*
* <h3>Type Casts</h3>
* Checks that a reference value is assignable to the target type. If it is
* assignable it is copied to the target local. If it is not assignable a
* {@link ClassCastException} is thrown.
*/
public void cast(Local<?> target, Local<?> source) {
if (source.getType().ropType.isReference()) {
addInstruction(new ThrowingCstInsn(Rops.CHECK_CAST, sourcePosition, RegisterSpecList.make(source.spec()), catches, target.type.constant));
moveResult(target, true);
} else {
addInstruction(new PlainInsn(getCastRop(source.type.ropType, target.type.ropType), sourcePosition, target.spec(), source.spec()));
}
}
use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.
the class Code method iget.
// instructions: fields
/**
* Copies the value in instance field {@code fieldId} of {@code instance} to
* {@code target}.
*/
public <D, V> void iget(FieldId<D, ? extends V> fieldId, Local<V> target, Local<D> instance) {
addInstruction(new ThrowingCstInsn(Rops.opGetField(target.type.ropType), sourcePosition, RegisterSpecList.make(instance.spec()), catches, fieldId.constant));
moveResult(target, true);
}
use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.
the class Code method instanceOfType.
// instructions: types
/**
* Tests if the value in {@code source} is assignable to {@code type}. If it
* is, {@code target} is assigned to 1; otherwise {@code target} is assigned
* to 0.
*/
public void instanceOfType(Local<?> target, Local<?> source, TypeId<?> type) {
addInstruction(new ThrowingCstInsn(Rops.INSTANCE_OF, sourcePosition, RegisterSpecList.make(source.spec()), catches, type.constant));
moveResult(target, true);
}
use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.
the class Code method loadConstant.
// instructions: locals
/**
* Copies the constant value {@code value} to {@code target}. The constant
* must be a primitive, String, Class, TypeId, or null.
*/
public <T> void loadConstant(Local<T> target, T value) {
Rop rop = value == null ? Rops.CONST_OBJECT_NOTHROW : Rops.opConst(target.type.ropType);
if (rop.getBranchingness() == BRANCH_NONE) {
addInstruction(new PlainCstInsn(rop, sourcePosition, target.spec(), RegisterSpecList.EMPTY, Constants.getConstant(value)));
} else {
addInstruction(new ThrowingCstInsn(rop, sourcePosition, RegisterSpecList.EMPTY, catches, Constants.getConstant(value)));
moveResult(target, true);
}
}
use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.
the class Code method sget.
/**
* Copies the value in the static field {@code fieldId} to {@code target}.
*/
public <V> void sget(FieldId<?, ? extends V> fieldId, Local<V> target) {
addInstruction(new ThrowingCstInsn(Rops.opGetStatic(target.type.ropType), sourcePosition, RegisterSpecList.EMPTY, catches, fieldId.constant));
moveResult(target, true);
}
Aggregations