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

The following examples show how to use org.apache.bcel.Const#T_BYTE . 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: 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 2
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 3
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 4
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 5
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 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 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 7
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 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 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 9
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 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 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 12
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 13
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 14
Source File: StandardTypeMerger.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Determine if the given typecode refers to an Integer type (other than
 * long). This implementation checks that the type code is T_INT, T_BYTE,
 * T_BOOLEAN, T_CHAR, or T_SHORT. Subclasses should override this if they
 * have defined new integer types with different type codes.
 */
protected boolean isIntegerType(byte type) {
    return type == Const.T_INT || type == Const.T_BYTE || type == Const.T_BOOLEAN || type == Const.T_CHAR || type == Const.T_SHORT;
}