use of com.android.dx.rop.cst.ConstantPool in project buck by facebook.
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.ConstantPool in project buck by facebook.
the class StdAttributeFactory method signature.
/**
* Parses a {@code Signature} attribute.
*/
private Attribute signature(DirectClassFile cf, int offset, int length, ParseObserver observer) {
if (length != 2) {
throwBadLength(2);
}
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int idx = bytes.getUnsignedShort(offset);
CstString cst = (CstString) pool.get(idx);
Attribute result = new AttSignature(cst);
if (observer != null) {
observer.parsed(bytes, offset, 2, "signature: " + cst);
}
return result;
}
use of com.android.dx.rop.cst.ConstantPool in project buck by facebook.
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.ConstantPool in project buck by facebook.
the class StdAttributeFactory method sourceFile.
/**
* Parses a {@code SourceFile} attribute.
*/
private Attribute sourceFile(DirectClassFile cf, int offset, int length, ParseObserver observer) {
if (length != 2) {
throwBadLength(2);
}
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int idx = bytes.getUnsignedShort(offset);
CstString cst = (CstString) pool.get(idx);
Attribute result = new AttSourceFile(cst);
if (observer != null) {
observer.parsed(bytes, offset, 2, "source: " + cst);
}
return result;
}
use of com.android.dx.rop.cst.ConstantPool in project buck by facebook.
the class AttributeFactory method parse0.
/**
* Parses attribute content. The base class implements this by constructing
* an instance of {@link RawAttribute}. Subclasses are expected to
* override this to do something better in most cases.
*
* @param cf {@code non-null;} class file to parse from
* @param context context to parse in; one of the {@code CTX_*}
* constants
* @param name {@code non-null;} the attribute name
* @param offset offset into {@code bytes} to start parsing at; this
* is the offset to the start of attribute data, not to the header
* @param length the length of the attribute data
* @param observer {@code null-ok;} parse observer to report to, if any
* @return {@code non-null;} an appropriately-constructed {@link Attribute}
*/
protected Attribute parse0(DirectClassFile cf, int context, String name, int offset, int length, ParseObserver observer) {
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
Attribute result = new RawAttribute(name, bytes, offset, length, pool);
if (observer != null) {
observer.parsed(bytes, offset, length, "attribute data");
}
return result;
}
Aggregations