use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class Form4rcc method isCompatible.
/**
* {@inheritDoc}
*/
@Override
public boolean isCompatible(DalvInsn insn) {
if (!(insn instanceof MultiCstInsn)) {
return false;
}
MultiCstInsn mci = (MultiCstInsn) insn;
int methodIdx = mci.getIndex(0);
int protoIdx = mci.getIndex(1);
if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
return false;
}
Constant methodRef = mci.getConstant(0);
if (!(methodRef instanceof CstMethodRef)) {
return false;
}
Constant protoRef = mci.getConstant(1);
if (!(protoRef instanceof CstProtoRef)) {
return false;
}
RegisterSpecList regs = mci.getRegisters();
int sz = regs.size();
if (sz == 0) {
return true;
}
return (unsignedFitsInByte(regs.getWordCount()) && unsignedFitsInShort(sz) && unsignedFitsInShort(regs.get(0).getReg()) && isRegListSequential(regs));
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class AnnotationItem method annotateTo.
/**
* Write a (listing file) annotation for this instance to the given
* output, that consumes no bytes of output. This is for annotating
* a reference to this instance at the point of the reference.
*
* @param out {@code non-null;} where to output to
* @param prefix {@code non-null;} prefix for each line of output
*/
public void annotateTo(AnnotatedOutput out, String prefix) {
out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman());
out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
for (NameValuePair pair : annotation.getNameValuePairs()) {
CstString name = pair.getName();
Constant value = pair.getValue();
out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value));
}
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class ClassDataItem method makeStaticValuesConstant.
/**
* Gets a {@link CstArray} corresponding to {@link #staticValues} if
* it contains any non-zero non-{@code null} values.
*
* @return {@code null-ok;} the corresponding constant or {@code null} if
* there are no values to encode
*/
private CstArray makeStaticValuesConstant() {
// First sort the statics into their final order.
Collections.sort(staticFields);
/*
* Get the size of staticValues minus any trailing zeros/nulls (both
* nulls per se as well as instances of CstKnownNull).
*/
int size = staticFields.size();
while (size > 0) {
EncodedField field = staticFields.get(size - 1);
Constant cst = staticValues.get(field);
if (cst instanceof CstLiteralBits) {
// Note: CstKnownNull extends CstLiteralBits.
if (((CstLiteralBits) cst).getLongBits() != 0) {
break;
}
} else if (cst != null) {
break;
}
size--;
}
if (size == 0) {
return null;
}
// There is something worth encoding, so build up a result.
CstArray.List list = new CstArray.List(size);
for (int i = 0; i < size; i++) {
EncodedField field = staticFields.get(i);
Constant cst = staticValues.get(field);
if (cst == null) {
cst = Zeroes.zeroFor(field.getRef().getType());
}
list.set(i, cst);
}
list.setImmutable();
return new CstArray(list);
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class CodeItem method addContents.
/**
* {@inheritDoc}
*/
public void addContents(DexFile file) {
MixedItemSection byteData = file.getByteData();
TypeIdsSection typeIds = file.getTypeIds();
if (code.hasPositions() || code.hasLocals()) {
debugInfo = new DebugInfoItem(code, isStatic, ref);
byteData.add(debugInfo);
}
if (code.hasAnyCatches()) {
for (Type type : code.getCatchTypes()) {
typeIds.intern(type);
}
catches = new CatchStructs(code);
}
for (Constant c : code.getInsnConstants()) {
file.internIfAppropriate(c);
}
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class ValueEncoder method writeAnnotation.
/**
* Writes out the encoded form of the given annotation, that is,
* as an {@code encoded_annotation} and not including a
* {@code value_type} prefix. If the output stream keeps
* (debugging) annotations and {@code topLevel} is
* {@code true}, then this method will write (debugging)
* annotations.
*
* @param annotation {@code non-null;} annotation instance to write
* @param topLevel {@code true} iff the given annotation is the
* top-level annotation or {@code false} if it is a sub-annotation
* of some other annotation
*/
public void writeAnnotation(Annotation annotation, boolean topLevel) {
boolean annotates = topLevel && out.annotates();
StringIdsSection stringIds = file.getStringIds();
TypeIdsSection typeIds = file.getTypeIds();
CstType type = annotation.getType();
int typeIdx = typeIds.indexOf(type);
if (annotates) {
out.annotate(" type_idx: " + Hex.u4(typeIdx) + " // " + type.toHuman());
}
out.writeUleb128(typeIds.indexOf(annotation.getType()));
Collection<NameValuePair> pairs = annotation.getNameValuePairs();
int size = pairs.size();
if (annotates) {
out.annotate(" size: " + Hex.u4(size));
}
out.writeUleb128(size);
int at = 0;
for (NameValuePair pair : pairs) {
CstString name = pair.getName();
int nameIdx = stringIds.indexOf(name);
Constant value = pair.getValue();
if (annotates) {
out.annotate(0, " elements[" + at + "]:");
at++;
out.annotate(" name_idx: " + Hex.u4(nameIdx) + " // " + name.toHuman());
}
out.writeUleb128(nameIdx);
if (annotates) {
out.annotate(" value: " + constantToHuman(value));
}
writeConstant(value);
}
if (annotates) {
out.endAnnotation();
}
}
Aggregations