Пример #1
0
 /**
  * Translates an integer into the Java type denoted by <code>clazz</code>. Expects an integer on
  * the stack and pushes a number of the appropriate type after coercion.
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) {
   final InstructionList il = methodGen.getInstructionList();
   if (clazz == Character.TYPE) {
     il.append(I2C);
   } else if (clazz == Byte.TYPE) {
     il.append(I2B);
   } else if (clazz == Short.TYPE) {
     il.append(I2S);
   } else if (clazz == Integer.TYPE) {
     il.append(NOP);
   } else if (clazz == Long.TYPE) {
     il.append(I2L);
   } else if (clazz == Float.TYPE) {
     il.append(I2F);
   } else if (clazz == Double.TYPE) {
     il.append(I2D);
   }
   // Is Double <: clazz? I.e. clazz in { Double, Number, Object }
   else if (clazz.isAssignableFrom(java.lang.Double.class)) {
     il.append(I2D);
     Type.Real.translateTo(classGen, methodGen, Type.Reference);
   } else {
     ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName());
     classGen.getParser().reportError(Constants.FATAL, err);
   }
 }
Пример #2
0
 /** Translates an object of this type to its unboxed representation. */
 public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) {
   final ConstantPoolGen cpg = classGen.getConstantPool();
   final InstructionList il = methodGen.getInstructionList();
   il.append(new CHECKCAST(cpg.addClass(INTEGER_CLASS)));
   final int index = cpg.addMethodref(INTEGER_CLASS, INT_VALUE, INT_VALUE_SIG);
   il.append(new INVOKEVIRTUAL(index));
 }
Пример #3
0
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    _left.translate(classGen, methodGen);
    _right.translate(classGen, methodGen);

    switch (_op) {
      case PLUS:
        il.append(_type.ADD());
        break;
      case MINUS:
        il.append(_type.SUB());
        break;
      case TIMES:
        il.append(_type.MUL());
        break;
      case DIV:
        il.append(_type.DIV());
        break;
      case MOD:
        il.append(_type.REM());
        break;
      default:
        ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
        getParser().reportError(Constants.ERROR, msg);
    }
  }
Пример #4
0
 /**
  * Expects an integer on the stack and pushes a boxed integer. Boxed integers are represented by
  * an instance of <code>java.lang.Integer</code>.
  *
  * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) {
   final ConstantPoolGen cpg = classGen.getConstantPool();
   final InstructionList il = methodGen.getInstructionList();
   il.append(new NEW(cpg.addClass(INTEGER_CLASS)));
   il.append(DUP_X1);
   il.append(SWAP);
   il.append(new INVOKESPECIAL(cpg.addMethodref(INTEGER_CLASS, "<init>", "(I)V")));
 }
Пример #5
0
 /**
  * Expects an integer on the stack and pushes a 0 if its value is 0 and a 1 otherwise.
  *
  * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) {
   final InstructionList il = methodGen.getInstructionList();
   final BranchHandle falsec = il.append(new IFEQ(null));
   il.append(ICONST_1);
   final BranchHandle truec = il.append(new GOTO(null));
   falsec.setTarget(il.append(ICONST_0));
   truec.setTarget(il.append(NOP));
 }
Пример #6
0
 /**
  * Expects an integer on the stack and translates it to a non-synthesized boolean. It does not
  * push a 0 or a 1 but instead returns branchhandle list to be appended to the false list.
  *
  * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
  */
 public FlowList translateToDesynthesized(
     ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) {
   final InstructionList il = methodGen.getInstructionList();
   return new FlowList(il.append(new IFEQ(null)));
 }
Пример #7
0
 /**
  * Expects an integer on the stack and pushes its string value by calling <code>
  * Integer.toString(int i)</code>.
  *
  * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
   final ConstantPoolGen cpg = classGen.getConstantPool();
   final InstructionList il = methodGen.getInstructionList();
   il.append(new INVOKESTATIC(cpg.addMethodref(INTEGER_CLASS, "toString", "(I)" + STRING_SIG)));
 }
Пример #8
0
 /**
  * Expects an integer on the stack and pushes a real.
  *
  * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, RealType type) {
   methodGen.getInstructionList().append(I2D);
 }
 /**
  * Translates a void into a string by pushing the empty string ''.
  *
  * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
  */
 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
   final InstructionList il = methodGen.getInstructionList();
   il.append(new PUSH(classGen.getConstantPool(), ""));
 }