Java Code Examples for com.google.javascript.rhino.Node#toStringTree()

The following examples show how to use com.google.javascript.rhino.Node#toStringTree() . 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_0024_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 2
Source File: Cardumen_0024_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 3
Source File: Closure_7_ChainableReverseAbstractInterpreter_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 4
Source File: Closure_7_ChainableReverseAbstractInterpreter_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 5
Source File: Closure_19_ChainableReverseAbstractInterpreter_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 6
Source File: Closure_19_ChainableReverseAbstractInterpreter_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

      // "this" references aren't currently modeled in the CFG.

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 7
Source File: TightenTypes.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an action for assigning the right-hand-side to the left or null
 * if this assignment should be ignored.
 */
private List<Action> createAssignmentActions(
    Node lhs, Node rhs, Node parent) {
  switch (lhs.getType()) {
    case Token.NAME:
      ConcreteSlot var = (ConcreteSlot) scope.getSlot(lhs.getString());
      Preconditions.checkState(var != null,
          "Type tightener could not find variable with name %s",
          lhs.getString());
      return Lists.<Action>newArrayList(
          new VariableAssignAction(var, rhs));

    case Token.GETPROP:
      Node receiver = lhs.getFirstChild();
      return Lists.<Action>newArrayList(
          new PropertyAssignAction(receiver, rhs));

    case Token.GETELEM:
      return Lists.newArrayList();

    default:
      throw new AssertionError(
          "Bad LHS for assignment: " + parent.toStringTree());
  }
}
 
Example 8
Source File: ChainableReverseAbstractInterpreter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Declares a refined type in {@code scope} for the name represented by
 * {@code node}. It must be possible to refine the type of the given node in
 * the given scope, as determined by {@link #getTypeIfRefinable}.
 */
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
  switch (node.getType()) {
    case Token.NAME:
      scope.inferSlotType(node.getString(), type);
      break;

    case Token.GETPROP:
      String qualifiedName = node.getQualifiedName();
      Preconditions.checkNotNull(qualifiedName);

      JSType origType = node.getJSType();
      origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
      scope.inferQualifiedSlot(node, qualifiedName, origType, type);
      break;

    case Token.THIS:
      // "this" references aren't currently modeled in the CFG.
      break;

    default:
      throw new IllegalArgumentException("Node cannot be refined. \n" +
          node.toStringTree());
  }
}
 
Example 9
Source File: ExpressionDecomposer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If required, rewrite the statement containing the expression.
 * @param expression The expression to be exposed.
 * @see #canExposeExpression
 */
void maybeExposeExpression(Node expression) {
  // If the expression needs to exposed.
  int i = 0;
  while (DecompositionType.DECOMPOSABLE == canExposeExpression(expression)) {
    exposeExpression(expression);
    i++;
    if (i > MAX_INTERATIONS) {
      throw new IllegalStateException(
          "DecomposeExpression depth exceeded on :\n" +
          expression.toStringTree());
    }
  }
}