Search in sources :

Example 46 with CstString

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

the class ConstantPoolParser method parseUtf8.

/**
     * Parses a utf8 constant.
     *
     * @param at offset to the start of the constant (where the tag byte is)
     * @return {@code non-null;} the parsed value
     */
private CstString parseUtf8(int at) {
    int length = bytes.getUnsignedShort(at + 1);
    // Skip to the data.
    at += 3;
    ByteArray ubytes = bytes.slice(at, at + length);
    try {
        return new CstString(ubytes);
    } catch (IllegalArgumentException ex) {
        // Translate the exception
        throw new ParseException(ex);
    }
}
Also used : CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException)

Example 47 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 48 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 49 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 50 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)

Aggregations

CstString (com.android.dx.rop.cst.CstString)69 CstType (com.android.dx.rop.cst.CstType)29 Constant (com.android.dx.rop.cst.Constant)25 ByteArray (com.android.dx.util.ByteArray)15 ConstantPool (com.android.dx.rop.cst.ConstantPool)12 ParseException (com.android.dx.cf.iface.ParseException)10 NameValuePair (com.android.dx.rop.annotation.NameValuePair)10 RegisterSpec (com.android.dx.rop.code.RegisterSpec)10 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)10 CstNat (com.android.dx.rop.cst.CstNat)10 Annotation (com.android.dx.rop.annotation.Annotation)8 Type (com.android.dx.rop.type.Type)8 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)6 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)6 Attribute (com.android.dx.cf.iface.Attribute)5 ClassDefItem (com.android.dx.dex.file.ClassDefItem)5 CstInsn (com.android.dx.dex.code.CstInsn)4 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)4 LocalItem (com.android.dx.rop.code.LocalItem)4 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)4