当前位置: 首页>>代码示例>>Java>>正文


Java Token.RETURN属性代码示例

本文整理汇总了Java中com.google.javascript.rhino.Token.RETURN属性的典型用法代码示例。如果您正苦于以下问题:Java Token.RETURN属性的具体用法?Java Token.RETURN怎么用?Java Token.RETURN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.javascript.rhino.Token的用法示例。


在下文中一共展示了Token.RETURN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: returnedExpression

/**
 * Return the node that represents the expression returned
 * by the method, given a FUNCTION node.
 */
private static Node returnedExpression(Node fn) {
  Node expectedBlock = getMethodBlock(fn);
  if (!expectedBlock.hasOneChild()) {
    return null;
  }

  Node expectedReturn = expectedBlock.getFirstChild();
  if (expectedReturn.getType() != Token.RETURN) {
    return null;
  }

  if (!expectedReturn.hasOneChild()) {
    return null;
  }

  return expectedReturn.getLastChild();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:InlineGetters.java

示例2: isDirectCallNodeReplacementPossible

/**
 * Checks if the given function matches the criteria for an inlinable
 * function, and if so, adds it to our set of inlinable functions.
 */
boolean isDirectCallNodeReplacementPossible(Node fnNode) {
  // Only inline single-statement functions
  Node block = NodeUtil.getFunctionBody(fnNode);

  // Check if this function is suitable for direct replacement of a CALL node:
  // a function that consists of single return that returns an expression.
  if (!block.hasChildren()) {
    // special case empty functions.
    return true;
  } else if (block.hasOneChild()) {
    // Only inline functions that return something.
    if (block.getFirstChild().getType() == Token.RETURN
        && block.getFirstChild().getFirstChild() != null) {
      return true;
    }
  }

  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:FunctionInjector.java

示例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;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:39,代码来源:NameAnalyzer.java

示例4: allPathsReturn

/**
 * @returns true if all paths from block must exit with an explicit return.
 */
private boolean allPathsReturn(Node block) {
  // Computes the control flow graph.
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false);
  cfa.process(null, block);
  ControlFlowGraph<Node> cfg = cfa.getCfg();

  Node returnPathsParent = cfg.getImplicitReturn().getValue();
  for (DiGraphNode<Node, Branch> pred :
    cfg.getDirectedPredNodes(returnPathsParent)) {
    Node n = pred.getValue();
    if (n.getType() != Token.RETURN) {
      return false;
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:InstrumentFunctions.java

示例5: matchingExitNode

/**
 * Determines if n matches the type and name for the following types of
 * "exits":
 *    - return without values
 *    - continues and breaks with or without names.
 * @param n The node to inspect.
 * @param type The Token type to look for.
 * @param labelName The name that must be associated with the exit type.
 * @nullable labelName non-null only for breaks associated with labels.
 * @return Whether the node matches the specified block-exit type.
 */
static private boolean matchingExitNode(Node n, int type, String labelName) {
  if (n.getType() == type) {
    if (type == Token.RETURN) {
      // only returns without expressions.
      return !n.hasChildren();
    } else {
      if (labelName == null) {
        return !n.hasChildren();
      } else {
        return n.hasChildren()
          && labelName.equals(n.getFirstChild().getString());
      }
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:MinimizeExitPoints.java

示例6: processReturnStatement

@Override
Node processReturnStatement(ReturnStatement statementNode) {
  Node node = new Node(Token.RETURN);
  if (statementNode.getReturnValue() != null) {
    node.addChildToBack(transform(statementNode.getReturnValue()));
  }
  return node;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:IRFactory.java

示例7: maybeGetSingleReturnRValue

/**
 * @return function return value node if function body contains a
 * single return statement.  Otherwise, null.
 */
protected final Node maybeGetSingleReturnRValue(Node functionNode) {
  Node body = functionNode.getLastChild();
  if (!body.hasOneChild()) {
    return null;
  }

  Node statement = body.getFirstChild();
  if (statement.getType() == Token.RETURN) {
    return statement.getFirstChild();
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:FunctionRewriter.java

示例8: isInThrowExpression

/**
 * Is the {@link Node} currently within a 'throw' expression?
 */
private static boolean isInThrowExpression(Node n) {
  // Look up the traversal stack to find a THROW node
  for (Node ancestor : n.getAncestors()) {
    switch (ancestor.getType()) {
      case Token.THROW:
        return true;
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
      case Token.FOR:
      case Token.SWITCH:
      case Token.CASE:
      case Token.DEFAULT:
      case Token.BLOCK:
      case Token.SCRIPT:
      case Token.FUNCTION:
      case Token.TRY:
      case Token.CATCH:
      case Token.RETURN:
      case Token.EXPR_RESULT:
        // early exit - these nodes types can't be within a THROW
        return false;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:AliasStrings.java

示例9: findExpressionRoot

/**
 * @return The statement containing the expression. null if subExpression
 *     is not contain by in by a Node where inlining is known to be possible.
 *     For example, a WHILE node condition expression.
 */
static Node findExpressionRoot(Node subExpression) {
  Node child = subExpression;
  for (Node parent : child.getAncestors()) {
    int parentType = parent.getType();
    switch (parentType) {
      // Supported expression roots:
      // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
      // or BLOCK will be encountered first for any of the children other
      // than the condition.
      case Token.EXPR_RESULT:
      case Token.IF:
      case Token.SWITCH:
      case Token.RETURN:
      case Token.VAR:
        Preconditions.checkState(child == parent.getFirstChild());
        return parent;
      // Any of these indicate an unsupported expression:
      case Token.SCRIPT:
      case Token.BLOCK:
      case Token.LABEL:
      case Token.CASE:
      case Token.DEFAULT:
        return null;
    }
    child = parent;
  }

  throw new IllegalStateException("Unexpected AST structure.");
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExpressionDecomposer.java

示例10: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (NodeUtil.isFunction(n)) {
    visitFunction(t, n);
  } else if (n.getType() == Token.RETURN) {
    visitReturn(t, n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:RuntimeTypeCheck.java

示例11: isReturnExpressBlock

/**
 * @return Whether the node is a block with a single statement that is
 *     an return.
 */
private boolean isReturnExpressBlock(Node n) {
  if (n.getType() == Token.BLOCK) {
    if (n.hasOneChild()) {
      Node first = n.getFirstChild();
      if (first.getType() == Token.RETURN) {
        return first.hasOneChild();
      }
    }
  }

  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:FoldConstants.java

示例12: tryRemoveDeadAssignments

/**
 * Try to remove useless assignments from a control flow graph that has been
 * annotated with liveness information.
 *
 * @param t The node traversal.
 * @param cfg The control flow graph of the program annotated with liveness
 *        information.
 */
private void tryRemoveDeadAssignments(NodeTraversal t,
    ControlFlowGraph<Node> cfg) {
  List<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();

  for (DiGraphNode<Node, Branch> cfgNode : nodes) {
    FlowState<LiveVariableLattice> state =
        cfgNode.getAnnotation();
    Node n = cfgNode.getValue();
    if (n == null) {
      continue;
    }
    switch (n.getType()) {
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
        tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state);
        continue;
      case Token.FOR:
        if (!NodeUtil.isForIn(n)) {
          tryRemoveAssignment(
              t, NodeUtil.getConditionExpression(n), state);
        }
        continue;
      case Token.SWITCH:
      case Token.CASE:
      case Token.RETURN:
        if (n.hasChildren()) {
          tryRemoveAssignment(t, n.getFirstChild(), state);
        }
        continue;
      // TODO(user): case Token.VAR: Remove var a=1;a=2;.....
    }
    
    tryRemoveAssignment(t, n, state);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:DeadAssignmentsElimination.java

示例13: replaceReturnWithBreak

/**
 * Replace the 'return' statement with its child expression.
 *   "return foo()" becomes "{foo(); break;}" or
 *      "{resultName = foo(); break;}"
 *   "return" becomes {break;} or "{resultName = void 0;break;}".
 */
private static Node replaceReturnWithBreak(Node current, Node parent,
    String resultName, String labelName) {

  if (current.getType() == Token.FUNCTION
      || current.getType() == Token.EXPR_RESULT) {
    // Don't recurse into functions definitions, and expressions can't
    // contain RETURN nodes.
    return current;
  }

  if (current.getType() == Token.RETURN) {
    Preconditions.checkState(NodeUtil.isStatementBlock(parent));

    Node resultNode = getReplacementReturnStatement(current, resultName);
    Node name = Node.newString(Token.NAME, labelName);
    Node breakNode = new Node(Token.BREAK, name);

    // Replace the node in parent, and reset current to the first new child.
    parent.replaceChild(current, breakNode);
    if (resultNode != null) {
      parent.addChildBefore(resultNode, breakNode);
    }
    current = breakNode;
  } else {
    for (Node c = current.getFirstChild(); c != null; c = c.getNext()) {
      // c may be replaced.
      c = replaceReturnWithBreak(c, current, resultName, labelName);
    }
  }

  return current;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:38,代码来源:FunctionToBlockMutator.java

示例14: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() != Token.RETURN) {
    return;
  }

  Node call = newReportFunctionExitNode();
  Node returnRhs = n.removeFirstChild();
  if (returnRhs != null) {
    call.addChildToBack(returnRhs);
  }
  n.addChildToFront(call);
  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:InstrumentFunctions.java

示例15: fastAllPathsReturnCheck

/**
 * Fast check to see if all execution paths contain a return statement.
 * May spuriously report that a return statement is missing.
 *
 * @return true if all paths return, converse not necessarily true
 */
private static boolean fastAllPathsReturnCheck(ControlFlowGraph<Node> cfg) {
  for (DiGraphEdge<Node, Branch> s : cfg.getImplicitReturn().getInEdges()) {
    if (s.getSource().getValue().getType() != Token.RETURN) {
      return false;
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:CheckMissingReturn.java


注:本文中的com.google.javascript.rhino.Token.RETURN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。