com.google.javascript.jscomp
Class PeepholeSubstituteAlternateSyntax

java.lang.Object
  extended by com.google.javascript.jscomp.PeepholeSubstituteAlternateSyntax

public class PeepholeSubstituteAlternateSyntax
extends Object

A peephole optimization that minimizes code by simplifying conditional expressions, replacing IFs with HOOKs, replacing object constructors with literals, and simplifying returns.


Constructor Summary
PeepholeSubstituteAlternateSyntax()
           
 
Method Summary
protected  boolean areNodesEqualForInlining(Node n1, Node n2)
          Are the nodes equal for the purpose of inlining? If type aware optimizations are on, type equality is checked.
protected  void error(DiagnosticType diagnostic, Node n)
          Helper method for reporting an error to the compiler when applying a peephole optimization.
protected  boolean isASTNormalized()
          Is the current AST normalized? (e.g.
 Node optimizeSubtree(Node node)
          Tries apply our various peephole minimizations on the passed in node.
protected  void reportCodeChange()
          Helper method for telling the compiler that something has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PeepholeSubstituteAlternateSyntax

public PeepholeSubstituteAlternateSyntax()
Method Detail

optimizeSubtree

public Node optimizeSubtree(Node node)
Tries apply our various peephole minimizations on the passed in node.

Parameters:
node - The subtree that will be optimized.
Returns:
The new version of the subtree (or null if the subtree or one of its parents was removed from the AST). If the subtree has not changed, this method must return subtree.

error

protected void error(DiagnosticType diagnostic,
                     Node n)
Helper method for reporting an error to the compiler when applying a peephole optimization.

Parameters:
diagnostic - The error type
n - The node for which the error should be reported

reportCodeChange

protected void reportCodeChange()
Helper method for telling the compiler that something has changed. Subclasses must call these if they have changed the AST.


areNodesEqualForInlining

protected boolean areNodesEqualForInlining(Node n1,
                                           Node n2)
Are the nodes equal for the purpose of inlining? If type aware optimizations are on, type equality is checked.


isASTNormalized

protected boolean isASTNormalized()
Is the current AST normalized? (e.g. has the Normalize pass been run and has the Denormalize pass not yet been run?)