Package com.google.gwt.dev.js.ast

Examples of com.google.gwt.dev.js.ast.JsBinaryOperation


      if (!x.getArg1().hasSideEffects()) {
        ctx.replaceMe(x.getArg2());
        return;
      }

      JsBinaryOperation toUpdate = isComma(x.getArg2());
      if (toUpdate == null) {
        /*
         * We have a JsBinaryOperation that's structurally normal: (X, a). Now
         * it may be the case that the inner expression X is a comma expression
         * (Y, b). If b creates no side-effects, we can remove it, leaving (Y,
         * a) as the expression.
         */
        JsBinaryOperation inner = isComma(x.getArg1());
        if (inner != null && !inner.getArg2().hasSideEffects()) {
          x.setArg1(inner.getArg1());
          didChange = true;
        }
        return;
      }

      // Find the left-most, nested comma expression
      while (isComma(toUpdate.getArg1()) != null) {
        toUpdate = (JsBinaryOperation) toUpdate.getArg1();
      }

      /*
       * Create a new comma expression with the original LHS and the LHS of the
       * nested comma expression.
       */
      JsBinaryOperation newOp = new JsBinaryOperation(JsBinaryOperator.COMMA);
      newOp.setArg1(x.getArg1());
      newOp.setArg2(toUpdate.getArg1());

      // Set the LHS of the nested comma expression to the new comma expression
      toUpdate.setArg1(newOp);

      // Replace the original node with its updated RHS
View Full Code Here


       * Assemble the expressions back into a list of JsExprStmts. We will
       * iteratively disassemble the nested comma expressions, stopping when the
       * LHS is not a comma expression.
       */
      while (e instanceof JsBinaryOperation) {
        JsBinaryOperation op = (JsBinaryOperation) e;

        if (!op.getOperator().equals(JsBinaryOperator.COMMA)) {
          break;
        }

        /*
         * We can ignore intermediate expressions as long as they have no
         * side-effects.
         */
        if (op.getArg2().hasSideEffects()) {
          statements.add(0, new JsExprStmt(op.getArg2()));
        }

        e = op.getArg1();
      }

      /*
       * We know the return value from the original invocation was ignored, so
       * it may be possible to ignore the final expressions as long as it has no
View Full Code Here

       * expression.
       */
      ListIterator<JsExpression> i = hoisted.listIterator(hoisted.size());
      JsExpression op = i.previous();
      while (i.hasPrevious()) {
        JsBinaryOperation outerOp = new JsBinaryOperation(
            JsBinaryOperator.COMMA);
        outerOp.setArg1(i.previous());
        outerOp.setArg2(op);
        op = outerOp;
      }

      // Confirm that the expression conforms to the desired heuristics
      if (!isInlinable(program, functionStack.peek(), x, f, op)) {
View Full Code Here

      for (JsVar var : vars) {
        // Extract the initialization expression
        JsExpression init = var.getInitExpr();
        if (init != null) {
          SourceInfo sourceInfo = var.getSourceInfo();
          JsBinaryOperation assignment = new JsBinaryOperation(sourceInfo,
              JsBinaryOperator.ASG);
          assignment.setArg1(var.getName().makeRef(sourceInfo));
          assignment.setArg2(init);

          // Multiple initializers go into a comma expression
          JsBinaryOperation comma = new JsBinaryOperation(sourceInfo,
              JsBinaryOperator.COMMA);
          comma.setArg1(expression);
          comma.setArg2(assignment);
          expression = comma;
        }
      }
    } else {
      return null;
View Full Code Here

      }

      SourceInfo sourceInfo = x.getSourceInfo();
      JsExpression lhs = x.getArg1();
      JsExpression rhs = x.getArg2();
      JsExpression newNode = new JsBinaryOperation(sourceInfo, op,
          new JsPrefixOperation(sourceInfo, JsUnaryOperator.BIT_NOT,
              new JsPrefixOperation(sourceInfo, JsUnaryOperator.BIT_NOT, lhs)),
          rhs);
      ctx.replaceMe(newNode);
    }
View Full Code Here

  private void addBeforeUnloadListener(SourceInfo info) {
    JsNameRef onbeforeunload = new JsNameRef(info, "onbeforeunload");
    onbeforeunload.setQualifier(new JsNameRef(info, "window"));
    JsNameRef handler =
        jsProgram.getIndexedFunction("CoverageUtil.onBeforeUnload").getName().makeRef(info);
    JsBinaryOperation assignment = new JsBinaryOperation(info, JsBinaryOperator.ASG,
        onbeforeunload, handler);
    jsProgram.getGlobalBlock().getStatements().add(assignment.makeStmt());
  }
View Full Code Here

    }.accept(jsProgram);
  }

  private void initializeBaselineCoverage(SourceInfo info) {
    JsNameRef coverageObject = jsProgram.getIndexedField("CoverageUtil.coverage").makeRef(info);
    JsBinaryOperation init = new JsBinaryOperation(info, JsBinaryOperator.ASG, coverageObject,
        baselineCoverage(info, instrumentableLines));
    jsProgram.getGlobalBlock().getStatements().add(init.makeStmt());
  }
View Full Code Here

      }
      JsInvocation update = new JsInvocation(info,
          jsProgram.getIndexedFunction("CoverageUtil.cover"),
          new JsStringLiteral(info, info.getFileName()),
          new JsNumberLiteral(info, info.getStartLine()));
      ctx.replaceMe(new JsBinaryOperation(info, JsBinaryOperator.COMMA, update, x));
    }
View Full Code Here

       * Assemble the expressions back into a list of JsExprStmts. We will
       * iteratively disassemble the nested comma expressions, stopping when the
       * LHS is not a comma expression.
       */
      while (e instanceof JsBinaryOperation) {
        JsBinaryOperation op = (JsBinaryOperation) e;

        if (!op.getOperator().equals(JsBinaryOperator.COMMA)) {
          break;
        }

        /*
         * We can ignore intermediate expressions as long as they have no
         * side-effects.
         */
        if (op.getArg2().hasSideEffects()) {
          statements.add(0, op.getArg2().makeStmt());
        }

        e = op.getArg1();
      }

      /*
       * We know the return value from the original invocation was ignored, so
       * it may be possible to ignore the final expressions as long as it has no
View Full Code Here

       */
      SourceInfo sourceInfo = x.getSourceInfo();
      ListIterator<JsExpression> i = hoisted.listIterator(hoisted.size());
      JsExpression op = i.previous();
      while (i.hasPrevious()) {
        JsBinaryOperation outerOp = new JsBinaryOperation(sourceInfo,
            JsBinaryOperator.COMMA);
        outerOp.setArg1(i.previous());
        outerOp.setArg2(op);
        op = outerOp;
      }

      // Confirm that the expression conforms to the desired heuristics
      if (!isInlinable(callerFunction, invokedFunction, thisExpr,
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.js.ast.JsBinaryOperation

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.