Search in sources :

Example 31 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class AnnotationParser method parseElement.

/**
     * Parses a {@link NameValuePair}.
     *
     * @return {@code non-null;} the parsed element
     */
private NameValuePair parseElement() throws IOException {
    requireLength(5);
    int elementNameIndex = input.readUnsignedShort();
    CstString elementName = (CstString) pool.get(elementNameIndex);
    if (observer != null) {
        parsed(2, "element_name: " + elementName.toHuman());
        parsed(0, "value: ");
        changeIndent(1);
    }
    Constant value = parseValue();
    if (observer != null) {
        changeIndent(-1);
    }
    return new NameValuePair(elementName, value);
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstString(com.android.dx.rop.cst.CstString)

Example 32 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

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);
        }
    }
}
Also used : LocalList(com.android.dx.dex.code.LocalList) Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) StdTypeList(com.android.dx.rop.type.StdTypeList) PositionList(com.android.dx.dex.code.PositionList) CstString(com.android.dx.rop.cst.CstString) CstString(com.android.dx.rop.cst.CstString)

Example 33 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class AnnotationItem method annotateTo.

/**
     * Write a (listing file) annotation for this instance to the given
     * output, that consumes no bytes of output. This is for annotating
     * a reference to this instance at the point of the reference.
     *
     * @param out {@code non-null;} where to output to
     * @param prefix {@code non-null;} prefix for each line of output
     */
public void annotateTo(AnnotatedOutput out, String prefix) {
    out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman());
    out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
    for (NameValuePair pair : annotation.getNameValuePairs()) {
        CstString name = pair.getName();
        Constant value = pair.getValue();
        out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value));
    }
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstString(com.android.dx.rop.cst.CstString)

Example 34 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class StringIdsSection method intern.

/**
     * Interns an element into this instance.
     *
     * @param string {@code non-null;} the string to intern
     * @return {@code non-null;} the interned string
     */
public synchronized StringIdItem intern(StringIdItem string) {
    if (string == null) {
        throw new NullPointerException("string == null");
    }
    throwIfPrepared();
    CstString value = string.getValue();
    StringIdItem already = strings.get(value);
    if (already != null) {
        return already;
    }
    strings.put(value, string);
    return string;
}
Also used : CstString(com.android.dx.rop.cst.CstString)

Example 35 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class TypeIdItem method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);
    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }
    out.writeInt(idx);
}
Also used : CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString)

Aggregations

CstString (com.android.dx.rop.cst.CstString)35 CstType (com.android.dx.rop.cst.CstType)15 Constant (com.android.dx.rop.cst.Constant)13 ByteArray (com.android.dx.util.ByteArray)7 ConstantPool (com.android.dx.rop.cst.ConstantPool)6 ParseException (com.android.dx.cf.iface.ParseException)5 NameValuePair (com.android.dx.rop.annotation.NameValuePair)5 RegisterSpec (com.android.dx.rop.code.RegisterSpec)5 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)5 CstNat (com.android.dx.rop.cst.CstNat)5 Annotation (com.android.dx.rop.annotation.Annotation)4 Type (com.android.dx.rop.type.Type)4 ClassDefItem (com.android.dx.dex.file.ClassDefItem)3 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)3 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)3 Attribute (com.android.dx.cf.iface.Attribute)2 CstInsn (com.android.dx.dex.code.CstInsn)2 Annotations (com.android.dx.rop.annotation.Annotations)2 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)2 LocalItem (com.android.dx.rop.code.LocalItem)2