Java Code Examples for com.sun.org.apache.bcel.internal.Constants#T_VOID

The following examples show how to use com.sun.org.apache.bcel.internal.Constants#T_VOID . 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: InstructionFactory.java    From jdk1.8-source-analysis with 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 2
Source File: BasicType.java    From openjdk-jdk8u with GNU General Public License v2.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 3
Source File: BasicType.java    From TencentKona-8 with GNU General Public License v2.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 4
Source File: InstructionFactory.java    From openjdk-jdk8u with GNU General Public License v2.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 5
Source File: BasicType.java    From hottub with GNU General Public License v2.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 6
Source File: Utility.java    From openjdk-8-source with GNU General Public License v2.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 7
Source File: Utility.java    From openjdk-8 with GNU General Public License v2.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 8
Source File: BasicType.java    From openjdk-jdk9 with GNU General Public License v2.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 9
Source File: BCELifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static String printType(String signature) {
  Type type = Type.getType(signature);
  byte t    = type.getType();

  if(t <= Constants.T_VOID) {
    return "Type." + Constants.TYPE_NAMES[t].toUpperCase();
  } else if(type.toString().equals("java.lang.String")) {
    return "Type.STRING";
  } else if(type.toString().equals("java.lang.Object")) {
    return "Type.OBJECT";
  } else if(type.toString().equals("java.lang.StringBuffer")) {
    return "Type.STRINGBUFFER";
  } else if(type instanceof ArrayType) {
    ArrayType at = (ArrayType)type;

    return "new ArrayType(" + printType(at.getBasicType()) +
      ", " + at.getDimensions() + ")";
  } else {
    return "new ObjectType(\"" + Utility.signatureToString(signature, false) +
      "\")";
  }
}
 
Example 10
Source File: InstructionFactory.java    From JDKSourceCode1.8 with MIT License 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 11
Source File: InstructionFactory.java    From jdk1.8-source-analysis 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(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 12
Source File: Type.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert signature to a Type object.
 * @param signature signature string such as Ljava/lang/String;
 * @return type object
 */
public static final Type getType(String signature)
  throws StringIndexOutOfBoundsException
{
  byte type = Utility.typeOfSignature(signature);

  if(type <= Constants.T_VOID) {
    consumed_chars = 1;
    return BasicType.getType(type);
  } else if(type == Constants.T_ARRAY) {
    int dim=0;
    do { // Count dimensions
      dim++;
    } while(signature.charAt(dim) == '[');

    // Recurse, but just once, if the signature is ok
    Type t = getType(signature.substring(dim));

    consumed_chars += dim; // update counter

    return new ArrayType(t, dim);
  } else { // type == T_REFERENCE
    int index = signature.indexOf(';'); // Look for closing `;'

    if(index < 0)
      throw new ClassFormatException("Invalid signature: " + signature);

    consumed_chars = index + 1; // "Lblabla;" `L' and `;' are removed

    return new ObjectType(signature.substring(1, index).replace('/', '.'));
  }
}
 
Example 13
Source File: ArrayType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor for array of given type
 *
 * @param type type of array (may be an array itself)
 */
public ArrayType(Type type, int dimensions) {
  super(Constants.T_ARRAY, "<dummy>");

  if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
    throw new ClassGenException("Invalid number of dimensions: " + dimensions);

  switch(type.getType()) {
  case Constants.T_ARRAY:
    ArrayType array = (ArrayType)type;
    this.dimensions = dimensions + array.dimensions;
    basic_type      = array.basic_type;
    break;

  case Constants.T_VOID:
    throw new ClassGenException("Invalid type: void[]");

  default: // Basic type or reference
    this.dimensions = dimensions;
    basic_type = type;
    break;
  }

  StringBuffer buf = new StringBuffer();
  for(int i=0; i < this.dimensions; i++)
    buf.append('[');

  buf.append(basic_type.getSignature());

  signature = buf.toString();
}
 
Example 14
Source File: Type.java    From TencentKona-8 with GNU General Public License v2.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 Constants.T_DOUBLE:
  case Constants.T_LONG: return 2;
  case Constants.T_VOID: return 0;
  default:     return 1;
  }
}
 
Example 15
Source File: ArrayType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor for array of given type
 *
 * @param type type of array (may be an array itself)
 */
public ArrayType(Type type, int dimensions) {
  super(Constants.T_ARRAY, "<dummy>");

  if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
    throw new ClassGenException("Invalid number of dimensions: " + dimensions);

  switch(type.getType()) {
  case Constants.T_ARRAY:
    ArrayType array = (ArrayType)type;
    this.dimensions = dimensions + array.dimensions;
    basic_type      = array.basic_type;
    break;

  case Constants.T_VOID:
    throw new ClassGenException("Invalid type: void[]");

  default: // Basic type or reference
    this.dimensions = dimensions;
    basic_type = type;
    break;
  }

  StringBuffer buf = new StringBuffer();
  for(int i=0; i < this.dimensions; i++)
    buf.append('[');

  buf.append(basic_type.getSignature());

  signature = buf.toString();
}
 
Example 16
Source File: Type.java    From jdk1.8-source-analysis 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 Constants.T_DOUBLE:
  case Constants.T_LONG: return 2;
  case Constants.T_VOID: return 0;
  default:     return 1;
  }
}
 
Example 17
Source File: Type.java    From JDKSourceCode1.8 with MIT License 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 Constants.T_DOUBLE:
  case Constants.T_LONG: return 2;
  case Constants.T_VOID: return 0;
  default:     return 1;
  }
}
 
Example 18
Source File: BasicType.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Constructor for basic types such as int, long, `void'
 *
 * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
 * @see com.sun.org.apache.bcel.internal.Constants
 */
BasicType(byte type) {
  super(type, Constants.SHORT_TYPE_NAMES[type]);

  if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID))
    throw new ClassGenException("Invalid type: " + type);
}
 
Example 19
Source File: Utility.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Parse Java type such as "char", or "java.lang.String[]" and return the
 * signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
 *
 * @param  type Java type
 * @return byte code signature
 */
public static String getSignature(String type) {
  StringBuffer buf        = new StringBuffer();
  char[]       chars      = type.toCharArray();
  boolean      char_found = false, delim = false;
  int          index      = -1;

loop:
  for(int i=0; i < chars.length; i++) {
    switch(chars[i]) {
    case ' ': case '\t': case '\n': case '\r': case '\f':
      if(char_found)
        delim = true;
      break;

    case '[':
      if(!char_found)
        throw new RuntimeException("Illegal type: " + type);

      index = i;
      break loop;

    default:
      char_found = true;
      if(!delim)
        buf.append(chars[i]);
    }
  }

  int brackets = 0;

  if(index > 0)
    brackets = countBrackets(type.substring(index));

  type = buf.toString();
  buf.setLength(0);

  for(int i=0; i < brackets; i++)
    buf.append('[');

  boolean found = false;

  for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) {
    if(Constants.TYPE_NAMES[i].equals(type)) {
      found = true;
      buf.append(Constants.SHORT_TYPE_NAMES[i]);
    }
  }

  if(!found) // Class name
    buf.append('L' + type.replace('.', '/') + ';');

  return buf.toString();
}
 
Example 20
Source File: Utility.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Parse Java type such as "char", or "java.lang.String[]" and return the
 * signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
 *
 * @param  type Java type
 * @return byte code signature
 */
public static String getSignature(String type) {
  StringBuffer buf        = new StringBuffer();
  char[]       chars      = type.toCharArray();
  boolean      char_found = false, delim = false;
  int          index      = -1;

loop:
  for(int i=0; i < chars.length; i++) {
    switch(chars[i]) {
    case ' ': case '\t': case '\n': case '\r': case '\f':
      if(char_found)
        delim = true;
      break;

    case '[':
      if(!char_found)
        throw new RuntimeException("Illegal type: " + type);

      index = i;
      break loop;

    default:
      char_found = true;
      if(!delim)
        buf.append(chars[i]);
    }
  }

  int brackets = 0;

  if(index > 0)
    brackets = countBrackets(type.substring(index));

  type = buf.toString();
  buf.setLength(0);

  for(int i=0; i < brackets; i++)
    buf.append('[');

  boolean found = false;

  for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) {
    if(Constants.TYPE_NAMES[i].equals(type)) {
      found = true;
      buf.append(Constants.SHORT_TYPE_NAMES[i]);
    }
  }

  if(!found) // Class name
    buf.append('L' + type.replace('.', '/') + ';');

  return buf.toString();
}