use of com.android.dx.rop.type.TypeList in project RocooFix by dodola.
the class ClassReferenceListBuilder method addClassWithHierachy.
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
use of com.android.dx.rop.type.TypeList in project buck by facebook.
the class ClassDefItem method writeTo.
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
boolean annotates = out.annotates();
TypeIdsSection typeIds = file.getTypeIds();
int classIdx = typeIds.indexOf(thisClass);
int superIdx = (superclass == null) ? -1 : typeIds.indexOf(superclass);
int interOff = OffsettedItem.getAbsoluteOffsetOr0(interfaces);
int annoOff = annotationsDirectory.isEmpty() ? 0 : annotationsDirectory.getAbsoluteOffset();
int sourceFileIdx = (sourceFile == null) ? -1 : file.getStringIds().indexOf(sourceFile);
int dataOff = classData.isEmpty() ? 0 : classData.getAbsoluteOffset();
int staticValuesOff = OffsettedItem.getAbsoluteOffsetOr0(staticValuesItem);
if (annotates) {
out.annotate(0, indexString() + ' ' + thisClass.toHuman());
out.annotate(4, " class_idx: " + Hex.u4(classIdx));
out.annotate(4, " access_flags: " + AccessFlags.classString(accessFlags));
out.annotate(4, " superclass_idx: " + Hex.u4(superIdx) + " // " + ((superclass == null) ? "<none>" : superclass.toHuman()));
out.annotate(4, " interfaces_off: " + Hex.u4(interOff));
if (interOff != 0) {
TypeList list = interfaces.getList();
int sz = list.size();
for (int i = 0; i < sz; i++) {
out.annotate(0, " " + list.getType(i).toHuman());
}
}
out.annotate(4, " source_file_idx: " + Hex.u4(sourceFileIdx) + " // " + ((sourceFile == null) ? "<none>" : sourceFile.toHuman()));
out.annotate(4, " annotations_off: " + Hex.u4(annoOff));
out.annotate(4, " class_data_off: " + Hex.u4(dataOff));
out.annotate(4, " static_values_off: " + Hex.u4(staticValuesOff));
}
out.writeInt(classIdx);
out.writeInt(accessFlags);
out.writeInt(superIdx);
out.writeInt(interOff);
out.writeInt(sourceFileIdx);
out.writeInt(annoOff);
out.writeInt(dataOff);
out.writeInt(staticValuesOff);
}
use of com.android.dx.rop.type.TypeList in project buck by facebook.
the class AttributeTranslator method getMethodAnnotations.
/**
* Gets the annotations out of a given method, similar to {@link
* #getAnnotations}, also including an annotation for the translation
* of the method-specific attribute {@code Exceptions}.
*
* @param method {@code non-null;} the method in question
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getMethodAnnotations(Method method) {
Annotations result = getAnnotations(method.getAttributes());
TypeList exceptions = getExceptions(method);
if (exceptions.size() != 0) {
Annotation throwsAnnotation = AnnotationUtils.makeThrows(exceptions);
result = Annotations.combine(result, throwsAnnotation);
}
return result;
}
use of com.android.dx.rop.type.TypeList in project buck by facebook.
the class CfTranslator method processMethods.
/**
* Processes the methods of the given class.
*
* @param context
* @param cf {@code non-null;} class being translated
* @param cfOptions {@code non-null;} options for class translation
* @param dexOptions {@code non-null;} options for dex output
* @param out {@code non-null;} output class
* @param dexFile {@code non-null;} dex output
*/
private static void processMethods(DxContext context, DirectClassFile cf, CfOptions cfOptions, DexOptions dexOptions, ClassDefItem out, DexFile dexFile) {
CstType thisClass = cf.getThisClass();
MethodList methods = cf.getMethods();
int sz = methods.size();
for (int i = 0; i < sz; i++) {
Method one = methods.get(i);
try {
CstMethodRef meth = new CstMethodRef(thisClass, one.getNat());
int accessFlags = one.getAccessFlags();
boolean isStatic = AccessFlags.isStatic(accessFlags);
boolean isPrivate = AccessFlags.isPrivate(accessFlags);
boolean isNative = AccessFlags.isNative(accessFlags);
boolean isAbstract = AccessFlags.isAbstract(accessFlags);
boolean isConstructor = meth.isInstanceInit() || meth.isClassInit();
DalvCode code;
if (isNative || isAbstract) {
// There's no code for native or abstract methods.
code = null;
} else {
ConcreteMethod concrete = new ConcreteMethod(one, cf, (cfOptions.positionInfo != PositionList.NONE), cfOptions.localInfo);
TranslationAdvice advice;
advice = DexTranslationAdvice.THE_ONE;
RopMethod rmeth = Ropper.convert(concrete, advice, methods);
RopMethod nonOptRmeth = null;
int paramSize;
paramSize = meth.getParameterWordCount(isStatic);
String canonicalName = thisClass.getClassType().getDescriptor() + "." + one.getName().getString();
if (cfOptions.optimize && context.optimizerOptions.shouldOptimize(canonicalName)) {
if (DEBUG) {
System.err.println("Optimizing " + canonicalName);
}
nonOptRmeth = rmeth;
rmeth = Optimizer.optimize(rmeth, paramSize, isStatic, cfOptions.localInfo, advice);
if (DEBUG) {
context.optimizerOptions.compareOptimizerStep(nonOptRmeth, paramSize, isStatic, cfOptions, advice, rmeth);
}
if (cfOptions.statistics) {
context.codeStatistics.updateRopStatistics(nonOptRmeth, rmeth);
}
}
LocalVariableInfo locals = null;
if (cfOptions.localInfo) {
locals = LocalVariableExtractor.extract(rmeth);
}
code = RopTranslator.translate(rmeth, cfOptions.positionInfo, locals, paramSize, dexOptions);
if (cfOptions.statistics && nonOptRmeth != null) {
updateDexStatistics(context, cfOptions, dexOptions, rmeth, nonOptRmeth, locals, paramSize, concrete.getCode().size());
}
}
// Preserve the synchronized flag as its "declared" variant...
if (AccessFlags.isSynchronized(accessFlags)) {
accessFlags |= AccessFlags.ACC_DECLARED_SYNCHRONIZED;
/*
* ...but only native methods are actually allowed to be
* synchronized.
*/
if (!isNative) {
accessFlags &= ~AccessFlags.ACC_SYNCHRONIZED;
}
}
if (isConstructor) {
accessFlags |= AccessFlags.ACC_CONSTRUCTOR;
}
TypeList exceptions = AttributeTranslator.getExceptions(one);
EncodedMethod mi = new EncodedMethod(meth, accessFlags, code, exceptions);
if (meth.isInstanceInit() || meth.isClassInit() || isStatic || isPrivate) {
out.addDirectMethod(mi);
} else {
out.addVirtualMethod(mi);
}
Annotations annotations = AttributeTranslator.getMethodAnnotations(one);
if (annotations.size() != 0) {
out.addMethodAnnotations(meth, annotations, dexFile);
}
AnnotationsList list = AttributeTranslator.getParameterAnnotations(one);
if (list.size() != 0) {
out.addParameterAnnotations(meth, list, dexFile);
}
dexFile.getMethodIds().intern(meth);
} catch (RuntimeException ex) {
String msg = "...while processing " + one.getName().toHuman() + " " + one.getDescriptor().toHuman();
throw ExceptionWithContext.withContext(ex, msg);
}
}
}
use of com.android.dx.rop.type.TypeList in project buck by facebook.
the class ClassDefsSection method orderItems0.
/**
* Helper for {@link #orderItems}, which recursively assigns indices
* to classes.
*
* @param type {@code null-ok;} type ref to assign, if any
* @param idx {@code >= 0;} the next index to assign
* @param maxDepth maximum recursion depth; if negative, this will
* throw an exception indicating class definition circularity
* @return {@code >= 0;} the next index to assign
*/
private int orderItems0(Type type, int idx, int maxDepth) {
ClassDefItem c = classDefs.get(type);
if ((c == null) || (c.hasIndex())) {
return idx;
}
if (maxDepth < 0) {
throw new RuntimeException("class circularity with " + type);
}
maxDepth--;
CstType superclassCst = c.getSuperclass();
if (superclassCst != null) {
Type superclass = superclassCst.getClassType();
idx = orderItems0(superclass, idx, maxDepth);
}
TypeList interfaces = c.getInterfaces();
int sz = interfaces.size();
for (int i = 0; i < sz; i++) {
idx = orderItems0(interfaces.getType(i), idx, maxDepth);
}
c.setIndex(idx);
orderedDefs.add(c);
return idx + 1;
}
Aggregations