use of com.android.dx.rop.cst.CstNat in project buck by facebook.
the class MemberIdItem method writeTo.
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
TypeIdsSection typeIds = file.getTypeIds();
StringIdsSection stringIds = file.getStringIds();
CstNat nat = cst.getNat();
int classIdx = typeIds.indexOf(getDefiningClass());
int nameIdx = stringIds.indexOf(nat.getName());
int typoidIdx = getTypoidIdx(file);
if (out.annotates()) {
out.annotate(0, indexString() + ' ' + cst.toHuman());
out.annotate(2, " class_idx: " + Hex.u2(classIdx));
out.annotate(2, String.format(" %-10s %s", getTypoidName() + ':', Hex.u2(typoidIdx)));
out.annotate(4, " name_idx: " + Hex.u4(nameIdx));
}
out.writeShort(classIdx);
out.writeShort(typoidIdx);
out.writeInt(nameIdx);
}
use of com.android.dx.rop.cst.CstNat in project J2ME-Loader by nikita36078.
the class EscapeAnalysis method insertExceptionThrow.
/**
* Replaces instructions that trigger an ArrayIndexOutofBounds exception
* with an actual throw of the exception.
*
* @param insn {@code non-null;} instruction causing the exception
* @param index {@code non-null;} index value that is out of bounds
* @param deletedInsns {@code non-null;} set of instructions marked for
* deletion
*/
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index, HashSet<SsaInsn> deletedInsns) {
// Create a new ArrayIndexOutOfBoundsException
CstType exception = new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null, RegOps.NEW_INSTANCE, exception);
// Add a successor block with a move result pseudo for the exception
SsaBasicBlock currBlock = insn.getBlock();
SsaBasicBlock newBlock = currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
SsaInsn newInsn = newBlock.getInsns().get(0);
RegisterSpec newReg = RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg, RegOps.MOVE_RESULT_PSEUDO, null);
// Add another successor block to initialize the exception
SsaBasicBlock newBlock2 = newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
SsaInsn newInsn2 = newBlock2.getInsns().get(0);
CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
CstMethodRef newRef = new CstMethodRef(exception, newNat);
insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index), null, RegOps.INVOKE_DIRECT, newRef);
deletedInsns.add(newInsn2);
// Add another successor block to throw the new exception
SsaBasicBlock newBlock3 = newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
SsaInsn newInsn3 = newBlock3.getInsns().get(0);
insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null, RegOps.THROW, null);
newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(), ssaMeth.getExitBlock().getIndex());
deletedInsns.add(newInsn3);
}
use of com.android.dx.rop.cst.CstNat in project J2ME-Loader by nikita36078.
the class MemberListParser method parse.
/**
* Does the actual parsing.
*/
private void parse() {
int attributeContext = getAttributeContext();
int count = getCount();
// Skip the count.
int at = offset + 2;
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
if (observer != null) {
observer.parsed(bytes, offset, 2, humanName() + "s_count: " + Hex.u2(count));
}
for (int i = 0; i < count; i++) {
try {
int accessFlags = bytes.getUnsignedShort(at);
int nameIdx = bytes.getUnsignedShort(at + 2);
int descIdx = bytes.getUnsignedShort(at + 4);
CstString name = (CstString) pool.get(nameIdx);
CstString desc = (CstString) pool.get(descIdx);
if (observer != null) {
observer.startParsingMember(bytes, at, name.getString(), desc.getString());
observer.parsed(bytes, at, 0, "\n" + humanName() + "s[" + i + "]:\n");
observer.changeIndent(1);
observer.parsed(bytes, at, 2, "access_flags: " + humanAccessFlags(accessFlags));
observer.parsed(bytes, at + 2, 2, "name: " + name.toHuman());
observer.parsed(bytes, at + 4, 2, "descriptor: " + desc.toHuman());
}
at += 6;
AttributeListParser parser = new AttributeListParser(cf, attributeContext, at, attributeFactory);
parser.setObserver(observer);
at = parser.getEndOffset();
StdAttributeList attributes = parser.getList();
attributes.setImmutable();
CstNat nat = new CstNat(name, desc);
Member member = set(i, accessFlags, nat, attributes);
if (observer != null) {
observer.changeIndent(-1);
observer.parsed(bytes, at, 0, "end " + humanName() + "s[" + i + "]\n");
observer.endParsingMember(bytes, at, name.getString(), desc.getString(), member);
}
} catch (ParseException ex) {
ex.addContext("...while parsing " + humanName() + "s[" + i + "]");
throw ex;
} catch (RuntimeException ex) {
ParseException pe = new ParseException(ex);
pe.addContext("...while parsing " + humanName() + "s[" + i + "]");
throw pe;
}
}
endOffset = at;
}
use of com.android.dx.rop.cst.CstNat in project J2ME-Loader by nikita36078.
the class StdAttributeFactory method enclosingMethod.
/**
* Parses an {@code EnclosingMethod} attribute.
*/
private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) {
if (length != 4) {
throwBadLength(4);
}
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int idx = bytes.getUnsignedShort(offset);
CstType type = (CstType) pool.get(idx);
idx = bytes.getUnsignedShort(offset + 2);
CstNat method = (CstNat) pool.get0Ok(idx);
Attribute result = new AttEnclosingMethod(type, method);
if (observer != null) {
observer.parsed(bytes, offset, 2, "class: " + type);
observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method));
}
return result;
}
use of com.android.dx.rop.cst.CstNat in project J2ME-Loader by nikita36078.
the class AnnotationParser method parseValue.
/**
* Parses an annotation value.
*
* @return {@code non-null;} the parsed value
*/
private Constant parseValue() throws IOException {
int tag = input.readUnsignedByte();
if (observer != null) {
CstString humanTag = new CstString(Character.toString((char) tag));
parsed(1, "tag: " + humanTag.toQuoted());
}
switch(tag) {
case 'B':
{
CstInteger value = (CstInteger) parseConstant();
return CstByte.make(value.getValue());
}
case 'C':
{
CstInteger value = (CstInteger) parseConstant();
return CstChar.make(value.getValue());
}
case 'D':
{
CstDouble value = (CstDouble) parseConstant();
return value;
}
case 'F':
{
CstFloat value = (CstFloat) parseConstant();
return value;
}
case 'I':
{
CstInteger value = (CstInteger) parseConstant();
return value;
}
case 'J':
{
CstLong value = (CstLong) parseConstant();
return value;
}
case 'S':
{
CstInteger value = (CstInteger) parseConstant();
return CstShort.make(value.getValue());
}
case 'Z':
{
CstInteger value = (CstInteger) parseConstant();
return CstBoolean.make(value.getValue());
}
case 'c':
{
int classInfoIndex = input.readUnsignedShort();
CstString value = (CstString) pool.get(classInfoIndex);
Type type = Type.internReturnType(value.getString());
if (observer != null) {
parsed(2, "class_info: " + type.toHuman());
}
return new CstType(type);
}
case 's':
{
return parseConstant();
}
case 'e':
{
requireLength(4);
int typeNameIndex = input.readUnsignedShort();
int constNameIndex = input.readUnsignedShort();
CstString typeName = (CstString) pool.get(typeNameIndex);
CstString constName = (CstString) pool.get(constNameIndex);
if (observer != null) {
parsed(2, "type_name: " + typeName.toHuman());
parsed(2, "const_name: " + constName.toHuman());
}
return new CstEnumRef(new CstNat(constName, typeName));
}
case '@':
{
Annotation annotation = parseAnnotation(AnnotationVisibility.EMBEDDED);
return new CstAnnotation(annotation);
}
case '[':
{
requireLength(2);
int numValues = input.readUnsignedShort();
CstArray.List list = new CstArray.List(numValues);
if (observer != null) {
parsed(2, "num_values: " + numValues);
changeIndent(1);
}
for (int i = 0; i < numValues; i++) {
if (observer != null) {
changeIndent(-1);
parsed(0, "element_value[" + i + "]:");
changeIndent(1);
}
list.set(i, parseValue());
}
if (observer != null) {
changeIndent(-1);
}
list.setImmutable();
return new CstArray(list);
}
default:
{
throw new ParseException("unknown annotation tag: " + Hex.u1(tag));
}
}
}
Aggregations