コード例 #1
0
  public Expression transform(UnaryMinusExpression exp, CompilerTransformer compiler) {
    final BytecodeExpr inner = (BytecodeExpr) compiler.transform(exp.getExpression());
    final ClassNode type = ClassHelper.getUnwrapper(inner.getType());
    if (type == ClassHelper.byte_TYPE
        || type == ClassHelper.short_TYPE
        || type == ClassHelper.int_TYPE
        || type == ClassHelper.long_TYPE
        || type == ClassHelper.float_TYPE
        || type == ClassHelper.double_TYPE) {
      return new BytecodeExpr(exp, type) {
        protected void compile(MethodVisitor mv) {
          inner.visit(mv);
          if (!ClassHelper.isPrimitiveType(inner.getType())) unbox(type, mv);

          if (type == ClassHelper.int_TYPE
              || type == ClassHelper.short_TYPE
              || type == ClassHelper.byte_TYPE) mv.visitInsn(INEG);
          else if (type == ClassHelper.long_TYPE) mv.visitInsn(LNEG);
          else if (type == ClassHelper.float_TYPE) mv.visitInsn(FNEG);
          else if (type == ClassHelper.double_TYPE) mv.visitInsn(DNEG);
        }
      };
    } else {
      MethodCallExpression negate =
          new MethodCallExpression(inner, "negate", new ArgumentListExpression());
      negate.setSourcePosition(exp);
      return compiler.transform(negate);
    }
  }
コード例 #2
0
    @Override
    public void visitUnaryMinusExpression(UnaryMinusExpression expression) {
      // LOG.debug "Transforming expression '${expression}':"

      if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
        // LOG.debug "   start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber
        // - 1]}"
        expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
      }

      if (expression.getLastLineNumber() > 0
          && expression.getLastLineNumber() < lineNumbers.length) {
        // LOG.debug "   end from ${expression.lastLineNumber} to
        // ${lineNumbers[expression.lastLineNumber - 1]}"
        expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
      }
      super.visitUnaryMinusExpression(expression);
    }
コード例 #3
0
 public void visitUnaryMinusExpression(UnaryMinusExpression expression) {
   expression.getExpression().visit(this);
 }