本文整理汇总了Java中com.google.javascript.rhino.Token.OR属性的典型用法代码示例。如果您正苦于以下问题:Java Token.OR属性的具体用法?Java Token.OR怎么用?Java Token.OR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.OR属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueType
/**
* Gets the type of a value or simple expression.
*
* @param n An rvalue in an assignment or variable declaration (not null)
* @return A {@link Name.Type}
*/
Name.Type getValueType(Node n) {
switch (n.getType()) {
case Token.OBJECTLIT:
return Name.Type.OBJECTLIT;
case Token.FUNCTION:
return Name.Type.FUNCTION;
case Token.OR:
// Recurse on the second value. If the first value were an object
// literal or function, then the OR would be meaningless and the
// second value would be dead code. Assume that if the second value
// is an object literal or function, then the first value will also
// evaluate to one when it doesn't evaluate to false.
return getValueType(n.getLastChild());
case Token.HOOK:
// The same line of reasoning used for the OR case applies here.
Node second = n.getFirstChild().getNext();
Name.Type t = getValueType(second);
if (t != Name.Type.OTHER) return t;
Node third = second.getNext();
return getValueType(third);
}
return Name.Type.OTHER;
}
示例2: valueConsumedByParent
/**
* Determine if the parent reads the value of a child expression
* directly. This is true children used in predicates, RETURN
* statements and, rhs of variable declarations and assignments.
*
* In the case of:
* if (a) b else c
*
* This method returns true for "a", and false for "b" and "c": the
* IF expression does something special based on "a"'s value. "b"
* and "c" are effectivelly outputs. Same logic applies to FOR,
* WHILE and DO loop predicates. AND/OR/HOOK expressions are
* syntactic sugar for IF statements; therefore this method returns
* true for the predicate and false otherwise.
*/
private boolean valueConsumedByParent(Node n, Node parent) {
if (NodeUtil.isAssignmentOp(parent)) {
return parent.getLastChild() == n;
}
switch (parent.getType()) {
case Token.NAME:
case Token.RETURN:
return true;
case Token.AND:
case Token.OR:
case Token.HOOK:
return parent.getFirstChild() == n;
case Token.FOR:
return parent.getFirstChild().getNext() == n;
case Token.IF:
case Token.WHILE:
return parent.getFirstChild() == n;
case Token.DO:
return parent.getLastChild() == n;
default:
return false;
}
}
示例3: definitionTypeContainsFunctionType
/**
* Determines if the type of the value of the rhs expression can
* be a function node.
*/
private static boolean definitionTypeContainsFunctionType(Definition def) {
Node rhs = def.getRValue();
if (rhs == null) {
return true;
}
switch (rhs.getType()) {
case Token.ASSIGN:
case Token.AND:
case Token.CALL:
case Token.GETPROP:
case Token.GETELEM:
case Token.FUNCTION:
case Token.HOOK:
case Token.NAME:
case Token.NEW:
case Token.OR:
return true;
default:
return false;
}
}
示例4: isAssociative
/**
* Returns true if the operator is associative.
* e.g. (a * b) * c = a * (b * c)
* Note: "+" is not associative because it is also the concatentation
* for strings. e.g. "a" + (1 + 2) is not "a" + 1 + 2
*/
static boolean isAssociative(int type) {
switch (type) {
case Token.MUL:
case Token.AND:
case Token.OR:
case Token.BITOR:
case Token.BITAND:
return true;
default:
return false;
}
}
示例5: isBlockBoundary
/**
* @return true if this node marks the start of a new basic block
*/
private static boolean isBlockBoundary(Node n, Node parent) {
if (parent != null) {
switch (parent.getType()) {
case Token.DO:
case Token.FOR:
case Token.TRY:
case Token.WHILE:
case Token.WITH:
// NOTE: TRY has up to 3 child blocks:
// TRY
// BLOCK
// BLOCK
// CATCH
// BLOCK
// Note that there is an explcit CATCH token but no explicit
// FINALLY token. For simplicity, we consider each BLOCK
// a separate basic BLOCK.
return true;
case Token.AND:
case Token.HOOK:
case Token.IF:
case Token.OR:
// The first child of a conditional is not a boundary,
// but all the rest of the children are.
return n != parent.getFirstChild();
}
}
return n.getType() == Token.CASE;
}
示例6: isConditionalOp
/**
* @return Whether the node is a conditional op.
*/
private static boolean isConditionalOp(Node n) {
switch(n.getType()) {
case Token.HOOK:
case Token.AND:
case Token.OR:
return true;
default:
return false;
}
}
示例7: traverseWithinShortCircuitingBinOp
private BooleanOutcomePair traverseWithinShortCircuitingBinOp(Node n,
FlowScope scope) {
switch (n.getType()) {
case Token.AND:
return traverseAnd(n, scope);
case Token.OR:
return traverseOr(n, scope);
default:
scope = traverse(n, scope);
return newBooleanOutcomePair(n.getJSType(), scope);
}
}
示例8: getOutcomeFlowScope
/**
* Gets the outcome scope if we do know the outcome of the entire
* expression.
*/
FlowScope getOutcomeFlowScope(int nodeType, boolean outcome) {
if (nodeType == Token.AND && outcome ||
nodeType == Token.OR && !outcome) {
// We know that the whole expression must have executed.
return rightScope;
} else {
return getJoinedFlowScope();
}
}
示例9: precedence
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.ARRAYLIT:
case Token.CALL:
case Token.EMPTY:
case Token.FALSE:
case Token.FUNCTION:
case Token.GETELEM:
case Token.GETPROP:
case Token.GET_REF:
case Token.IF:
case Token.LP:
case Token.NAME:
case Token.NULL:
case Token.NUMBER:
case Token.OBJECTLIT:
case Token.REGEXP:
case Token.RETURN:
case Token.STRING:
case Token.THIS:
case Token.TRUE:
return 15;
default: throw new Error("Unknown precedence for " +
Node.tokenToName(type) +
" (type " + type + ")");
}
}
示例10: opToStr
/**
* 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;
}
}
示例11: handleGet
/**
* Updates our respresentation of the global namespace to reflect a read
* of a global name.
*
* @param t The traversal
* @param n The node currently being visited
* @param parent {@code n}'s parent
* @param name The global name (e.g. "a" or "a.b.c.d")
*/
void handleGet(NodeTraversal t, Node n, Node parent, String name) {
if (maybeHandlePrototypePrefix(t, n, parent, name)) return;
Ref.Type type = Ref.Type.DIRECT_GET;
if (parent != null) {
switch (parent.getType()) {
case Token.IF:
case Token.TYPEOF:
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.POS:
case Token.NEG:
break;
case Token.CALL:
type = n == parent.getFirstChild()
? Ref.Type.CALL_GET
: Ref.Type.ALIASING_GET;
break;
case Token.NEW:
type = n == parent.getFirstChild()
? Ref.Type.DIRECT_GET
: Ref.Type.ALIASING_GET;
break;
case Token.OR:
case Token.AND:
// This node is x or y in (x||y) or (x&&y). We only know that an
// alias is not getting created for this name if the result is used
// in a boolean context or assigned to the same name
// (e.g. var a = a || {}).
type = determineGetTypeForHookOrBooleanExpr(t, parent, name);
break;
case Token.HOOK:
if (n != parent.getFirstChild()) {
// This node is y or z in (x?y:z). We only know that an alias is
// not getting created for this name if the result is assigned to
// the same name (e.g. var a = a ? a : {}).
type = determineGetTypeForHookOrBooleanExpr(t, parent, name);
}
break;
default:
type = Ref.Type.ALIASING_GET;
break;
}
}
handleGet(t, n, parent, name, type);
}
示例12: shouldTraverse
/**
* Computes the list of subtrees whose root nodes have side effects.
*
* <p>If the current subtree's root has side effects this method should
* call accumulator.keepSubTree and return 'false' to add the
* subtree to the result list and avoid avoid traversing the nodes children.
*
* <p>Branching nodes whose then or else branch contain side effects
* must be simplified by doing a recursive traversal; this method
* should call the appropriate accumulator 'keepSimplified' method
* and return 'false' to stop the regular traversal.
*/
@Override
public boolean shouldTraverse(
NodeTraversal traversal, Node node, Node parent) {
if (FORBIDDEN_TYPES.contains(node.getType()) ||
NodeUtil.isControlStructure(node)) {
throw new IllegalArgumentException(
Token.name(node.getType()) + " nodes are not supported.");
}
// Do not recurse into nested functions.
if (node.getType() == Token.FUNCTION) {
return false;
}
// simplify and maybe keep hook expression.
if (node.getType() == Token.HOOK) {
return processHook(node);
}
// simplify and maybe keep AND/OR expression.
if ((node.getType() == Token.AND) || (node.getType() == Token.OR)) {
return processShortCircuitExpression(node);
}
if (!NodeUtil.nodeTypeMayHaveSideEffects(node)) {
return true;
} else {
// Node type suggests that the expression has side effects.
if (node.getType() == Token.CALL) {
return processFunctionCall(node);
} else if (node.getType() == Token.NEW) {
return processConstructorCall(node);
} else {
accumulator.keepSubTree(node);
return false;
}
}
}
示例13: tryFoldAndOr
/**
* Try to fold a AND/OR node.
*/
void tryFoldAndOr(NodeTraversal t, Node n, Node left, Node right,
Node parent) {
Node result = null;
int type = n.getType();
if (NodeUtil.isLiteralValue(left)) {
boolean lval = NodeUtil.getBooleanValue(left);
// (TRUE || x) => TRUE (also, (3 || x) => 3)
// (FALSE && x) => FALSE
if (lval && type == Token.OR ||
!lval && type == Token.AND) {
result = left;
} else {
// (FALSE || x) => x
// (TRUE && x) => x
result = right;
}
} else if (NodeUtil.isLiteralValue(right)) {
// Note: We cannot always fold when the constant is on the
// right, because the typed value of the expression will depend
// on the type of the constant on the right, even if the boolean
// equivalent of the value does not. Specifically, in "a = x ||
// 0", a will be numeric 0 if x is undefined (and hence is
// e.g. a valid array index). However, it is safe to fold
// e.g. "if (x || true)" because 'if' doesn't care if the
// expression is 'true' or '3'.
int pt = parent.getType();
if (pt == Token.IF || pt == Token.WHILE || pt == Token.DO ||
(pt == Token.FOR && NodeUtil.getConditionExpression(parent) == n) ||
(pt == Token.HOOK && parent.getFirstChild() == n)) {
boolean rval = NodeUtil.getBooleanValue(right);
// (x || FALSE) => x
// (x && TRUE) => x
if (type == Token.OR && !rval ||
type == Token.AND && rval) {
result = left;
} else {
// If x has no side-effects:
// (x || TRUE) => TRUE
// (x && FALSE) => FALSE
if (!NodeUtil.mayHaveSideEffects(left)) {
result = right;
}
}
}
}
// Note: The parser parses 'x && FALSE && y' as 'x && (FALSE && y)', so
// there is not much need to worry about const values on left's
// right child.
if (result != null) {
// Fold it!
n.removeChild(result);
parent.replaceChild(n, result);
t.getCompiler().reportCodeChange();
}
}