コード例 #1
0
  private Node transform(JsFor x) {
    // The init expressions or var decl.
    //
    Node init;
    if (x.getInitExpr() != null) {
      init = transform(x.getInitExpr());
    } else if (x.getInitVars() != null) {
      init = transform(x.getInitVars());
    } else {
      init = IR.empty();
    }

    // The loop test.
    //
    Node cond;
    if (x.getCondition() != null) {
      cond = transform(x.getCondition());
    } else {
      cond = IR.empty();
    }

    // The incr expression.
    //
    Node incr;
    if (x.getIncrExpr() != null) {
      incr = transform(x.getIncrExpr());
    } else {
      incr = IR.empty();
    }

    Node body = transformBody(x.getBody(), x);
    Node n = IR.forNode(init, cond, incr, body);
    return applySourceInfo(n, x);
  }
コード例 #2
0
ファイル: CoverageVisitor.java プロジェクト: hammoum/gwt
  /**
   * This is essentially a hacked-up version of JsFor.traverse to account for flow control differing
   * from visitation order. It resets lastFile and lastLine before the condition and increment
   * expressions in the for loop so that location data will be recorded correctly.
   */
  @Override
  public boolean visit(JsFor x, JsContext ctx) {
    if (x.getInitExpr() != null) {
      x.setInitExpr(accept(x.getInitExpr()));
    } else if (x.getInitVars() != null) {
      x.setInitVars(accept(x.getInitVars()));
    }

    if (x.getCondition() != null) {
      resetPosition();
      x.setCondition(accept(x.getCondition()));
    }

    if (x.getIncrExpr() != null) {
      resetPosition();
      x.setIncrExpr(accept(x.getIncrExpr()));
    }
    accept(x.getBody());
    return false;
  }