Java Code Examples for com.google.javascript.rhino.jstype.JSType#matchesInt32Context()

The following examples show how to use com.google.javascript.rhino.jstype.JSType#matchesInt32Context() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 2
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 3
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 4
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 5
Source File: Closure_96_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 6
Source File: Closure_96_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 7
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 8
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 9
Source File: Closure_66_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 10
Source File: Nopol2017_0051_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 11
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 12
Source File: Closure_125_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 13
Source File: Closure_69_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 14
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}
 
Example 15
Source File: Nopol2017_0029_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 16
Source File: Nopol2017_0029_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Token.name(op));
  }
  ensureTyped(t, n);
}
 
Example 17
Source File: Nopol2017_0051_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * This function unifies the type checking involved in the core binary
 * operators and the corresponding assignment operators.  The representation
 * used internally is such that common code can handle both kinds of
 * operators easily.
 *
 * @param op The operator.
 * @param t The traversal object, needed to report errors.
 * @param n The node being checked.
 */
private void visitBinaryOperator(int op, NodeTraversal t, Node n) {
  Node left = n.getFirstChild();
  JSType leftType = getJSType(left);
  Node right = n.getLastChild();
  JSType rightType = getJSType(right);
  switch (op) {
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.LSH:
    case Token.RSH:
    case Token.ASSIGN_URSH:
    case Token.URSH:
      if (!leftType.matchesInt32Context()) {
        report(t, left, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), leftType.toString());
      }
      if (!rightType.matchesUint32Context()) {
        report(t, right, BIT_OPERATION,
                 NodeUtil.opToStr(n.getType()), rightType.toString());
      }
      break;

    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_SUB:
    case Token.DIV:
    case Token.MOD:
    case Token.MUL:
    case Token.SUB:
      validator.expectNumber(t, left, leftType, "left operand");
      validator.expectNumber(t, right, rightType, "right operand");
      break;

    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITOR:
    case Token.BITAND:
    case Token.BITXOR:
    case Token.BITOR:
      validator.expectBitwiseable(t, left, leftType,
          "bad left operand to bitwise operator");
      validator.expectBitwiseable(t, right, rightType,
          "bad right operand to bitwise operator");
      break;

    case Token.ASSIGN_ADD:
    case Token.ADD:
      break;

    default:
      report(t, n, UNEXPECTED_TOKEN, Node.tokenToName(op));
  }
  ensureTyped(t, n);
}