Package com.google.gwt.dev.jjs.ast

Examples of com.google.gwt.dev.jjs.ast.JBinaryOperation


             */
            lhs = maskUndefined(lhs);
            rhs = maskUndefined(rhs);
          }

          JBinaryOperation binOp =
              new JBinaryOperation(x.getSourceInfo(), x.getType(), x.getOp(), lhs, rhs);
          ctx.replaceMe(binOp);
          break;
        }

        case STRAT_DOUBLE: {
View Full Code Here


      switch (analysisResult) {
        case TRUE:
          if (x.getExpr().getType().canBeNull()) {
          // replace with a simple null test
            JBinaryOperation neq =
                new JBinaryOperation(x.getSourceInfo(), program.getTypePrimitiveBoolean(),
                    JBinaryOperator.NEQ, x.getExpr(), program.getLiteralNull());
            ctx.replaceMe(neq);
          } else {
            ctx.replaceMe(
                JjsUtils.createOptimizedMultiExpression(x.getExpr(),
View Full Code Here

      // TODO(spoon): immediately simplify the newMulti
      return newMulti;
    }
    if (arg instanceof JBinaryOperation) {
      // try to invert the binary operator
      JBinaryOperation argOp = (JBinaryOperation) arg;
      JBinaryOperator op = argOp.getOp();
      JBinaryOperator newOp = null;
      if (op == JBinaryOperator.EQ) {
        // e.g. !(x == y) -> x != y
        newOp = JBinaryOperator.NEQ;
      } else if (op == JBinaryOperator.NEQ) {
        // e.g. !(x != y) -> x == y
        newOp = JBinaryOperator.EQ;
      } else if (op == JBinaryOperator.GT) {
        // e.g. !(x > y) -> x <= y
        newOp = JBinaryOperator.LTE;
      } else if (op == JBinaryOperator.LTE) {
        // e.g. !(x <= y) -> x > y
        newOp = JBinaryOperator.GT;
      } else if (op == JBinaryOperator.GTE) {
        // e.g. !(x >= y) -> x < y
        newOp = JBinaryOperator.LT;
      } else if (op == JBinaryOperator.LT) {
        // e.g. !(x < y) -> x >= y
        newOp = JBinaryOperator.GTE;
      }
      if (newOp != null) {
        JBinaryOperation newBinOp =
            new JBinaryOperation(info, argOp.getType(), newOp, argOp.getLhs(), argOp.getRhs());
        return newBinOp;
      }
    } else if (arg instanceof JPrefixOperation) {
      // try to invert the unary operator
      JPrefixOperation argOp = (JPrefixOperation) arg;
View Full Code Here

    }
    // no simplification made
    if (original != null) {
      return original;
    }
    return new JBinaryOperation(info, rhs.getType(), JBinaryOperator.AND, lhs, rhs);
  }
View Full Code Here

    }
    // no simplification made
    if (original != null) {
      return original;
    }
    return new JBinaryOperation(info, rhs.getType(), JBinaryOperator.OR, lhs, rhs);
  }
View Full Code Here

        if (unflipExpression != null) {
          condExpr = unflipExpression;
          binaryOperator = JBinaryOperator.OR;
        }

        JBinaryOperation binaryOperation =
            new JBinaryOperation(sourceInfo, JPrimitiveType.VOID, binaryOperator, condExpr,
                thenExpression);

        return binaryOperation.makeStatement();
      }
    }

    return null;
  }
View Full Code Here

    }
    // Assignment-to-cast-operation, e.g.
    // (Foo) x = foo -> x = foo
    // (Foo) x += foo -> x += foo
    JCastOperation cast = (JCastOperation) x.getLhs();
    return new JBinaryOperation(x.getSourceInfo(), x.getType(), x.getOp(), cast.getExpr(),
            x.getRhs());
  }
View Full Code Here

    }

    // Assignment-to-unbox, e.g.
    // unbox(x) = foo -> x = box(foo)
    JClassType boxedType = (JClassType) boxed.getType();
    return  new JBinaryOperation(x.getSourceInfo(), boxedType, x.getOp(), boxed,
        autoboxUtils.box(x.getRhs(), (JPrimitiveType) lhs.getType()));
  }
View Full Code Here

  public void endVisit(JBinaryOperation x, Context ctx) {
    if (!x.isAssignment()) {
      return;
    }

    JBinaryOperation result = maybeFixLhsCast(maybeUndoBox(x));

    if (result != x) {
      ctx.replaceMe(result);
    }
  }
View Full Code Here

        // removed anyway.

        List<JExpression> expressions = ((JMultiExpression) lhs).getExpressions();
        JMultiExpression result = new JMultiExpression(lhs.getSourceInfo(),
            expressions.subList(0, expressions.size() - 1));
        result.addExpressions(new JBinaryOperation(x.getSourceInfo(), x.getType(), x.getOp(),
            expressions.get(expressions.size() - 1), rhs));
        ctx.replaceMe(result);
        return;
      }

      if (isNonEmptyMultiExpression(rhs) &&  lhs instanceof JValueLiteral &&
          op != JBinaryOperator.AND && op != JBinaryOperator.OR) {
        // Push the operation inside the multiexpression if the lhs is a value literal.
        // This exposes other optimization opportunities for latter passes e.g:
        //
        // 2 + (a(), b(), 1) ==> (a(), b(), 2 + 1) ==> (a(), b(), 3)
        //
        // And exception must be made for || and &&, as these operations might not evaluate the
        // rhs due to shortcutting.
        List<JExpression> expressions = ((JMultiExpression) rhs).getExpressions();
        JMultiExpression result = new JMultiExpression(rhs.getSourceInfo(),
            expressions.subList(0, expressions.size() - 1));
        result.addExpressions(new JBinaryOperation(x.getSourceInfo(), x.getType(), x.getOp(),
            lhs, expressions.get(expressions.size() - 1)));
        ctx.replaceMe(result);
        return;
      }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JBinaryOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.