use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
the class AttributeTranslator method translateInnerClasses.
/**
* Gets the {@code InnerClasses} attribute out of a given
* {@link AttributeList}, if any, translating it to one or more of an
* {@code InnerClass}, {@code EnclosingClass}, or
* {@code MemberClasses} annotation.
*
* @param thisClass {@code non-null;} type representing the class being
* processed
* @param attribs {@code non-null;} the attributes list to search in
* @param needEnclosingClass whether to include an
* {@code EnclosingClass} annotation
* @return {@code null-ok;} the converted list of annotations, if there
* was an attribute to translate
*/
private static Annotations translateInnerClasses(CstType thisClass, AttributeList attribs, boolean needEnclosingClass) {
AttInnerClasses innerClasses = (AttInnerClasses) attribs.findFirst(AttInnerClasses.ATTRIBUTE_NAME);
if (innerClasses == null) {
return null;
}
/*
* Search the list for the element representing the current class
* as well as for any named member classes.
*/
InnerClassList list = innerClasses.getInnerClasses();
int size = list.size();
InnerClassList.Item foundThisClass = null;
ArrayList<Type> membersList = new ArrayList<Type>();
for (int i = 0; i < size; i++) {
InnerClassList.Item item = list.get(i);
CstType innerClass = item.getInnerClass();
if (innerClass.equals(thisClass)) {
foundThisClass = item;
} else if (thisClass.equals(item.getOuterClass())) {
membersList.add(innerClass.getClassType());
}
}
int membersSize = membersList.size();
if ((foundThisClass == null) && (membersSize == 0)) {
return null;
}
Annotations result = new Annotations();
if (foundThisClass != null) {
result.add(AnnotationUtils.makeInnerClass(foundThisClass.getInnerName(), foundThisClass.getAccessFlags()));
if (needEnclosingClass) {
CstType outer = foundThisClass.getOuterClass();
if (outer == null) {
throw new Warning("Ignoring InnerClasses attribute for an " + "anonymous inner class\n" + "(" + thisClass.toHuman() + ") that doesn't come with an\n" + "associated EnclosingMethod attribute. " + "This class was probably produced by a\n" + "compiler that did not target the modern " + ".class file format. The recommended\n" + "solution is to recompile the class from " + "source, using an up-to-date compiler\n" + "and without specifying any \"-target\" type " + "options. The consequence of ignoring\n" + "this warning is that reflective operations " + "on this class will incorrectly\n" + "indicate that it is *not* an inner class.");
}
result.add(AnnotationUtils.makeEnclosingClass(foundThisClass.getOuterClass()));
}
}
if (membersSize != 0) {
StdTypeList typeList = new StdTypeList(membersSize);
for (int i = 0; i < membersSize; i++) {
typeList.set(i, membersList.get(i));
}
typeList.setImmutable();
result.add(AnnotationUtils.makeMemberClasses(typeList));
}
result.setImmutable();
return result;
}
use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
the class OutputFinisher method addConstants.
/**
* Helper for {@link #getAllConstants} which adds all the info for
* a single {@code RegisterSpec}.
*
* @param result {@code non-null;} result set to add to
* @param spec {@code null-ok;} register spec to add
*/
private static void addConstants(HashSet<Constant> result, RegisterSpec spec) {
if (spec == null) {
return;
}
LocalItem local = spec.getLocalItem();
CstString name = local.getName();
CstString signature = local.getSignature();
Type type = spec.getType();
if (type != Type.KNOWN_NULL) {
result.add(CstType.intern(type));
}
if (name != null) {
result.add(name);
}
if (signature != null) {
result.add(signature);
}
}
use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
the class StdCatchBuilder method handlersFor.
/**
* Makes the {@link CatchHandlerList} for the given basic block.
*
* @param block {@code non-null;} block to get entries for
* @param addresses {@code non-null;} address objects for each block
* @return {@code non-null;} array of entries
*/
private static CatchHandlerList handlersFor(BasicBlock block, BlockAddresses addresses) {
IntList successors = block.getSuccessors();
int succSize = successors.size();
int primary = block.getPrimarySuccessor();
TypeList catches = block.getLastInsn().getCatches();
int catchSize = catches.size();
if (catchSize == 0) {
return CatchHandlerList.EMPTY;
}
if (((primary == -1) && (succSize != catchSize)) || ((primary != -1) && ((succSize != (catchSize + 1)) || (primary != successors.get(catchSize))))) {
/*
* Blocks that throw are supposed to list their primary
* successor -- if any -- last in the successors list, but
* that constraint appears to be violated here.
*/
throw new RuntimeException("shouldn't happen: weird successors list");
}
/*
* Reduce the effective catchSize if we spot a catch-all that
* isn't at the end.
*/
for (int i = 0; i < catchSize; i++) {
Type type = catches.getType(i);
if (type.equals(Type.OBJECT)) {
catchSize = i + 1;
break;
}
}
CatchHandlerList result = new CatchHandlerList(catchSize);
for (int i = 0; i < catchSize; i++) {
CstType oneType = new CstType(catches.getType(i));
CodeAddress oneHandler = addresses.getStart(successors.get(i));
result.set(i, oneType, oneHandler.getAddress());
}
result.setImmutable();
return result;
}
use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
the class DebugInfoEncoder method emitHeader.
/**
* Emits the header sequence, which consists of LEB128-encoded initial
* line number and string indicies for names of all non-"this" arguments.
*
* @param sortedPositions positions, sorted by ascending address
* @param methodArgs local list entries for method argumens arguments,
* in left-to-right order omitting "this"
* @throws IOException
*/
private void emitHeader(ArrayList<PositionList.Entry> sortedPositions, ArrayList<LocalList.Entry> methodArgs) throws IOException {
boolean annotate = (annotateTo != null) || (debugPrint != null);
int mark = output.getCursor();
// Start by initializing the line number register.
if (sortedPositions.size() > 0) {
PositionList.Entry entry = sortedPositions.get(0);
line = entry.getPosition().getLine();
}
output.writeUleb128(line);
if (annotate) {
annotate(output.getCursor() - mark, "line_start: " + line);
}
int curParam = getParamBase();
// paramTypes will not include 'this'
StdTypeList paramTypes = desc.getParameterTypes();
int szParamTypes = paramTypes.size();
/*
* Initialize lastEntryForReg to have an initial
* entry for the 'this' pointer.
*/
if (!isStatic) {
for (LocalList.Entry arg : methodArgs) {
if (curParam == arg.getRegister()) {
lastEntryForReg[curParam] = arg;
break;
}
}
curParam++;
}
// Write out the number of parameter entries that will follow.
mark = output.getCursor();
output.writeUleb128(szParamTypes);
if (annotate) {
annotate(output.getCursor() - mark, String.format("parameters_size: %04x", szParamTypes));
}
/*
* Then emit the string indicies of all the method parameters.
* Note that 'this', if applicable, is excluded.
*/
for (int i = 0; i < szParamTypes; i++) {
Type pt = paramTypes.get(i);
LocalList.Entry found = null;
mark = output.getCursor();
for (LocalList.Entry arg : methodArgs) {
if (curParam == arg.getRegister()) {
found = arg;
if (arg.getSignature() != null) {
/*
* Parameters with signatures will be re-emitted
* in complete as LOCAL_START_EXTENDED's below.
*/
emitStringIndex(null);
} else {
emitStringIndex(arg.getName());
}
lastEntryForReg[curParam] = arg;
break;
}
}
if (found == null) {
/*
* Emit a null symbol for "unnamed." This is common
* for, e.g., synthesized methods and inner-class
* this$0 arguments.
*/
emitStringIndex(null);
}
if (annotate) {
String parameterName = (found == null || found.getSignature() != null) ? "<unnamed>" : found.getName().toHuman();
annotate(output.getCursor() - mark, "parameter " + parameterName + " " + RegisterSpec.PREFIX + curParam);
}
curParam += pt.getCategory();
}
for (LocalList.Entry arg : lastEntryForReg) {
if (arg == null) {
continue;
}
CstString signature = arg.getSignature();
if (signature != null) {
emitLocalStartExtended(arg);
}
}
}
use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
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