Java Code Examples for com.google.javascript.rhino.Token#ASSIGN_RSH

The following examples show how to use com.google.javascript.rhino.Token#ASSIGN_RSH . 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: Cardumen_0087_s.java    From coming with MIT License 6 votes vote down vote up
static boolean isAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN:
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
      return true;
  }
  return false;
}
 
Example 2
Source File: jMutRepair_003_t.java    From coming with MIT License 6 votes vote down vote up
static boolean isAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN:
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
      return true;
  }
  return false;
}
 
Example 3
Source File: Cardumen_00149_s.java    From coming with MIT License 6 votes vote down vote up
static boolean isAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN:
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
      return true;
  }
  return false;
}
 
Example 4
Source File: Cardumen_00200_t.java    From coming with MIT License 6 votes vote down vote up
static boolean isAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN:
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
      return true;
  }
  return false;
}
 
Example 5
Source File: Closure_80_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
static int getOpFromAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN_BITOR:
      return Token.BITOR;
    case Token.ASSIGN_BITXOR:
      return Token.BITXOR;
    case Token.ASSIGN_BITAND:
      return Token.BITAND;
    case Token.ASSIGN_LSH:
      return Token.LSH;
    case Token.ASSIGN_RSH:
      return Token.RSH;
    case Token.ASSIGN_URSH:
      return Token.URSH;
    case Token.ASSIGN_ADD:
      return Token.ADD;
    case Token.ASSIGN_SUB:
      return Token.SUB;
    case Token.ASSIGN_MUL:
      return Token.MUL;
    case Token.ASSIGN_DIV:
      return Token.DIV;
    case Token.ASSIGN_MOD:
      return Token.MOD;
  }
  throw new IllegalArgumentException("Not an assiment op");
}
 
Example 6
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static int getOpFromAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN_BITOR:
      return Token.BITOR;
    case Token.ASSIGN_BITXOR:
      return Token.BITXOR;
    case Token.ASSIGN_BITAND:
      return Token.BITAND;
    case Token.ASSIGN_LSH:
      return Token.LSH;
    case Token.ASSIGN_RSH:
      return Token.RSH;
    case Token.ASSIGN_URSH:
      return Token.URSH;
    case Token.ASSIGN_ADD:
      return Token.ADD;
    case Token.ASSIGN_SUB:
      return Token.SUB;
    case Token.ASSIGN_MUL:
      return Token.MUL;
    case Token.ASSIGN_DIV:
      return Token.DIV;
    case Token.ASSIGN_MOD:
      return Token.MOD;
  }
  throw new IllegalArgumentException("Not an assignment op:" + n);
}
 
Example 7
Source File: Closure_94_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
static int getOpFromAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN_BITOR:
      return Token.BITOR;
    case Token.ASSIGN_BITXOR:
      return Token.BITXOR;
    case Token.ASSIGN_BITAND:
      return Token.BITAND;
    case Token.ASSIGN_LSH:
      return Token.LSH;
    case Token.ASSIGN_RSH:
      return Token.RSH;
    case Token.ASSIGN_URSH:
      return Token.URSH;
    case Token.ASSIGN_ADD:
      return Token.ADD;
    case Token.ASSIGN_SUB:
      return Token.SUB;
    case Token.ASSIGN_MUL:
      return Token.MUL;
    case Token.ASSIGN_DIV:
      return Token.DIV;
    case Token.ASSIGN_MOD:
      return Token.MOD;
  }
  throw new IllegalArgumentException("Not an assiment op");
}
 
Example 8
Source File: Closure_75_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
static int getOpFromAssignmentOp(Node n) {
  switch (n.getType()){
    case Token.ASSIGN_BITOR:
      return Token.BITOR;
    case Token.ASSIGN_BITXOR:
      return Token.BITXOR;
    case Token.ASSIGN_BITAND:
      return Token.BITAND;
    case Token.ASSIGN_LSH:
      return Token.LSH;
    case Token.ASSIGN_RSH:
      return Token.RSH;
    case Token.ASSIGN_URSH:
      return Token.URSH;
    case Token.ASSIGN_ADD:
      return Token.ADD;
    case Token.ASSIGN_SUB:
      return Token.SUB;
    case Token.ASSIGN_MUL:
      return Token.MUL;
    case Token.ASSIGN_DIV:
      return Token.DIV;
    case Token.ASSIGN_MOD:
      return Token.MOD;
  }
  throw new IllegalArgumentException("Not an assiment op");
}
 
Example 9
Source File: Closure_94_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Converts an operator's token value (see {@link Token}) to a string
 * representation.
 *
 * @param operator the operator's token value to convert
 * @return the string representation or {@code null} if the token value is
 * not an operator
 */
static String opToStr(int operator) {
  switch (operator) {
    case Token.BITOR: return "|";
    case Token.OR: return "||";
    case Token.BITXOR: return "^";
    case Token.AND: return "&&";
    case Token.BITAND: return "&";
    case Token.SHEQ: return "===";
    case Token.EQ: return "==";
    case Token.NOT: return "!";
    case Token.NE: return "!=";
    case Token.SHNE: return "!==";
    case Token.LSH: return "<<";
    case Token.IN: return "in";
    case Token.LE: return "<=";
    case Token.LT: return "<";
    case Token.URSH: return ">>>";
    case Token.RSH: return ">>";
    case Token.GE: return ">=";
    case Token.GT: return ">";
    case Token.MUL: return "*";
    case Token.DIV: return "/";
    case Token.MOD: return "%";
    case Token.BITNOT: return "~";
    case Token.ADD: return "+";
    case Token.SUB: return "-";
    case Token.POS: return "+";
    case Token.NEG: return "-";
    case Token.ASSIGN: return "=";
    case Token.ASSIGN_BITOR: return "|=";
    case Token.ASSIGN_BITXOR: return "^=";
    case Token.ASSIGN_BITAND: return "&=";
    case Token.ASSIGN_LSH: return "<<=";
    case Token.ASSIGN_RSH: return ">>=";
    case Token.ASSIGN_URSH: return ">>>=";
    case Token.ASSIGN_ADD: return "+=";
    case Token.ASSIGN_SUB: return "-=";
    case Token.ASSIGN_MUL: return "*=";
    case Token.ASSIGN_DIV: return "/=";
    case Token.ASSIGN_MOD: return "%=";
    case Token.VOID: return "void";
    case Token.TYPEOF: return "typeof";
    case Token.INSTANCEOF: return "instanceof";
    default: return null;
  }
}
 
Example 10
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);
}
 
Example 11
Source File: Closure_60_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Converts an operator's token value (see {@link Token}) to a string
 * representation.
 *
 * @param operator the operator's token value to convert
 * @return the string representation or {@code null} if the token value is
 * not an operator
 */
static String opToStr(int operator) {
  switch (operator) {
    case Token.BITOR: return "|";
    case Token.OR: return "||";
    case Token.BITXOR: return "^";
    case Token.AND: return "&&";
    case Token.BITAND: return "&";
    case Token.SHEQ: return "===";
    case Token.EQ: return "==";
    case Token.NOT: return "!";
    case Token.NE: return "!=";
    case Token.SHNE: return "!==";
    case Token.LSH: return "<<";
    case Token.IN: return "in";
    case Token.LE: return "<=";
    case Token.LT: return "<";
    case Token.URSH: return ">>>";
    case Token.RSH: return ">>";
    case Token.GE: return ">=";
    case Token.GT: return ">";
    case Token.MUL: return "*";
    case Token.DIV: return "/";
    case Token.MOD: return "%";
    case Token.BITNOT: return "~";
    case Token.ADD: return "+";
    case Token.SUB: return "-";
    case Token.POS: return "+";
    case Token.NEG: return "-";
    case Token.ASSIGN: return "=";
    case Token.ASSIGN_BITOR: return "|=";
    case Token.ASSIGN_BITXOR: return "^=";
    case Token.ASSIGN_BITAND: return "&=";
    case Token.ASSIGN_LSH: return "<<=";
    case Token.ASSIGN_RSH: return ">>=";
    case Token.ASSIGN_URSH: return ">>>=";
    case Token.ASSIGN_ADD: return "+=";
    case Token.ASSIGN_SUB: return "-=";
    case Token.ASSIGN_MUL: return "*=";
    case Token.ASSIGN_DIV: return "/=";
    case Token.ASSIGN_MOD: return "%=";
    case Token.VOID: return "void";
    case Token.TYPEOF: return "typeof";
    case Token.INSTANCEOF: return "instanceof";
    default: return null;
  }
}
 
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: Cardumen_00149_s.java    From coming with MIT License 4 votes vote down vote up
static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.CALL:
    case Token.GETELEM:
    case Token.GETPROP:
    // Data values
    case Token.ARRAYLIT:
    case Token.EMPTY:  // TODO(johnlenz): remove this.
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.STRING:
    case Token.STRING_KEY:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Token.name(type) +
                             " (type " + type + ")");
  }
}
 
Example 14
Source File: Closure_10_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Converts an operator's token value (see {@link Token}) to a string
 * representation.
 *
 * @param operator the operator's token value to convert
 * @return the string representation or {@code null} if the token value is
 * not an operator
 */
static String opToStr(int operator) {
  switch (operator) {
    case Token.BITOR: return "|";
    case Token.OR: return "||";
    case Token.BITXOR: return "^";
    case Token.AND: return "&&";
    case Token.BITAND: return "&";
    case Token.SHEQ: return "===";
    case Token.EQ: return "==";
    case Token.NOT: return "!";
    case Token.NE: return "!=";
    case Token.SHNE: return "!==";
    case Token.LSH: return "<<";
    case Token.IN: return "in";
    case Token.LE: return "<=";
    case Token.LT: return "<";
    case Token.URSH: return ">>>";
    case Token.RSH: return ">>";
    case Token.GE: return ">=";
    case Token.GT: return ">";
    case Token.MUL: return "*";
    case Token.DIV: return "/";
    case Token.MOD: return "%";
    case Token.BITNOT: return "~";
    case Token.ADD: return "+";
    case Token.SUB: return "-";
    case Token.POS: return "+";
    case Token.NEG: return "-";
    case Token.ASSIGN: return "=";
    case Token.ASSIGN_BITOR: return "|=";
    case Token.ASSIGN_BITXOR: return "^=";
    case Token.ASSIGN_BITAND: return "&=";
    case Token.ASSIGN_LSH: return "<<=";
    case Token.ASSIGN_RSH: return ">>=";
    case Token.ASSIGN_URSH: return ">>>=";
    case Token.ASSIGN_ADD: return "+=";
    case Token.ASSIGN_SUB: return "-=";
    case Token.ASSIGN_MUL: return "*=";
    case Token.ASSIGN_DIV: return "/=";
    case Token.ASSIGN_MOD: return "%=";
    case Token.VOID: return "void";
    case Token.TYPEOF: return "typeof";
    case Token.INSTANCEOF: return "instanceof";
    default: return null;
  }
}
 
Example 15
Source File: Cardumen_0014_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Converts an operator's token value (see {@link Token}) to a string
 * representation.
 *
 * @param operator the operator's token value to convert
 * @return the string representation or {@code null} if the token value is
 * not an operator
 */
static String opToStr(int operator) {
  switch (operator) {
    case Token.BITOR: return "|";
    case Token.OR: return "||";
    case Token.BITXOR: return "^";
    case Token.AND: return "&&";
    case Token.BITAND: return "&";
    case Token.SHEQ: return "===";
    case Token.EQ: return "==";
    case Token.NOT: return "!";
    case Token.NE: return "!=";
    case Token.SHNE: return "!==";
    case Token.LSH: return "<<";
    case Token.IN: return "in";
    case Token.LE: return "<=";
    case Token.LT: return "<";
    case Token.URSH: return ">>>";
    case Token.RSH: return ">>";
    case Token.GE: return ">=";
    case Token.GT: return ">";
    case Token.MUL: return "*";
    case Token.DIV: return "/";
    case Token.MOD: return "%";
    case Token.BITNOT: return "~";
    case Token.ADD: return "+";
    case Token.SUB: return "-";
    case Token.POS: return "+";
    case Token.NEG: return "-";
    case Token.ASSIGN: return "=";
    case Token.ASSIGN_BITOR: return "|=";
    case Token.ASSIGN_BITXOR: return "^=";
    case Token.ASSIGN_BITAND: return "&=";
    case Token.ASSIGN_LSH: return "<<=";
    case Token.ASSIGN_RSH: return ">>=";
    case Token.ASSIGN_URSH: return ">>>=";
    case Token.ASSIGN_ADD: return "+=";
    case Token.ASSIGN_SUB: return "-=";
    case Token.ASSIGN_MUL: return "*=";
    case Token.ASSIGN_DIV: return "/=";
    case Token.ASSIGN_MOD: return "%=";
    case Token.VOID: return "void";
    case Token.TYPEOF: return "typeof";
    case Token.INSTANCEOF: return "instanceof";
    default: return null;
  }
}
 
Example 16
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 17
Source File: Closure_61_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.CALL:
    case Token.GETELEM:
    case Token.GETPROP:
    // Data values
    case Token.ARRAYLIT:
    case Token.EMPTY:  // TODO(johnlenz): remove this.
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.STRING:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Node.tokenToName(type) +
                             " (type " + type + ")");
  }
}
 
Example 18
Source File: Closure_105_FoldConstants_t.java    From coming with MIT License 4 votes vote down vote up
private void tryFoldAssign(NodeTraversal t, Node n, Node left, Node right) {
  Preconditions.checkArgument(n.getType() == Token.ASSIGN);

  // Tries to convert x = x + y -> x += y;
  if (!right.hasChildren() ||
      right.getFirstChild().getNext() != right.getLastChild()) {
    // RHS must have two children.
    return;
  }

  if (NodeUtil.mayHaveSideEffects(left)) {
    return;
  }

  Node leftChild = right.getFirstChild();
  if (!compiler.areNodesEqualForInlining(left, leftChild)) {
    return;
  }

  int newType = -1;
  switch (right.getType()) {
    case Token.ADD:
      newType = Token.ASSIGN_ADD;
      break;
    case Token.BITAND:
      newType = Token.ASSIGN_BITAND;
      break;
    case Token.BITOR:
      newType = Token.ASSIGN_BITOR;
      break;
    case Token.BITXOR:
      newType = Token.ASSIGN_BITXOR;
      break;
    case Token.DIV:
      newType = Token.ASSIGN_DIV;
      break;
    case Token.LSH:
      newType = Token.ASSIGN_LSH;
      break;
    case Token.MOD:
      newType = Token.ASSIGN_MOD;
      break;
    case Token.MUL:
      newType = Token.ASSIGN_MUL;
      break;
    case Token.RSH:
      newType = Token.ASSIGN_RSH;
      break;
    case Token.SUB:
      newType = Token.ASSIGN_SUB;
      break;
    case Token.URSH:
      newType = Token.ASSIGN_URSH;
      break;
    default:
      return;
  }

  n.getParent().replaceChild(n, new Node(newType,
      left.detachFromParent(), right.getLastChild().detachFromParent()));
  t.getCompiler().reportCodeChange();
}
 
Example 19
Source File: Cardumen_0087_t.java    From coming with MIT License 4 votes vote down vote up
static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.CALL:
    case Token.GETELEM:
    case Token.GETPROP:
    // Data values
    case Token.ARRAYLIT:
    case Token.EMPTY:  // TODO(johnlenz): remove this.
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.STRING:
    case Token.STRING_KEY:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Token.name(type) +
                             " (type " + type + ")");
  }
}
 
Example 20
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);
}