Пример #1
0
  /**
   * Generates a bytecode sequence to convert a value of this type to the specified destination
   * type.
   *
   * @param dest the destination type
   * @param code the code sequence
   */
  public void genCastTo(CNumericType dest, GenerationContext context) {
    CodeSequence code = context.getCodeSequence();

    if (dest != this) {
      switch (dest.type) {
        case TID_BYTE:
          code.plantNoArgInstruction(opc_i2b);
          break;

        case TID_SHORT:
          code.plantNoArgInstruction(opc_i2s);
          break;

        case TID_INT:
          break;

        case TID_LONG:
          code.plantNoArgInstruction(opc_i2l);
          break;

        case TID_FLOAT:
          code.plantNoArgInstruction(opc_i2f);
          break;

        case TID_DOUBLE:
          code.plantNoArgInstruction(opc_i2d);
          break;

        default:
          throw new InconsistencyException();
      }
    }
  }