Java Code Examples for org.apache.bcel.Constants#T_INT

The following examples show how to use org.apache.bcel.Constants#T_INT . 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: ApkToolPlus   File: FieldGen.java    License: Apache License 2.0 6 votes vote down vote up
private int addConstant() {
	switch (type.getType()) {
	case Constants.T_INT:
	case Constants.T_CHAR:
	case Constants.T_BYTE:
	case Constants.T_BOOLEAN:
	case Constants.T_SHORT:
		return cp.addInteger(((Integer) value).intValue());

	case Constants.T_FLOAT:
		return cp.addFloat(((Float) value).floatValue());

	case Constants.T_DOUBLE:
		return cp.addDouble(((Double) value).doubleValue());

	case Constants.T_LONG:
		return cp.addLong(((Long) value).longValue());

	case Constants.T_REFERENCE:
		return cp.addString(((String) value));

	default:
		throw new RuntimeException("Oops: Unhandled : " + type.getType());
	}
}
 
Example 2
Source Project: ApkToolPlus   File: InstructionFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Instruction createAppend(Type type) {
  byte t = type.getType();

  if(isString(type))
    return createInvoke(append_mos[0], Constants.INVOKEVIRTUAL);

  switch(t) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR: 
  case Constants.T_FLOAT:
  case Constants.T_DOUBLE:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:
  case Constants.T_LONG
    :   return createInvoke(append_mos[t], Constants.INVOKEVIRTUAL);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT:
    return createInvoke(append_mos[1], Constants.INVOKEVIRTUAL);
  default:
    throw new RuntimeException("Oops: No append for this type? " + type);
  }
}
 
Example 3
Source Project: ApkToolPlus   File: InstructionFactory.java    License: Apache License 2.0 6 votes vote down vote up
/** Create typed return
 */
public static ReturnInstruction createReturn(Type type) {
  switch(type.getType()) {
  case Constants.T_ARRAY:
  case Constants.T_OBJECT:  return ARETURN;
  case Constants.T_INT:
  case Constants.T_SHORT:
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR: 
  case Constants.T_BYTE:    return IRETURN;
  case Constants.T_FLOAT:   return FRETURN;
  case Constants.T_DOUBLE:  return DRETURN;
  case Constants.T_LONG:    return LRETURN;
  case Constants.T_VOID:    return RETURN;

  default:
    throw new RuntimeException("Invalid type: " + type);
  }
}
 
Example 4
Source Project: ApkToolPlus   File: InstructionFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createStore(Type type, int index) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:    return new ISTORE(index);
  case Constants.T_FLOAT:  return new FSTORE(index);
  case Constants.T_DOUBLE: return new DSTORE(index);
  case Constants.T_LONG:   return new LSTORE(index);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return new ASTORE(index);
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example 5
Source Project: ApkToolPlus   File: InstructionFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createLoad(Type type, int index) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:    return new ILOAD(index);
  case Constants.T_FLOAT:  return new FLOAD(index);
  case Constants.T_DOUBLE: return new DLOAD(index);
  case Constants.T_LONG:   return new LLOAD(index);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return new ALOAD(index);
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example 6
Source Project: ApkToolPlus   File: InstructionFactory.java    License: 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(Type type) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_BYTE:   return BALOAD;
  case Constants.T_CHAR:   return CALOAD;
  case Constants.T_SHORT:  return SALOAD;
  case Constants.T_INT:    return IALOAD;
  case Constants.T_FLOAT:  return FALOAD;
  case Constants.T_DOUBLE: return DALOAD;
  case Constants.T_LONG:   return LALOAD;
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return AALOAD;
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example 7
Source Project: ApkToolPlus   File: InstructionFactory.java    License: 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(Type type) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_BYTE:   return BASTORE;
  case Constants.T_CHAR:   return CASTORE;
  case Constants.T_SHORT:  return SASTORE;
  case Constants.T_INT:    return IASTORE;
  case Constants.T_FLOAT:  return FASTORE;
  case Constants.T_DOUBLE: return DASTORE;
  case Constants.T_LONG:   return LASTORE;
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return AASTORE;
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example 8
Source Project: ApkToolPlus   File: InstructionFactory.java    License: 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(Type type) {
  switch(type.getType()) {
  case Constants.T_ARRAY:
  case Constants.T_OBJECT:  return ACONST_NULL;
  case Constants.T_INT:
  case Constants.T_SHORT:
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR: 
  case Constants.T_BYTE:    return ICONST_0;
  case Constants.T_FLOAT:   return FCONST_0;
  case Constants.T_DOUBLE:  return DCONST_0;
  case Constants.T_LONG:    return LCONST_0;
  case Constants.T_VOID:    return NOP;

  default:
    throw new RuntimeException("Invalid type: " + type);
  }
}
 
Example 9
Source Project: ApkToolPlus   File: BasicType.java    License: Apache License 2.0 6 votes vote down vote up
public static final BasicType getType(byte type) {
  switch(type) {
  case Constants.T_VOID:    return VOID;
  case Constants.T_BOOLEAN: return BOOLEAN;
  case Constants.T_BYTE:    return BYTE;
  case Constants.T_SHORT:   return SHORT;
  case Constants.T_CHAR:    return CHAR;
  case Constants.T_INT:     return INT;
  case Constants.T_LONG:    return LONG;
  case Constants.T_DOUBLE:  return DOUBLE;
  case Constants.T_FLOAT:   return FLOAT;

  default:
    throw new ClassGenException("Invalid type: " + type);
  }
}
 
Example 10
Source Project: ApkToolPlus   File: Utility.java    License: Apache License 2.0 6 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    Constants
  */
 public static final byte typeOfSignature(String signature)
   throws ClassFormatException
 {
   try {
     switch(signature.charAt(0)) {
     case 'B' : return Constants.T_BYTE;
     case 'C' : return Constants.T_CHAR;
     case 'D' : return Constants.T_DOUBLE;
     case 'F' : return Constants.T_FLOAT;
     case 'I' : return Constants.T_INT;
     case 'J' : return Constants.T_LONG;
     case 'L' : return Constants.T_REFERENCE;
     case '[' : return Constants.T_ARRAY;
     case 'V' : return Constants.T_VOID;
     case 'Z' : return Constants.T_BOOLEAN;
     case 'S' : return Constants.T_SHORT;
     default:  
throw new ClassFormatException("Invalid method signature: " + signature);
     }
   } catch(StringIndexOutOfBoundsException e) {
     throw new ClassFormatException("Invalid method signature: " + signature);
   }
 }
 
Example 11
Source Project: ApkToolPlus   File: InstructionFactory.java    License: Apache License 2.0 5 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(String op, Type type) {
  char first = op.toCharArray()[0];

  switch(type.getType()) {
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:
  case Constants.T_CHAR:    return createBinaryIntOp(first, op);
  case Constants.T_LONG:    return createBinaryLongOp(first, op);
  case Constants.T_FLOAT:   return createBinaryFloatOp(first);
  case Constants.T_DOUBLE:  return createBinaryDoubleOp(first);
  default:        throw new RuntimeException("Invalid type " + type);
  }
}
 
Example 12
Source Project: ApkToolPlus   File: InstructionFactory.java    License: 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(Type src_type, Type dest_type) {
   if((src_type instanceof BasicType) && (dest_type instanceof BasicType)) {
     byte dest = dest_type.getType();
     byte src  = src_type.getType();

     if(dest == Constants.T_LONG && (src == Constants.T_CHAR || src == Constants.T_BYTE ||
			      src == Constants.T_SHORT))
src = Constants.T_INT;

     String[] short_names = { "C", "F", "D", "B", "S", "I", "L" };

     String name = "org.apache.bcel.generic." + short_names[src - Constants.T_CHAR] +
"2" + short_names[dest - Constants.T_CHAR];
     
     Instruction i = null;
     try {
i = (Instruction) Class.forName(name).newInstance();
     } catch(Exception e) {
throw new RuntimeException("Could not find instruction: " + name);
     }

     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));
     else
return new CHECKCAST(cp.addClass(((ObjectType)dest_type).getClassName()));
   }
   else
     throw new RuntimeException("Can not cast " + src_type + " to " + dest_type);
 }