use of com.android.dx.rop.cst.ConstantPool 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.ConstantPool in project J2ME-Loader by nikita36078.
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 J2ME-Loader by nikita36078.
the class StdAttributeFactory method constantValue.
/**
* Parses a {@code ConstantValue} attribute.
*/
private Attribute constantValue(DirectClassFile cf, int offset, int length, ParseObserver observer) {
if (length != 2) {
return throwBadLength(2);
}
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int idx = bytes.getUnsignedShort(offset);
TypedConstant cst = (TypedConstant) pool.get(idx);
Attribute result = new AttConstantValue(cst);
if (observer != null) {
observer.parsed(bytes, offset, 2, "value: " + cst);
}
return result;
}
use of com.android.dx.rop.cst.ConstantPool 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.ConstantPool in project J2ME-Loader by nikita36078.
the class CfTranslator method translate0.
/**
* Performs the main act of translation. This method is separated
* from {@link #translate} just to keep things a bit simpler in
* terms of exception handling.
*
* @param context {@code non-null;} the state global to this invocation.
* @param cf {@code non-null;} the class file
* @param bytes {@code non-null;} contents of the file
* @param cfOptions options for class translation
* @param dexOptions options for dex output
* @param dexFile {@code non-null;} dex output
* @return {@code non-null;} the translated class
*/
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {
context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile);
// Build up a class to output.
CstType thisClass = cf.getThisClass();
int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile();
ClassDefItem out = new ClassDefItem(thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile);
Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions);
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations, dexFile);
}
FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
MethodIdsSection methodIdsSection = dexFile.getMethodIds();
processFields(cf, out, dexFile);
processMethods(context, cf, cfOptions, dexOptions, out, dexFile);
// intern constant pool method, field and type references
ConstantPool constantPool = cf.getConstantPool();
int constantPoolSize = constantPool.size();
for (int i = 0; i < constantPoolSize; i++) {
Constant constant = constantPool.getOrNull(i);
if (constant instanceof CstMethodRef) {
methodIdsSection.intern((CstBaseMethodRef) constant);
} else if (constant instanceof CstInterfaceMethodRef) {
methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
} else if (constant instanceof CstFieldRef) {
fieldIdsSection.intern((CstFieldRef) constant);
} else if (constant instanceof CstEnumRef) {
fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
}
}
return out;
}
Aggregations