com.google.javascript.jscomp
Class SpecializeModule.SpecializationState

java.lang.Object
  extended by com.google.javascript.jscomp.SpecializeModule.SpecializationState
Enclosing class:
SpecializeModule

public static class SpecializeModule.SpecializationState
extends Object

A class to hold state during SpecializeModule. An instance of this class is passed to specialization-aware compiler passes -- they use it to communicate with SpecializeModule. SpecializationAware optimizations are required to keep track of the functions they remove and the functions that they modify so that the fixups can be added. However, not all functions can be fixed up. Specialization-aware classes *must* call reportSpecializedFunction(com.google.javascript.rhino.Node) when a function is modified during specialization and reportRemovedFunction(com.google.javascript.rhino.Node, com.google.javascript.rhino.Node) when one is removed. Also, when specializing, they must query canFixupFunction(com.google.javascript.rhino.Node) before modifying a function. This two-way communication, is the reason we don't use AstChangeProxy to report code changes.


Constructor Summary
SpecializeModule.SpecializationState(com.google.javascript.jscomp.SimpleFunctionAliasAnalysis initialModuleAliasAnalysis)
           
 
Method Summary
 boolean canFixupFunction(Node functionNode)
          Returns true if the function can be fixed up (that is, if it can be safely removed or specialized).
 boolean canFixupSpecializedFunctionContainingNode(Node n)
          Returns true if the function containing n can be fixed up.
 Set<Node> getRemovedFunctions()
          The functions removed by this compiler pass.
 Set<Node> getSpecializedFunctions()
          Returns the functions specialized by this compiler pass.
 void reportRemovedFunction(Node functionNode, Node declaringBlock)
          Reports that a function has been removed.
 void reportSpecializedFunction(Node functionNode)
          Reports that a function has been specialized.
 void reportSpecializedFunctionContainingNode(Node node)
          Reports that the function containing the node has been specialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpecializeModule.SpecializationState

public SpecializeModule.SpecializationState(com.google.javascript.jscomp.SimpleFunctionAliasAnalysis initialModuleAliasAnalysis)
Method Detail

getSpecializedFunctions

public Set<Node> getSpecializedFunctions()
Returns the functions specialized by this compiler pass.


reportSpecializedFunction

public void reportSpecializedFunction(Node functionNode)
Reports that a function has been specialized.

Parameters:
functionNode - A specialized AST node with type Token.FUNCTION

reportSpecializedFunctionContainingNode

public void reportSpecializedFunctionContainingNode(Node node)
Reports that the function containing the node has been specialized.


getRemovedFunctions

public Set<Node> getRemovedFunctions()
The functions removed by this compiler pass.


reportRemovedFunction

public void reportRemovedFunction(Node functionNode,
                                  Node declaringBlock)
Reports that a function has been removed.

Parameters:
functionNode - A removed AST node with type Token.FUNCTION
declaringBlock - If the function declaration puts a variable in the scope, we need to have a VAR statement in the scope where the function is declared. Null if the function does not put a name in the scope.

canFixupFunction

public boolean canFixupFunction(Node functionNode)
Returns true if the function can be fixed up (that is, if it can be safely removed or specialized).

In order to be safely fixed up, a function must be:

 - in the global scope
 - not aliased in the initial module
 - of one of the following forms:
    function f() {}
    var f = function() {}
    f = function(){}
    var ns = {}; ns.f = function() {}
    SomeClass.prototype.foo = function() {};
 

Anonymous functions cannot be safely fixed up, nor can functions that have been aliased.

Some functions declared as object literals could be safely fixed up, however we do not currently support this.


canFixupSpecializedFunctionContainingNode

public boolean canFixupSpecializedFunctionContainingNode(Node n)
Returns true if the function containing n can be fixed up. Also returns true if n is in the global scope -- since it is always safe to specialize the global scope.