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

The following examples show how to use com.google.javascript.rhino.Token#CALL . 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: Closure_14_ControlFlowAnalysis_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines if the subtree might throw an exception.
 */
public static boolean mayThrowException(Node n) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.THROW:
    case Token.NEW:
    case Token.ASSIGN:
    case Token.INC:
    case Token.DEC:
    case Token.INSTANCEOF:
      return true;
    case Token.FUNCTION:
      return false;
  }
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: Closure_61_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
static boolean nodeTypeMayHaveSideEffects(Node n, AbstractCompiler compiler) {
  if (isAssignmentOp(n)) {
    return true;
  }

  switch(n.getType()) {
    case Token.DELPROP:
    case Token.DEC:
    case Token.INC:
    case Token.THROW:
      return true;
    case Token.CALL:
      return NodeUtil.functionCallHasSideEffects(n, compiler);
    case Token.NEW:
      return NodeUtil.constructorCallHasSideEffects(n, compiler);
    case Token.NAME:
      // A variable definition.
      return n.hasChildren();
    default:
      return false;
  }
}
 
Example 3
Source File: CheckProvides.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.CALL:
      String providedClassName =
        codingConvention.extractClassNameIfProvide(n, parent);
      if (providedClassName != null) {
        provides.put(providedClassName, n);
      }
      break;
    case Token.FUNCTION:
      visitFunctionNode(n, parent);
      break;
    case Token.SCRIPT:
      visitScriptNode(t, n);
  }
}
 
Example 4
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
static boolean nodeTypeMayHaveSideEffects(Node n, AbstractCompiler compiler) {
  if (isAssignmentOp(n)) {
    return true;
  }

  switch(n.getType()) {
    case Token.DELPROP:
    case Token.DEC:
    case Token.INC:
    case Token.THROW:
      return true;
    case Token.CALL:
      return NodeUtil.functionCallHasSideEffects(n, compiler);
    case Token.NEW:
      return NodeUtil.constructorCallHasSideEffects(n, compiler);
    case Token.NAME:
      // A variable definition.
      return n.hasChildren();
    default:
      return false;
  }
}
 
Example 5
Source File: Closure_55_FunctionRewriter_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Builds a method call based on the the given method name,
 * argument and history.
 *
 * @param methodName Method to call.
 * @param argumentNode Method argument.
 * @param lineno line number in original source.
 * @param charno character offset in original line.
 */
protected final Node buildCallNode(String methodName, Node argumentNode,
                                   int lineno, int charno) {
  Node call = new Node(Token.CALL, lineno, charno);
  call.putBooleanProp(Node.FREE_CALL, true);
  call.addChildToBack(Node.newString(Token.NAME, methodName));
  if (argumentNode != null) {
    call.addChildToBack(argumentNode.cloneTree());
  }
  return call;
}
 
Example 6
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;

    case Token.NOT:
      return parent.getParent().isOr() &&
          parent.getParent().getFirstChild() == parent;
  }
  return false;
}
 
Example 7
Source File: Nopol2017_0029_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;

    case Token.NOT:
      return parent.getParent().isOr() &&
          parent.getParent().getFirstChild() == parent;
  }
  return false;
}
 
Example 8
Source File: Closure_61_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @return Whether node is a call to methodName.
 *    a.f(...)
 *    a['f'](...)
 */
static boolean isObjectCallMethod(Node callNode, String methodName) {
  if (callNode.getType() == Token.CALL) {
    Node functionIndentifyingExpression = callNode.getFirstChild();
    if (isGet(functionIndentifyingExpression)) {
      Node last = functionIndentifyingExpression.getLastChild();
      if (last != null && last.getType() == Token.STRING) {
        String propName = last.getString();
        return (propName.equals(methodName));
      }
    }
  }
  return false;
}
 
Example 9
Source File: Closure_75_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * A new CALL node with the "FREE_CALL" set based on call target.
 */
static Node newCallNode(Node callTarget, Node... parameters) {
  boolean isFreeCall = isName(callTarget);
  Node call = new Node(Token.CALL, callTarget);
  call.putBooleanProp(Node.FREE_CALL, isFreeCall);
  for (Node parameter : parameters) {
    call.addChildToBack(parameter);
  }
  return call;
}
 
Example 10
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;

    case Token.NOT:
      return parent.getParent().getType() == Token.OR &&
          parent.getParent().getFirstChild() == parent;
  }
  return false;
}
 
Example 11
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

    case Token.NOT:
      return parent.getParent().isOr() &&
          parent.getParent().getFirstChild() == parent;
  }
  return false;
}
 
Example 12
Source File: Closure_75_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.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.STRING:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Node.tokenToName(type) +
                             " (type " + type + ")");
  }
}
 
Example 13
Source File: Closure_60_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param locals A predicate to apply to unknown local values.
 * @return Whether the node is known to be a value that is not a reference
 *     outside the expression scope.
 */
static boolean evaluatesToLocalValue(Node value, Predicate<Node> locals) {
  switch (value.getType()) {
    case Token.ASSIGN:
      // A result that is aliased by a non-local name, is the effectively the
      // same as returning a non-local name, but this doesn't matter if the
      // value is immutable.
      return NodeUtil.isImmutableValue(value.getLastChild())
          || (locals.apply(value)
              && evaluatesToLocalValue(value.getLastChild(), locals));
    case Token.COMMA:
      return evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.AND:
    case Token.OR:
      return evaluatesToLocalValue(value.getFirstChild(), locals)
         && evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.HOOK:
      return evaluatesToLocalValue(value.getFirstChild().getNext(), locals)
         && evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.INC:
    case Token.DEC:
      if (value.getBooleanProp(Node.INCRDECR_PROP)) {
        return evaluatesToLocalValue(value.getFirstChild(), locals);
      } else {
        return true;
      }
    case Token.THIS:
      return locals.apply(value);
    case Token.NAME:
      return isImmutableValue(value) || locals.apply(value);
    case Token.GETELEM:
    case Token.GETPROP:
      // There is no information about the locality of object properties.
      return locals.apply(value);
    case Token.CALL:
      return callHasLocalResult(value)
          || isToStringMethodCall(value)
          || locals.apply(value);
    case Token.NEW:
      return newHasLocalResult(value)
             || locals.apply(value);
    case Token.FUNCTION:
    case Token.REGEXP:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      // Literals objects with non-literal children are allowed.
      return true;
    case Token.DELPROP:
    case Token.IN:
      // TODO(johnlenz): should IN operator be included in #isSimpleOperator?
      return true;
    default:
      // Other op force a local value:
      //  x = '' + g (x is now an local string)
      //  x -= g (x is now an local number)
      if (isAssignmentOp(value)
          || isSimpleOperator(value)
          || isImmutableValue(value)) {
        return true;
      }

      throw new IllegalStateException(
          "Unexpected expression node" + value +
          "\n parent:" + value.getParent());
  }
}
 
Example 14
Source File: Closure_119_GlobalNamespace_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Updates our representation of the global namespace to reflect a read
 * of a global name.
 *
 * @param module The current module
 * @param scope The current scope
 * @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(JSModule module, Scope scope,
    Node n, Node parent, String name) {
  if (maybeHandlePrototypePrefix(module, scope, n, parent, name)) {
    return;
  }

  Ref.Type type = Ref.Type.DIRECT_GET;
  if (parent != null) {
    switch (parent.getType()) {
      case Token.IF:
      case Token.INSTANCEOF:
      case Token.TYPEOF:
      case Token.VOID:
      case Token.NOT:
      case Token.BITNOT:
      case Token.POS:
      case Token.NEG:
        break;
      case Token.CALL:
        if (n == parent.getFirstChild()) {
          // It is a call target
          type = Ref.Type.CALL_GET;
        } else if (isClassDefiningCall(parent)) {
          type = Ref.Type.DIRECT_GET;
        } else {
          type = 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(module, scope, 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(module, scope, parent, name);
        }
        break;
      case Token.DELPROP:
        type = Ref.Type.DELETE_PROP;
        break;
      default:
        type = Ref.Type.ALIASING_GET;
        break;
    }
  }

  handleGet(module, scope, n, parent, name, type);
}
 
Example 15
Source File: Closure_53_InlineObjectLiterals_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Counts the number of direct (full) references to an object.
 * Specifically we check for references of the following type:
 * <pre>
 *   x;
 *   x.fn();
 * </pre>
 */
private boolean isInlinableObject(List<Reference> refs) {
  boolean ret = false;
  for (Reference ref : refs) {
    Node name = ref.getNode();
    Node parent = ref.getParent();
    Node gramps = ref.getGrandparent();

    // Ignore indirect references, like x.y (except x.y(), since
    // the function referenced by y might reference 'this').
    //
    if (parent.getType() == Token.GETPROP) {
      Preconditions.checkState(parent.getFirstChild() == name);
      // A call target maybe using the object as a 'this' value.
      if (gramps.getType() == Token.CALL
          && gramps.getFirstChild() == parent) {
        return false;
      }
      continue;
    }

    // Only rewrite VAR declarations or simple assignment statements
    if (!isVarOrAssignExprLhs(name)) {
       return false;
    }

    Node val = ref.getAssignedValue();
    if (val == null) {
      // A var with no assignment.
      continue;
    }

    // We're looking for object literal assignments only.
    if (val.getType() != Token.OBJECTLIT) {
      return false;
    }

    // Make sure that the value is not self-refential. IOW,
    // disallow things like x = {b: x.a}.
    //
    // TODO: Only exclude unorderable self-referential
    // assignments. i.e. x = {a: x.b, b: x.a} is not orderable,
    // but x = {a: 1, b: x.a} is.
    //
    // Also, ES5 getters/setters aren't handled by this pass.
    for (Node child = val.getFirstChild(); child != null;
         child = child.getNext()) {
      if (child.getType() == Token.GET ||
          child.getType() == Token.SET) {
        // ES5 get/set not supported.
        return false;
      }
      Node childVal = child.getFirstChild();
      // Check if childVal is the parent of any of the passed in
      // references, as that is how self-referential assignments
      // will happen.
      for (Reference t : refs) {
        Node refNode = t.getParent();
        while (!NodeUtil.isStatementBlock(refNode)) {
          if (refNode == childVal) {
            // There's a self-referential assignment
            return false;
          }
          refNode = refNode.getParent();
        }
      }
    }


    // We have found an acceptable object literal assignment. As
    // long as there are no other assignments that mess things up,
    // we can inline.
    ret = true;
  }
  return ret;
}
 
Example 16
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 17
Source File: jKali_003_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 18
Source File: CrossModuleCodeMotion.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines whether the given NAME node belongs to a declaration that
 * can be moved across modules. If it is, registers it properly.
 *
 * There are four types of movable declarations:
 * 1) var NAME = [movable object];
 * 2) function NAME() {}
 * 3) NAME = [movable object];
 *    NAME.prop = [movable object];
 *    NAME.prop.prop2 = [movable object];
 *    etc.
 * 4) Class-defining function calls, like "inherits" and "mixin".
 *    NAME.inherits([some other name]);
 * where "movable object" is a literal or a function.
 */
private boolean maybeProcessDeclaration(NodeTraversal t, Node name,
    Node parent, NamedInfo info) {
  Node gramps = parent.getParent();
  switch (parent.getType()) {
    case Token.VAR:
      if (canMoveValue(name.getFirstChild())) {
        return info.addDeclaration(
            new Declaration(t.getModule(), name, parent, gramps));
      }
      return false;

    case Token.FUNCTION:
      if (NodeUtil.isFunctionDeclaration(parent)) {
        return info.addDeclaration(
            new Declaration(t.getModule(), name, parent, gramps));
      }
      return false;

    case Token.ASSIGN:
    case Token.GETPROP:
      Node child = name;

      // Look for assignment expressions where the name is the root
      // of a qualified name on the left hand side of the assignment.
      for (Node current : name.getAncestors()) {
        if (current.isGetProp()) {
          // fallthrough
        } else if (current.isAssign() &&
                   current.getFirstChild() == child) {
          Node currentParent = current.getParent();
          if (currentParent.isExprResult() &&
              canMoveValue(current.getLastChild())) {
            return info.addDeclaration(
                new Declaration(t.getModule(), current, currentParent,
                    currentParent.getParent()));
          }
        } else {
          return false;
        }

        child = current;
      }
      return false;

    case Token.CALL:
      if (NodeUtil.isExprCall(gramps)) {
        SubclassRelationship relationship =
            compiler.getCodingConvention().getClassesDefinedByCall(parent);
        if (relationship != null &&
            name.getString().equals(relationship.subclassName)) {
          return info.addDeclaration(
              new Declaration(t.getModule(), parent, gramps,
                  gramps.getParent()));
        }
      }
      return false;

    default:
      return false;
  }
}
 
Example 19
Source File: Closure_86_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param locals A predicate to apply to unknown local values.
 * @return Whether the node is known to be a value that is not a reference
 *     outside the expression scope.
 */
static boolean evaluatesToLocalValue(Node value, Predicate<Node> locals) {
  switch (value.getType()) {
    case Token.ASSIGN:
      // A result that is aliased by a non-local name, is the effectively the
      // same as returning a non-local name, but this doesn't matter if the
      // value is immutable.
      return NodeUtil.isImmutableValue(value.getLastChild())
          || (locals.apply(value)
              && evaluatesToLocalValue(value.getLastChild(), locals));
    case Token.COMMA:
      return evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.AND:
    case Token.OR:
      return evaluatesToLocalValue(value.getFirstChild(), locals)
         && evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.HOOK:
      return evaluatesToLocalValue(value.getFirstChild().getNext(), locals)
         && evaluatesToLocalValue(value.getLastChild(), locals);
    case Token.INC:
    case Token.DEC:
      if (value.getBooleanProp(Node.INCRDECR_PROP)) {
        return evaluatesToLocalValue(value.getFirstChild(), locals);
      } else {
        return true;
      }
    case Token.THIS:
      return locals.apply(value);
    case Token.NAME:
      return isImmutableValue(value) || locals.apply(value);
    case Token.GETELEM:
    case Token.GETPROP:
      // There is no information about the locality of object properties.
      return locals.apply(value);
    case Token.CALL:
      return callHasLocalResult(value)
          || isToStringMethodCall(value)
          || locals.apply(value);
    case Token.NEW:
      // TODO(nicksantos): This needs to be changed so that it
      // returns true iff we're sure the value was never aliased from inside
      // the constructor (similar to callHasLocalResult)
      return true;
    case Token.FUNCTION:
    case Token.REGEXP:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      // Literals objects with non-literal children are allowed.
      return true;
    case Token.IN:
      // TODO(johnlenz): should IN operator be included in #isSimpleOperator?
      return true;
    default:
      // Other op force a local value:
      //  x = '' + g (x is now an local string)
      //  x -= g (x is now an local number)
      if (isAssignmentOp(value)
          || isSimpleOperator(value)
          || isImmutableValue(value)) {
        return true;
      }

      throw new IllegalStateException(
          "Unexpected expression node" + value +
          "\n parent:" + value.getParent());
  }
}
 
Example 20
Source File: Closure_80_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Is this a CALL node?
 */
static boolean isCall(Node n) {
  return n.getType() == Token.CALL;
}