本文整理汇总了Java中com.google.javascript.rhino.Token.HOOK属性的典型用法代码示例。如果您正苦于以下问题:Java Token.HOOK属性的具体用法?Java Token.HOOK怎么用?Java Token.HOOK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.HOOK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: updateAssignAllowedStack
/**
* Determines whether assignment to a define should be allowed
* in the subtree of the given node, and if not, records that fact.
*
* @param n The node whose subtree we're about to enter or exit.
* @param entering True if we're entering the subtree, false otherwise.
*/
private void updateAssignAllowedStack(Node n, boolean entering) {
switch (n.getType()) {
case Token.CASE:
case Token.FOR:
case Token.FUNCTION:
case Token.HOOK:
case Token.IF:
case Token.SWITCH:
case Token.WHILE:
if (entering) {
assignAllowed.push(0);
} else {
assignAllowed.remove();
}
break;
}
}
示例3: 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;
}
}
示例4: isPropertyTest
/**
* Determines whether this node is testing for the existence of a property.
* If true, we will not emit warnings about a missing property.
*
* @param getProp The GETPROP being tested.
*/
private boolean isPropertyTest(Node getProp) {
Node parent = getProp.getParent();
switch (parent.getType()) {
case Token.CALL:
return parent.getFirstChild() != getProp &&
compiler.getCodingConvention().isPropertyTestFunction(parent);
case Token.IF:
case Token.WHILE:
case Token.DO:
case Token.FOR:
return NodeUtil.getConditionExpression(parent) == getProp;
case Token.INSTANCEOF:
case Token.TYPEOF:
return true;
case Token.AND:
case Token.HOOK:
return parent.getFirstChild() == getProp;
}
return false;
}
示例5: 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;
}
}
示例6: getSideEffectsHookNode
private Node getSideEffectsHookNode() {
Node hookNode = new Node(Token.HOOK);
Node assign1 = new Node(Token.ASSIGN);
assign1.addChildToBack(Node.newString(Token.NAME, "bar"));
assign1.addChildToBack(Node.newNumber(0));
Node assign2 = new Node(Token.ASSIGN);
assign2.addChildToBack(Node.newString(Token.NAME, "baz"));
assign2.addChildToBack(Node.newNumber(0));
hookNode.addChildToBack(Node.newString(Token.NAME, "foo"));
hookNode.addChildToBack(assign1);
hookNode.addChildToBack(assign2);
return hookNode;
}
示例7: hasConditionalAncestor
/**
* return true if the node has any form of conditional in its ancestry
* TODO(nicksantos) keep track of the conditionals in the ancestory, so
* that we don't have to recrawl it.
*/
private boolean hasConditionalAncestor(Node n) {
for (Node ancestor : n.getAncestors()) {
switch (ancestor.getType()) {
case Token.DO:
case Token.FOR:
case Token.HOOK:
case Token.IF:
case Token.SWITCH:
case Token.WHILE:
return true;
}
}
return false;
}
示例8: 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;
}
示例9: 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;
}
}
示例10: processConditionalExpression
@Override
Node processConditionalExpression(ConditionalExpression exprNode) {
return new Node(
Token.HOOK,
transform(exprNode.getTestExpression()),
transform(exprNode.getTrueExpression()),
transform(exprNode.getFalseExpression()));
}
示例11: getNoSideEffectsHookNode
private Node getNoSideEffectsHookNode() {
Node hookNode = new Node(Token.HOOK);
hookNode.addChildToBack(Node.newString(Token.NAME, "foo"));
hookNode.addChildToBack(Node.newString(Token.NAME, "bar"));
hookNode.addChildToBack(Node.newString(Token.NAME, "baz"));
return hookNode;
}
示例12: 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 + ")");
}
}
示例13: 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);
}
示例14: determineGetTypeForHookOrBooleanExpr
/**
* Determines whether the result of a hook (x?y:z) or boolean expression
* (x||y) or (x&&y) is assigned to a specific global name.
*
* @param t The traversal
* @param parent The parent of the current node in the traversal. This node
* should already be known to be a HOOK, AND, or OR node.
* @param name A name that is already known to be global in the current
* scope (e.g. "a" or "a.b.c.d")
* @return The expression's get type, either {@link Ref.Type#DIRECT_GET} or
* {@link Ref.Type#ALIASING_GET}
*/
Ref.Type determineGetTypeForHookOrBooleanExpr(
NodeTraversal t, Node parent, String name) {
Node prev = parent;
for (Node anc : parent.getAncestors()) {
switch (anc.getType()) {
case Token.EXPR_RESULT:
case Token.VAR:
case Token.IF:
case Token.WHILE:
case Token.FOR:
case Token.TYPEOF:
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.POS:
case Token.NEG:
return Ref.Type.DIRECT_GET;
case Token.HOOK:
if (anc.getFirstChild() == prev) {
return Ref.Type.DIRECT_GET;
}
break;
case Token.ASSIGN:
if (!name.equals(anc.getFirstChild().getQualifiedName())) {
return Ref.Type.ALIASING_GET;
}
break;
case Token.NAME: // a variable declaration
if (!name.equals(anc.getString())) {
return Ref.Type.ALIASING_GET;
}
break;
case Token.CALL:
if (anc.getFirstChild() != prev) {
return Ref.Type.ALIASING_GET;
}
break;
}
prev = anc;
}
return Ref.Type.ALIASING_GET;
}
示例15: 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;
}
}
}