Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.Operation.children()


      }
      if (!(first instanceof ExpressionStmt)) { break; }
      Expression e = ((ExpressionStmt) first).getExpression();
      if (!Operation.is(e, Operator.ASSIGN)) { break; }
      Operation op = (Operation) e;
      Expression lhs = op.children().get(0);
      if (!(lhs instanceof Reference)) { break; }
      Reference r = (Reference) lhs;
      if (!unassigned.contains(r.getIdentifier())) { break; }
      // Don't return two with the same name, because we don't want to have
      // multiple var declarations for the same name.
View Full Code Here


    } else if (n instanceof Reference) {
      String name = ((Reference) n).getIdentifierName();
      if (isOuter(name, s)) { outers.add(name); }
    } else if (Operation.is(n, Operator.MEMBER_ACCESS)) {
      Operation op = (Operation) n;
      checkScope(op.children().get(0), s, outers);
      return;
    }
    for (ParseTreeNode child : n.children()) {
      checkScope(child, childScope, outers);
    }
View Full Code Here

  static boolean isStringy(Expression e, boolean strict) {
    if (e instanceof StringLiteral) { return true; }
    if (e instanceof Operation) {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      switch (op.getOperator()) {
        case ADDITION:
          return isStringy(operands.get(0), false)
              || isStringy(operands.get(1), false);
        case TERNARY:
View Full Code Here

    if (isStringy(e, strict)) { return e; }

    Expression stringier = null;
    if (e instanceof Operation) {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      switch (op.getOperator()) {
        // Change arguments to ||,&& would change semantics.
        case TERNARY:
          stringier = Operation.create(
              e.getFilePosition(), Operator.TERNARY, operands.get(0),
View Full Code Here

  }

  static boolean isStringConcat(Expression e) {
    if (!is(e, Operator.ADDITION)) { return false; }
    Operation op = (Operation) e;
    return isStringy(op.children().get(0), false)
        || isStringy(op.children().get(1), false);
  }

  static String asString(Literal l) {
    if (l instanceof NumberLiteral) {
View Full Code Here

  static boolean isStringConcat(Expression e) {
    if (!is(e, Operator.ADDITION)) { return false; }
    Operation op = (Operation) e;
    return isStringy(op.children().get(0), false)
        || isStringy(op.children().get(1), false);
  }

  static String asString(Literal l) {
    if (l instanceof NumberLiteral) {
      return NumberLiteral.numberToString(((NumberLiteral) l).doubleValue());
View Full Code Here

  }

  static Expression optimizeExpressionFlow(Expression e) {
    if (!(e instanceof Operation)) { return e; }
    Operation op = (Operation) e;
    List<? extends Expression> operands = op.children();
    Expression[] newOperands = null;
    int n = operands.size();
    for (int i = 0; i < n; ++i) {
      Expression operand = operands.get(i);
      Expression newOperand = optimizeExpressionFlow(operand);
View Full Code Here

      Operation xop = (Operation) x;
      Operation yop = (Operation) y;
      Operator xoper = xop.getOperator();
      if (xoper == yop.getOperator()) {
        List<? extends Expression> xoperands = xop.children();
        List<? extends Expression> yoperands = yop.children();
        int nOperands = xoperands.size();
        if (nOperands == yoperands.size()) {
          Expression xoperand0 = xoperands.get(0);
          // We can often pull the rightmost operand out since it would be
          // evaluated last regardless.
View Full Code Here

      case FUNCTION_CALL:
        return false;
      case CONSTRUCTOR:
        return true;
      case LOGICAL_AND: case LOGICAL_OR:
        return shouldBeEvaluatedForValue(op.children().get(1));
      case TERNARY:
        return shouldBeEvaluatedForValue(op.children().get(1))
            && shouldBeEvaluatedForValue(op.children().get(2));
      case COMMA:
        // We do not allow comma, since bad things happen when commas are used.
View Full Code Here

      case CONSTRUCTOR:
        return true;
      case LOGICAL_AND: case LOGICAL_OR:
        return shouldBeEvaluatedForValue(op.children().get(1));
      case TERNARY:
        return shouldBeEvaluatedForValue(op.children().get(1))
            && shouldBeEvaluatedForValue(op.children().get(2));
      case COMMA:
        // We do not allow comma, since bad things happen when commas are used.
        // Consider
        //    if (foo)
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.