Package com.google.javascript.jscomp.DefinitionsRemover

Examples of com.google.javascript.jscomp.DefinitionsRemover.Definition


      DefinitionSite defSite = defFinder.getDefinitionForFunction(function);
      if (defSite == null) {
        return false;
      }

      Definition definition = defSite.definition;

      // Be conservative, don't try to optimize any declaration that isn't as
      // simple function declaration or assignment.
      if (!SimpleDefinitionFinder.isSimpleFunctionDeclaration(function)) {
        return false;
View Full Code Here


    /**
     * @return Whether the definitionSite represents a function whose call
     *      signature can be modified.
     */
    private boolean canChangeSignature(Node function) {
      Definition definition = getFunctionDefinition(function);
      CodingConvention convention = compiler.getCodingConvention();

      Preconditions.checkState(!definition.isExtern());

      Collection<UseSite> useSites = defFinder.getUseSites(definition);
      for (UseSite site : useSites) {
        Node parent = site.node.getParent();

View Full Code Here

     */
    private Definition getFunctionDefinition(Node function) {
      DefinitionSite definitionSite = defFinder.getDefinitionForFunction(
          function);
      Preconditions.checkNotNull(definitionSite);
      Definition definition = definitionSite.definition;
      Preconditions.checkState(!definitionSite.inExterns);
      Preconditions.checkState(definition.getRValue() == function);
      return definition;
    }
View Full Code Here

    aliasedFunctions = Sets.newHashSet();
    functionsExposedToCallOrApply = Sets.newHashSet();

    for (DefinitionSite definitionSite : finder.getDefinitionSites()) {
      Definition definition = definitionSite.definition;

      if (!definition.isExtern()) {
        Node rValue = definition.getRValue();

        if (rValue != null && rValue.isFunction()) {
          // rValue is a Token.FUNCTION from a definition

          for (UseSite useSite : finder.getUseSites(definition)) {
View Full Code Here

   * @return Whether the definitionSite represents a function whose call
   *      signature can be modified.
   */
  private static boolean canChangeSignature(
      DefinitionSite definitionSite, SimpleDefinitionFinder defFinder) {
    Definition definition = definitionSite.definition;

    if (definitionSite.inExterns) {
      return false;
    }

    // Only functions may be rewritten.
    // Functions that access "arguments" are not eligible since
    // rewrite changes the structure of this object.
    Node rValue = definition.getRValue();
    if (rValue == null ||
        !rValue.isFunction() ||
        NodeUtil.isVarArgsFunction(rValue)) {
      return false;
    }
View Full Code Here

      DefinitionSite defSite, SimpleDefinitionFinder defFinder) {
    // Count the maximum number of arguments passed into this function all
    // all points of the program.
    int maxArgs = -1;

    Definition definition = defSite.definition;
    Collection<UseSite> useSites = defFinder.getUseSites(definition);
    for (UseSite site : useSites) {
      Preconditions.checkState(SimpleDefinitionFinder.isCallOrNewSite(site));
      Node call = site.node.getParent();

      int numArgs = call.getChildCount() - 1;
      if (numArgs > maxArgs) {
        maxArgs = numArgs;
      }
    }

    eliminateParamsAfter(definition.getRValue(), maxArgs);
  }
View Full Code Here

    List<Parameter> parameters = Lists.newArrayList();
    boolean firstCall = true;

    // Build a list of parameters to remove
    Definition definition = defSite.definition;
    Collection<UseSite> useSites = defFinder.getUseSites(definition);
    boolean continueLooking = false;
    for (UseSite site : useSites) {
      Preconditions.checkState(SimpleDefinitionFinder.isCallOrNewSite(site));
      Node call = site.node.getParent();

      Node cur = call.getFirstChild();
      if (firstCall) {
        // Use the first call to construct a list of parameters of the
        // function.
        continueLooking = buildParameterList(parameters, cur, site.scope);
        firstCall = false;
      } else {
        continueLooking = findFixedParameters(parameters, cur);
      }
      if (!continueLooking) {
        return;
      }
    }

    continueLooking = adjustForSideEffects(parameters);
    if (!continueLooking) {
      return;
    }

    // Remove the constant parameters in all the calls
    for (UseSite site : useSites) {
      Preconditions.checkState(SimpleDefinitionFinder.isCallOrNewSite(site));
      Node call = site.node.getParent();

      optimizeCallSite(defFinder, parameters, call);
    }

    // Remove the constant parameters in the definitions and add it as a local
    // variable.
    Node function = definition.getRValue();
    if (function.isFunction()) {
      optimizeFunctionDefinition(parameters, function);
    }
  }
View Full Code Here

   */
  private void fillInFunctionInformation(DefinitionProvider provider) {
    SimpleDefinitionFinder finder = (SimpleDefinitionFinder) provider;

    for (DefinitionSite definitionSite : finder.getDefinitionSites()) {
      Definition definition = definitionSite.definition;

      Function function = lookupFunctionForDefinition(definition);

      if (function != null) {
        for (UseSite useSite : finder.getUseSites(definition)) {
View Full Code Here

   * - The definition is never accessed outside a function call context.
   */
  private boolean callResultsMaybeUsed(
      SimpleDefinitionFinder defFinder, DefinitionSite definitionSite) {

    Definition definition = definitionSite.definition;

    // Assume non-function definitions results are used.
    Node rValue = definition.getRValue();
    if (rValue == null || !NodeUtil.isFunction(rValue)) {
      return true;
    }

    // Be conservative, don't try to optimize any declaration that isn't as
View Full Code Here

   * - Definition must happen in a module loaded before the first use.
   */
  private boolean isEligibleDefinition(SimpleDefinitionFinder defFinder,
                                       DefinitionSite definitionSite) {

    Definition definition = definitionSite.definition;
    JSModule definitionModule = definitionSite.module;

    // Only functions may be rewritten.
    // Functions that access "arguments" are not eligible since
    // rewrite changes the structure of this object.
    Node rValue = definition.getRValue();
    if (rValue == null ||
        !NodeUtil.isFunction(rValue) ||
        NodeUtil.isVarArgsFunction(rValue)) {
      return false;
    }

    // Exporting a method prevents rewrite.
    Node lValue = definition.getLValue();
    if ((lValue == null) ||
        !NodeUtil.isGetProp(lValue)) {
      return false;
    }
    CodingConvention codingConvention = compiler.getCodingConvention();
View Full Code Here

TOP

Related Classes of com.google.javascript.jscomp.DefinitionsRemover.Definition

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.