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

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


     * Short circuit binary operations.
     */
    @Override
    public void endVisit(JBinaryOperation x, Context ctx) {
      JBinaryOperator op = x.getOp();
      JExpression lhs = x.getLhs();
      JExpression rhs = x.getRhs();
      if ((lhs instanceof JValueLiteral) && (rhs instanceof JValueLiteral)) {
        if (evalOpOnLiterals(op, (JValueLiteral) lhs, (JValueLiteral) rhs, ctx)) {
          return;
        }
      }
      switch (op) {
        case AND:
          shortCircuitAnd(lhs, rhs, ctx);
          break;
        case OR:
          shortCircuitOr(lhs, rhs, ctx);
          break;
        case BIT_XOR:
          simplifyXor(lhs, rhs, ctx);
          break;
        case EQ:
          // simplify: null == null -> true
          if (lhs.getType() == program.getTypeNull()
              && rhs.getType() == program.getTypeNull() && !x.hasSideEffects()) {
            ctx.replaceMe(program.getLiteralBoolean(true));
            return;
          }
          simplifyEq(lhs, rhs, ctx, false);
          break;
        case NEQ:
          // simplify: null != null -> false
          if (lhs.getType() == program.getTypeNull()
              && rhs.getType() == program.getTypeNull() && !x.hasSideEffects()) {
            ctx.replaceMe(program.getLiteralBoolean(false));
            return;
          }
          simplifyEq(lhs, rhs, ctx, true);
          break;
View Full Code Here


      }
    }

    @Override
    public void endVisit(JCastOperation x, Context ctx) {
      JExpression updated = simplifier.cast(x, x.getSourceInfo(),
          x.getCastType(), x.getExpr());
      if (updated != x) {
        ctx.replaceMe(updated);
      }
    }
View Full Code Here

      // previously set currentClass = null;
    }

    @Override
    public void endVisit(JConditional x, Context ctx) {
      JExpression updated = simplifier.conditional(x, x.getSourceInfo(),
          x.getType(), x.getIfTest(), x.getThenExpr(), x.getElseExpr());
      if (updated != x) {
        ctx.replaceMe(updated);
      }
    }
View Full Code Here

    /**
     * Convert do { } while (false); into a block.
     */
    @Override
    public void endVisit(JDoStatement x, Context ctx) {
      JExpression expression = x.getTestExpr();
      if (expression instanceof JBooleanLiteral) {
        JBooleanLiteral booleanLiteral = (JBooleanLiteral) expression;

        // If false, replace do with do's body
        if (!booleanLiteral.getValue()) {
View Full Code Here

       */
      // We can inline the constant, but we might also need to evaluate an
      // instance and run a clinit.
      JMultiExpression multi = new JMultiExpression(x.getSourceInfo());

      JExpression instance = x.getInstance();
      if (instance != null) {
        multi.exprs.add(instance);
      }

      JMethodCall clinit = maybeCreateClinitCall(x);
View Full Code Here

    /**
     * Prune for (X; false; Y) statements, but make sure X is run.
     */
    @Override
    public void endVisit(JForStatement x, Context ctx) {
      JExpression expression = x.getTestExpr();
      if (expression instanceof JBooleanLiteral) {
        JBooleanLiteral booleanLiteral = (JBooleanLiteral) expression;

        // If false, replace the for statement with its initializers
        if (!booleanLiteral.getValue()) {
View Full Code Here

        ignoringExpressionOutput.remove(x.getInstance());
      }

      int paramCount = target.getParams().size();
      for (int i = paramCount; i < x.getArgs().size(); ++i) {
        JExpression arg = x.getArgs().get(i);
        ignoringExpressionOutput.remove(arg);
        if (!arg.hasSideEffects()) {
          x.removeArg(i--);
          didChange = true;
        }
      }
View Full Code Here

        List<JExpression> nonFinalChildren = exprs.subList(0, exprs.size() - 1);
        ignoringExpressionOutput.removeAll(nonFinalChildren);
      }

      for (int i = 0; i < numRemovableExpressions(x); ++i) {
        JExpression expr = x.exprs.get(i);
        if (!expr.hasSideEffects()) {
          x.exprs.remove(i);
          --i;
          didChange = true;
          continue;
        }
View Full Code Here

        if (evalOpOnLiteral(x.getOp(), (JValueLiteral) x.getArg(), ctx)) {
          return;
        }
      }
      if (x.getOp() == JUnaryOperator.NOT) {
        JExpression updated = simplifier.not(x, x.getSourceInfo(), x.getArg());
        if (updated != x) {
          ctx.replaceMe(updated);
        }
        return;
      } else if (x.getOp() == JUnaryOperator.NEG) {
        JExpression updated = simplifyNegate(x, x.getArg());
        if (updated != x) {
          ctx.replaceMe(updated);
        }
      }
    }
View Full Code Here

    /**
     * Prune while (false) statements.
     */
    @Override
    public void endVisit(JWhileStatement x, Context ctx) {
      JExpression expression = x.getTestExpr();
      if (expression instanceof JBooleanLiteral) {
        JBooleanLiteral booleanLiteral = (JBooleanLiteral) expression;

        // If false, prune the while statement
        if (!booleanLiteral.getValue()) {
View Full Code Here

TOP

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

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.