Java Code Examples for com.android.dx.rop.cst.CstNat

The following examples show how to use com.android.dx.rop.cst.CstNat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example 2
Source Project: Box   Source File: MemberIdItem.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    StringIdsSection stringIds = file.getStringIds();
    CstNat nat = cst.getNat();
    int classIdx = typeIds.indexOf(getDefiningClass());
    int nameIdx = stringIds.indexOf(nat.getName());
    int typoidIdx = getTypoidIdx(file);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + cst.toHuman());
        out.annotate(2, "  class_idx: " + Hex.u2(classIdx));
        out.annotate(2, String.format("  %-10s %s", getTypoidName() + ':',
                        Hex.u2(typoidIdx)));
        out.annotate(4, "  name_idx:  " + Hex.u4(nameIdx));
    }

    out.writeShort(classIdx);
    out.writeShort(typoidIdx);
    out.writeInt(nameIdx);
}
 
Example 3
Source Project: Box   Source File: StdMember.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMember(CstType definingClass, int accessFlags, CstNat nat,
                 AttributeList attributes) {
    if (definingClass == null) {
        throw new NullPointerException("definingClass == null");
    }

    if (nat == null) {
        throw new NullPointerException("nat == null");
    }

    if (attributes == null) {
        throw new NullPointerException("attributes == null");
    }

    this.definingClass = definingClass;
    this.accessFlags = accessFlags;
    this.nat = nat;
    this.attributes = attributes;
}
 
Example 4
Source Project: Box   Source File: StdAttributeFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example 6
Source Project: Box   Source File: MemberIdItem.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    StringIdsSection stringIds = file.getStringIds();
    CstNat nat = cst.getNat();
    int classIdx = typeIds.indexOf(getDefiningClass());
    int nameIdx = stringIds.indexOf(nat.getName());
    int typoidIdx = getTypoidIdx(file);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + cst.toHuman());
        out.annotate(2, "  class_idx: " + Hex.u2(classIdx));
        out.annotate(2, String.format("  %-10s %s", getTypoidName() + ':',
                        Hex.u2(typoidIdx)));
        out.annotate(4, "  name_idx:  " + Hex.u4(nameIdx));
    }

    out.writeShort(classIdx);
    out.writeShort(typoidIdx);
    out.writeInt(nameIdx);
}
 
Example 7
Source Project: Box   Source File: StdMember.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMember(CstType definingClass, int accessFlags, CstNat nat,
                 AttributeList attributes) {
    if (definingClass == null) {
        throw new NullPointerException("definingClass == null");
    }

    if (nat == null) {
        throw new NullPointerException("nat == null");
    }

    if (attributes == null) {
        throw new NullPointerException("attributes == null");
    }

    this.definingClass = definingClass;
    this.accessFlags = accessFlags;
    this.nat = nat;
    this.attributes = attributes;
}
 
Example 8
Source Project: Box   Source File: StdAttributeFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
/**
 * Convert a value of an element to a {@code Constant}.
 * <p><strong>Warning:</strong> Array or TypeId value is not supported yet.
 *
 * @param value an annotation element value.
 * @return a Constant
 */
static Constant toConstant(Object value) {
    Class clazz = value.getClass();
    if (clazz.isEnum()) {
        CstString descriptor = new CstString(TypeId.get(clazz).getName());
        CstString name = new CstString(((Enum) value).name());
        CstNat cstNat = new CstNat(name, descriptor);
        return new CstEnumRef(cstNat);
    } else if (clazz.isArray()) {
        throw new UnsupportedOperationException("Array is not supported yet");
    } else if (value instanceof TypeId) {
        throw new UnsupportedOperationException("TypeId is not supported yet");
    } else {
        return Constants.getConstant(value);
    }
}
 
Example 10
Source Project: J2ME-Loader   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example 11
Source Project: J2ME-Loader   Source File: MemberIdItem.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    StringIdsSection stringIds = file.getStringIds();
    CstNat nat = cst.getNat();
    int classIdx = typeIds.indexOf(getDefiningClass());
    int nameIdx = stringIds.indexOf(nat.getName());
    int typoidIdx = getTypoidIdx(file);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + cst.toHuman());
        out.annotate(2, "  class_idx: " + Hex.u2(classIdx));
        out.annotate(2, String.format("  %-10s %s", getTypoidName() + ':',
                        Hex.u2(typoidIdx)));
        out.annotate(4, "  name_idx:  " + Hex.u4(nameIdx));
    }

    out.writeShort(classIdx);
    out.writeShort(typoidIdx);
    out.writeInt(nameIdx);
}
 
Example 12
Source Project: J2ME-Loader   Source File: StdMember.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMember(CstType definingClass, int accessFlags, CstNat nat,
                 AttributeList attributes) {
    if (definingClass == null) {
        throw new NullPointerException("definingClass == null");
    }

    if (nat == null) {
        throw new NullPointerException("nat == null");
    }

    if (attributes == null) {
        throw new NullPointerException("attributes == null");
    }

    this.definingClass = definingClass;
    this.accessFlags = accessFlags;
    this.nat = nat;
    this.attributes = attributes;
}
 
Example 13
Source Project: J2ME-Loader   Source File: StdAttributeFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source Project: buck   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example 15
Source Project: buck   Source File: MemberIdItem.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    StringIdsSection stringIds = file.getStringIds();
    CstNat nat = cst.getNat();
    int classIdx = typeIds.indexOf(getDefiningClass());
    int nameIdx = stringIds.indexOf(nat.getName());
    int typoidIdx = getTypoidIdx(file);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + cst.toHuman());
        out.annotate(2, "  class_idx: " + Hex.u2(classIdx));
        out.annotate(2, String.format("  %-10s %s", getTypoidName() + ':',
                        Hex.u2(typoidIdx)));
        out.annotate(4, "  name_idx:  " + Hex.u4(nameIdx));
    }

    out.writeShort(classIdx);
    out.writeShort(typoidIdx);
    out.writeInt(nameIdx);
}
 
Example 16
Source Project: buck   Source File: StdMember.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMember(CstType definingClass, int accessFlags, CstNat nat,
                 AttributeList attributes) {
    if (definingClass == null) {
        throw new NullPointerException("definingClass == null");
    }

    if (nat == null) {
        throw new NullPointerException("nat == null");
    }

    if (attributes == null) {
        throw new NullPointerException("attributes == null");
    }

    this.definingClass = definingClass;
    this.accessFlags = accessFlags;
    this.nat = nat;
    this.attributes = attributes;
}
 
Example 17
Source Project: buck   Source File: StdAttributeFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source Project: Box   Source File: AttEnclosingMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param type {@code non-null;} the innermost enclosing class
 * @param method {@code null-ok;} the name-and-type of the innermost enclosing
 * method, if any
 */
public AttEnclosingMethod(CstType type, CstNat method) {
    super(ATTRIBUTE_NAME);

    if (type == null) {
        throw new NullPointerException("type == null");
    }

    this.type = type;
    this.method = method;
}
 
Example 19
Source Project: Box   Source File: StdMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMethod(CstType definingClass, int accessFlags, CstNat nat,
        AttributeList attributes) {
    super(definingClass, accessFlags, nat, attributes);

    String descStr = getDescriptor().getString();
    effectiveDescriptor =
        Prototype.intern(descStr, definingClass.getClassType(),
                                AccessFlags.isStatic(accessFlags),
                                nat.isInstanceInit());
}
 
Example 20
Source Project: Box   Source File: MethodListParser.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdMethod meth =
        new StdMethod(getDefiner(), accessFlags, nat, attributes);

    methods.set(n, meth);
    return meth;
}
 
Example 21
Source Project: Box   Source File: FieldListParser.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdField field =
        new StdField(getDefiner(), accessFlags, nat, attributes);

    fields.set(n, field);
    return field;
}
 
Example 22
Source Project: Box   Source File: EscapeAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Replaces instructions that trigger an ArrayIndexOutofBounds exception
 * with an actual throw of the exception.
 *
 * @param insn {@code non-null;} instruction causing the exception
 * @param index {@code non-null;} index value that is out of bounds
 * @param deletedInsns {@code non-null;} set of instructions marked for
 * deletion
 */
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index,
                                      HashSet<SsaInsn> deletedInsns) {
    // Create a new ArrayIndexOutOfBoundsException
    CstType exception =
        new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
    insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null,
                                 RegOps.NEW_INSTANCE, exception);

    // Add a successor block with a move result pseudo for the exception
    SsaBasicBlock currBlock = insn.getBlock();
    SsaBasicBlock newBlock =
        currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
    SsaInsn newInsn = newBlock.getInsns().get(0);
    RegisterSpec newReg =
        RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
    insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg,
                              RegOps.MOVE_RESULT_PSEUDO, null);

    // Add another successor block to initialize the exception
    SsaBasicBlock newBlock2 =
        newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
    SsaInsn newInsn2 = newBlock2.getInsns().get(0);
    CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
    CstMethodRef newRef = new CstMethodRef(exception, newNat);
    insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index),
                                 null, RegOps.INVOKE_DIRECT, newRef);
    deletedInsns.add(newInsn2);

    // Add another successor block to throw the new exception
    SsaBasicBlock newBlock3 =
        newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
    SsaInsn newInsn3 = newBlock3.getInsns().get(0);
    insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null,
                                 RegOps.THROW, null);
    newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(),
                                   ssaMeth.getExitBlock().getIndex());
    deletedInsns.add(newInsn3);
}
 
Example 23
Source Project: Box   Source File: AttEnclosingMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param type {@code non-null;} the innermost enclosing class
 * @param method {@code null-ok;} the name-and-type of the innermost enclosing
 * method, if any
 */
public AttEnclosingMethod(CstType type, CstNat method) {
    super(ATTRIBUTE_NAME);

    if (type == null) {
        throw new NullPointerException("type == null");
    }

    this.type = type;
    this.method = method;
}
 
Example 24
Source Project: Box   Source File: StdMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param definingClass {@code non-null;} the defining class
 * @param accessFlags access flags
 * @param nat {@code non-null;} member name and type (descriptor)
 * @param attributes {@code non-null;} list of associated attributes
 */
public StdMethod(CstType definingClass, int accessFlags, CstNat nat,
        AttributeList attributes) {
    super(definingClass, accessFlags, nat, attributes);

    String descStr = getDescriptor().getString();
    effectiveDescriptor =
        Prototype.intern(descStr, definingClass.getClassType(),
                                AccessFlags.isStatic(accessFlags),
                                nat.isInstanceInit());
}
 
Example 25
Source Project: Box   Source File: MethodListParser.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdMethod meth =
        new StdMethod(getDefiner(), accessFlags, nat, attributes);

    methods.set(n, meth);
    return meth;
}
 
Example 26
Source Project: Box   Source File: FieldListParser.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdField field =
        new StdField(getDefiner(), accessFlags, nat, attributes);

    fields.set(n, field);
    return field;
}
 
Example 27
Source Project: Box   Source File: EscapeAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Replaces instructions that trigger an ArrayIndexOutofBounds exception
 * with an actual throw of the exception.
 *
 * @param insn {@code non-null;} instruction causing the exception
 * @param index {@code non-null;} index value that is out of bounds
 * @param deletedInsns {@code non-null;} set of instructions marked for
 * deletion
 */
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index,
                                      HashSet<SsaInsn> deletedInsns) {
    // Create a new ArrayIndexOutOfBoundsException
    CstType exception =
        new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
    insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null,
                                 RegOps.NEW_INSTANCE, exception);

    // Add a successor block with a move result pseudo for the exception
    SsaBasicBlock currBlock = insn.getBlock();
    SsaBasicBlock newBlock =
        currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
    SsaInsn newInsn = newBlock.getInsns().get(0);
    RegisterSpec newReg =
        RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
    insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg,
                              RegOps.MOVE_RESULT_PSEUDO, null);

    // Add another successor block to initialize the exception
    SsaBasicBlock newBlock2 =
        newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
    SsaInsn newInsn2 = newBlock2.getInsns().get(0);
    CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
    CstMethodRef newRef = new CstMethodRef(exception, newNat);
    insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index),
                                 null, RegOps.INVOKE_DIRECT, newRef);
    deletedInsns.add(newInsn2);

    // Add another successor block to throw the new exception
    SsaBasicBlock newBlock3 =
        newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
    SsaInsn newInsn3 = newBlock3.getInsns().get(0);
    insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null,
                                 RegOps.THROW, null);
    newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(),
                                   ssaMeth.getExitBlock().getIndex());
    deletedInsns.add(newInsn3);
}
 
Example 28
MethodId(TypeId<D> declaringType, TypeId<R> returnType, String name, TypeList parameters) {
    if (declaringType == null || returnType == null || name == null || parameters == null) {
        throw new NullPointerException();
    }
    this.declaringType = declaringType;
    this.returnType = returnType;
    this.name = name;
    this.parameters = parameters;
    this.nat = new CstNat(new CstString(name), new CstString(descriptor(false)));
    this.constant = new CstMethodRef(declaringType.constant, nat);
}
 
Example 29
FieldId(TypeId<D> declaringType, TypeId<V> type, String name) {
    if (declaringType == null || type == null || name == null) {
        throw new NullPointerException();
    }
    this.declaringType = declaringType;
    this.type = type;
    this.name = name;
    this.nat = new CstNat(new CstString(name), new CstString(type.name));
    this.constant = new CstFieldRef(declaringType.constant, nat);
}
 
Example 30
Source Project: J2ME-Loader   Source File: AttEnclosingMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param type {@code non-null;} the innermost enclosing class
 * @param method {@code null-ok;} the name-and-type of the innermost enclosing
 * method, if any
 */
public AttEnclosingMethod(CstType type, CstNat method) {
    super(ATTRIBUTE_NAME);

    if (type == null) {
        throw new NullPointerException("type == null");
    }

    this.type = type;
    this.method = method;
}