Java Code Examples for org.apache.bcel.Const#T_LONG

The following examples show how to use org.apache.bcel.Const#T_LONG . 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 File: TypeFrameModelingVisitor.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Work around some weirdness in BCEL (inherited from JVM Spec 1): BCEL
 * considers long and double types to consume two slots on the stack. This
 * method ensures that we push two types for each double or long value.
 */
protected void pushValue(Type type) {
    if (type.getType() == Const.T_VOID) {
        throw new IllegalArgumentException("Can't push void");
    }
    TypeFrame frame = getFrame();
    if (type.getType() == Const.T_LONG) {
        frame.pushValue(Type.LONG);
        frame.pushValue(TypeFrame.getLongExtraType());
    } else if (type.getType() == Const.T_DOUBLE) {
        frame.pushValue(Type.DOUBLE);
        frame.pushValue(TypeFrame.getDoubleExtraType());
    } else {
        frame.pushValue(type);
    }
}
 
Example 2
Source File: FieldGen.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private int addConstant() {
    switch (super.getType().getType()) { // sic
        case Const.T_INT:
        case Const.T_CHAR:
        case Const.T_BYTE:
        case Const.T_BOOLEAN:
        case Const.T_SHORT:
            return super.getConstantPool().addInteger(((Integer) value).intValue());
        case Const.T_FLOAT:
            return super.getConstantPool().addFloat(((Float) value).floatValue());
        case Const.T_DOUBLE:
            return super.getConstantPool().addDouble(((Double) value).doubleValue());
        case Const.T_LONG:
            return super.getConstantPool().addLong(((Long) value).longValue());
        case Const.T_REFERENCE:
            return super.getConstantPool().addString((String) value);
        default:
            throw new IllegalStateException("Unhandled : " + super.getType().getType()); // sic
    }
}
 
Example 3
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
public Instruction createAppend( final Type type ) {
    final byte t = type.getType();
    if (isString(type)) {
        return createInvoke(append_mos[0], Const.INVOKEVIRTUAL);
    }
    switch (t) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_FLOAT:
        case Const.T_DOUBLE:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
        case Const.T_LONG:
            return createInvoke(append_mos[t], Const.INVOKEVIRTUAL);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return createInvoke(append_mos[1], Const.INVOKEVIRTUAL);
        default:
            throw new IllegalArgumentException("No append for this type? " + type);
    }
}
 
Example 4
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Create typed return
 */
public static ReturnInstruction createReturn( final Type type ) {
    switch (type.getType()) {
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.ARETURN;
        case Const.T_INT:
        case Const.T_SHORT:
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
            return InstructionConst.IRETURN;
        case Const.T_FLOAT:
            return InstructionConst.FRETURN;
        case Const.T_DOUBLE:
            return InstructionConst.DRETURN;
        case Const.T_LONG:
            return InstructionConst.LRETURN;
        case Const.T_VOID:
            return InstructionConst.RETURN;
        default:
            throw new IllegalArgumentException("Invalid type: " + type);
    }
}
 
Example 5
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Create binary operation for simple basic types, such as int and float.
 *
 * @param op operation, such as "+", "*", "<<", etc.
 */
public static ArithmeticInstruction createBinaryOperation( final String op, final Type type ) {
    final char first = op.charAt(0);
    switch (type.getType()) {
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
        case Const.T_CHAR:
            return createBinaryIntOp(first, op);
        case Const.T_LONG:
            return createBinaryLongOp(first, op);
        case Const.T_FLOAT:
            return createBinaryFloatOp(first);
        case Const.T_DOUBLE:
            return createBinaryDoubleOp(first);
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 6
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createStore( final Type type, final int index ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
            return new ISTORE(index);
        case Const.T_FLOAT:
            return new FSTORE(index);
        case Const.T_DOUBLE:
            return new DSTORE(index);
        case Const.T_LONG:
            return new LSTORE(index);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return new ASTORE(index);
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 7
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createLoad( final Type type, final int index ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
            return new ILOAD(index);
        case Const.T_FLOAT:
            return new FLOAD(index);
        case Const.T_DOUBLE:
            return new DLOAD(index);
        case Const.T_LONG:
            return new LLOAD(index);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return new ALOAD(index);
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 8
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayLoad( final Type type ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_BYTE:
            return InstructionConst.BALOAD;
        case Const.T_CHAR:
            return InstructionConst.CALOAD;
        case Const.T_SHORT:
            return InstructionConst.SALOAD;
        case Const.T_INT:
            return InstructionConst.IALOAD;
        case Const.T_FLOAT:
            return InstructionConst.FALOAD;
        case Const.T_DOUBLE:
            return InstructionConst.DALOAD;
        case Const.T_LONG:
            return InstructionConst.LALOAD;
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.AALOAD;
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 9
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayStore( final Type type ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_BYTE:
            return InstructionConst.BASTORE;
        case Const.T_CHAR:
            return InstructionConst.CASTORE;
        case Const.T_SHORT:
            return InstructionConst.SASTORE;
        case Const.T_INT:
            return InstructionConst.IASTORE;
        case Const.T_FLOAT:
            return InstructionConst.FASTORE;
        case Const.T_DOUBLE:
            return InstructionConst.DASTORE;
        case Const.T_LONG:
            return InstructionConst.LASTORE;
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.AASTORE;
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 10
Source File: BasicType.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
public static BasicType getType( final byte type ) {
    switch (type) {
        case Const.T_VOID:
            return VOID;
        case Const.T_BOOLEAN:
            return BOOLEAN;
        case Const.T_BYTE:
            return BYTE;
        case Const.T_SHORT:
            return SHORT;
        case Const.T_CHAR:
            return CHAR;
        case Const.T_INT:
            return INT;
        case Const.T_LONG:
            return LONG;
        case Const.T_DOUBLE:
            return DOUBLE;
        case Const.T_FLOAT:
            return FLOAT;
        default:
            throw new ClassGenException("Invalid type: " + type);
    }
}
 
Example 11
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Create "null" value for reference types, 0 for basic types like int
 */
public static Instruction createNull( final Type type ) {
    switch (type.getType()) {
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.ACONST_NULL;
        case Const.T_INT:
        case Const.T_SHORT:
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
            return InstructionConst.ICONST_0;
        case Const.T_FLOAT:
            return InstructionConst.FCONST_0;
        case Const.T_DOUBLE:
            return InstructionConst.DCONST_0;
        case Const.T_LONG:
            return InstructionConst.LCONST_0;
        case Const.T_VOID:
            return InstructionConst.NOP;
        default:
            throw new IllegalArgumentException("Invalid type: " + type);
    }
}
 
Example 12
Source File: Pass3aVerifier.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
@Override
public void visitNEWARRAY(final NEWARRAY o) {
    final byte t = o.getTypecode();
    if (!    (    (t == Const.T_BOOLEAN)    ||
                    (t == Const.T_CHAR)            ||
                    (t == Const.T_FLOAT)        ||
                    (t == Const.T_DOUBLE)        ||
                    (t == Const.T_BYTE)            ||
                    (t == Const.T_SHORT)        ||
                    (t == Const.T_INT)            ||
                    (t == Const.T_LONG)    )    ) {
        constraintViolated(o, "Illegal type code '+t+' for 'atype' operand.");
    }
}
 
Example 13
Source File: Utility.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Return type of signature as a byte value as defined in <em>Constants</em>
 *
 * @param  signature in format described above
 * @return type of signature
 * @see    Const
 *
 * @throws ClassFormatException if signature isn't a known type
 */
public static byte typeOfSignature( final String signature ) throws ClassFormatException {
    try {
        switch (signature.charAt(0)) {
            case 'B':
                return Const.T_BYTE;
            case 'C':
                return Const.T_CHAR;
            case 'D':
                return Const.T_DOUBLE;
            case 'F':
                return Const.T_FLOAT;
            case 'I':
                return Const.T_INT;
            case 'J':
                return Const.T_LONG;
            case 'L':
            case 'T':
                return Const.T_REFERENCE;
            case '[':
                return Const.T_ARRAY;
            case 'V':
                return Const.T_VOID;
            case 'Z':
                return Const.T_BOOLEAN;
            case 'S':
                return Const.T_SHORT;
            case '!':
            case '+':
            case '*':
                return typeOfSignature(signature.substring(1));
            default:
                throw new ClassFormatException("Invalid method signature: " + signature);
        }
    } catch (final StringIndexOutOfBoundsException e) {
        throw new ClassFormatException("Invalid method signature: " + signature, e);
    }
}
 
Example 14
Source File: Type.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * @return stack size of this type (2 for long and double, 0 for void, 1 otherwise)
 */
public int getSize() {
    switch (type) {
        case Const.T_DOUBLE:
        case Const.T_LONG:
            return 2;
        case Const.T_VOID:
            return 0;
        default:
            return 1;
    }
}
 
Example 15
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g.,
 * if the operands are basic types and CHECKCAST if they are reference types.
 */
public Instruction createCast( final Type src_type, final Type dest_type ) {
    if ((src_type instanceof BasicType) && (dest_type instanceof BasicType)) {
        final byte dest = dest_type.getType();
        byte src = src_type.getType();
        if (dest == Const.T_LONG
                && (src == Const.T_CHAR || src == Const.T_BYTE || src == Const.T_SHORT)) {
            src = Const.T_INT;
        }
        final String name = "org.apache.bcel.generic." + short_names[src - Const.T_CHAR] + "2"
                + short_names[dest - Const.T_CHAR];
        Instruction i = null;
        try {
            i = (Instruction) java.lang.Class.forName(name).newInstance();
        } catch (final Exception e) {
            throw new IllegalArgumentException("Could not find instruction: " + name, e);
        }
        return i;
    } else if ((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) {
        if (dest_type instanceof ArrayType) {
            return new CHECKCAST(cp.addArrayClass((ArrayType) dest_type));
        }
        return new CHECKCAST(cp.addClass(((ObjectType) dest_type).getClassName()));
    } else {
        throw new IllegalArgumentException("Cannot cast " + src_type + " to " + dest_type);
    }
}
 
Example 16
Source File: TypeAnalysis.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void initEntryFact(TypeFrame result) {
    // Make the frame valid
    result.setValid();

    int slot = 0;

    // Clear the stack slots in the frame
    result.clearStack();

    // Add local for "this" pointer, if present
    if (!methodGen.isStatic()) {
        result.setValue(slot++, ObjectTypeFactory.getInstance(methodGen.getClassName()));
    }

    // [Added: Support for Generics]
    // Get a parser that reads the generic signature of the method and
    // can be used to get the correct GenericObjectType if an argument
    // has a class type
    Iterator<String> iter = GenericSignatureParser.getGenericSignatureIterator(method);

    // Add locals for parameters.
    // Note that long and double parameters need to be handled
    // specially because they occupy two locals.
    Type[] argumentTypes = methodGen.getArgumentTypes();
    for (Type argType : argumentTypes) {
        // Add special "extra" type for long or double params.
        // These occupy the slot before the "plain" type.
        if (argType.getType() == Const.T_LONG) {
            result.setValue(slot++, TypeFrame.getLongExtraType());
        } else if (argType.getType() == Const.T_DOUBLE) {
            result.setValue(slot++, TypeFrame.getDoubleExtraType());
        }

        // [Added: Support for Generics]
        String s = (iter == null || !iter.hasNext()) ? null : iter.next();
        if (s != null && (argType instanceof ObjectType || argType instanceof ArrayType)
                && !(argType instanceof ExceptionObjectType)) {
            // replace with a generic version of the type
            try {
                Type t = GenericUtilities.getType(s);
                if (t != null) {
                    argType = t;
                }
            } catch (RuntimeException e) {
            } // degrade gracefully
        }

        // Add the plain parameter type.
        result.setValue(slot++, argType);
    }

    // Set remaining locals to BOTTOM; this will cause any
    // uses of them to be flagged
    while (slot < methodGen.getMaxLocals()) {
        result.setValue(slot++, TypeFrame.getBottomType());
    }
}
 
Example 17
Source File: FieldAccess.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Return whether the given FieldInstruction accesses a long or double
 * field.
 *
 * @param fieldIns
 *            the FieldInstruction
 * @param cpg
 *            the ConstantPoolGen for the method
 */
protected static boolean isLongOrDouble(FieldInstruction fieldIns, ConstantPoolGen cpg) {
    Type type = fieldIns.getFieldType(cpg);
    int code = type.getType();
    return code == Const.T_LONG || code == Const.T_DOUBLE;
}