Package com.google.javascript.jscomp.Scope

Examples of com.google.javascript.jscomp.Scope.Var


   * @param node The CFG node where the definition should be record to.
   *     {@code null} if this is a conditional define.
   */
  private void addToDefIfLocal(String name, @Nullable Node node,
      @Nullable Node rValue, MustDef def) {
    Var var = jsScope.getVar(name);

    // var might be null because the variable might be defined in the extern
    // that we might not traverse.
    if (var == null || var.scope != jsScope) {
      return;
View Full Code Here


    }
  }

  private void escapeParameters(MustDef output) {
    for (Iterator<Var> i = jsScope.getVars(); i.hasNext();) {
      Var v = i.next();
      if (isParameter(v)) {
        // Assume we no longer know where the parameter comes from
        // anymore.
        output.reachingDef.put(v, null);
      }
View Full Code Here

    NodeTraversal.traverse(compiler, rValue,
        new AbstractCfgNodeTraversalCallback() {
      @Override
      public void visit(NodeTraversal t, Node n, Node parent) {
        if (n.isName()) {
          Var dep = jsScope.getVar(n.getString());
          if (dep == null) {
            def.unknownDependencies = true;
          } else {
            def.depends.add(dep);
          }
View Full Code Here

    }

    public MustDef(Iterator<Var> vars) {
      this();
      while (vars.hasNext()) {
        Var var = vars.next();
        // Every variable in the scope is defined once in the beginning of the
        // function: all the declared variables are undefined, all functions
        // have been assigned and all arguments has its value from the caller.
        reachingDef.put(var, new Definition(var.scope.getRootNode()));
      }
View Full Code Here

      MustDef result = new MustDef();
      Map<Var, Definition> resultMap = result.reachingDef;

      // Take the join of all variables that are not TOP in this.
      for (Map.Entry<Var, Definition> varEntry : a.reachingDef.entrySet()) {
        Var var = varEntry.getKey();
        Definition aDef = varEntry.getValue();

        if (aDef == null) {
          // "a" is BOTTOM implies that the variable has more than one possible
          // definition. We set the join of this to be BOTTOM regardless of what
          // "b" might be.
          resultMap.put(var, null);
          continue;
        }

        if (b.reachingDef.containsKey(var)) {
          Definition bDef = b.reachingDef.get(var);

          if (aDef.equals(bDef)) {
            resultMap.put(var, aDef);
          } else {
            resultMap.put(var, null);
          }
        } else {
          resultMap.put(var, aDef);
        }
      }

      // Take the join of all variables that are not TOP in other but it is TOP
      // in this.
      for (Map.Entry<Var, Definition> entry : b.reachingDef.entrySet()) {
        Var var = entry.getKey();
        if (!a.reachingDef.containsKey(var)) {
          resultMap.put(var, entry.getValue());
        }
      }
      return result;
View Full Code Here

  @Override
  public void inferQualifiedSlot(Node node, String symbol, JSType bottomType,
      JSType inferredType) {
    Scope functionScope = getFunctionScope();
    if (functionScope.isLocal()) {
      Var v  = functionScope.getVar(symbol);
      if (v == null && !functionScope.isBottom()) {
        functionScope.declare(symbol, node, bottomType, null);
      }

      if (v != null && !v.isTypeInferred()) {
        JSType declaredType = v.getType();
        // Use the inferred type over the declared type only if the
        // inferred type is a strict subtype of the declared type.
        if (declaredType != null && inferredType.isSubtype(declaredType)
            && !declaredType.isSubtype(inferredType)) {
          inferSlotType(symbol, inferredType);
View Full Code Here

   */
  @Override
  public void completeScope(StaticScope<JSType> staticScope) {
    Scope scope = (Scope) staticScope;
    for (Iterator<Var> it = scope.getVars(); it.hasNext();) {
      Var var = it.next();
      if (var.isTypeInferred()) {
        JSType type = var.getType();
        if (type == null || type.isUnknownType()) {
          JSType flowType = getSlot(var.getName()).getType();
          var.setType(flowType);
        }
      }
    }
  }
View Full Code Here

     */
    private boolean isLocalNameReference(NodeTraversal t, Node n) {
      // TODO(user): What happen if it is a reference to an outer local
      // variable (closures)?
      if (n.isName()) {
        Var v = t.getScope().getVar(n.getString());
        return v != null && v.isLocal();
      }
      return false;
    }
View Full Code Here

      Node msgNode, boolean isUnnamedMessage) {
    if (!isUnnamedMessage) {
      MessageLocation location = new MessageLocation(message, msgNode);
      messageNames.put(msgName, location);
    } else {
      Var var = t.getScope().getVar(msgName);
      if (var != null) {
        unnamedMessages.put(var, message);
      }
    }
  }
View Full Code Here

    boolean isUnnamedMessage = isUnnamedMessageName(msgName);
    if (!isUnnamedMessage) {
      MessageLocation location = messageNames.get(msgName);
      return location == null ? null : location.message;
    } else {
      Var var = t.getScope().getVar(msgName);
      if (var != null) {
        return unnamedMessages.get(var);
      }
    }
    return null;
View Full Code Here

TOP

Related Classes of com.google.javascript.jscomp.Scope.Var

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.