Sort & format

Review by: zundel@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9036 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JModVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JModVisitor.java
index 7e83000..73d8aa5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JModVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JModVisitor.java
@@ -264,12 +264,13 @@
       throw new InternalCompilerException("Cannot replace with null");
     }
     if (newNode == origNode) {
-      throw new InternalCompilerException("The replacement is the same as the original");
+      throw new InternalCompilerException(
+          "The replacement is the same as the original");
     }
   }
 
   private int numVisitorChanges = 0;
-  
+
   @Override
   public JNode accept(JNode node) {
     return accept(node, false);
@@ -370,10 +371,10 @@
   protected void madeChanges() {
     numVisitorChanges++;
   }
-  
+
   /**
-   * Call this method to indicate that a visitor has made multiple changes
-   * to the tree.  Used to determine when the optimization pass can exit.
+   * Call this method to indicate that a visitor has made multiple changes to
+   * the tree. Used to determine when the optimization pass can exit.
    */
   protected void madeChanges(int numMods) {
     numVisitorChanges += numMods;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index 915a509..936cdf9 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2008 Google Inc.
- *
+ * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- *
+ * 
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -80,15 +80,13 @@
  * Attempts to remove dead code.
  */
 public class DeadCodeElimination {
-  public static final String NAME = DeadCodeElimination.class.getSimpleName();
-
   /**
    * Eliminates dead or unreachable code when possible, and makes local
    * simplifications like changing "<code>x || true</code>" to "<code>x</code>".
-   *
+   * 
    * TODO: leverage ignoring expression output more to remove intermediary
    * operations in favor of pure side effects.
-   *
+   * 
    * TODO(spoon): move more simplifications into methods like
    * {@link #cast(JExpression, SourceInfo, JType, JExpression) simplifyCast}, so
    * that more simplifications can be made on a single pass through a tree.
@@ -101,7 +99,7 @@
      * children whose result does not matter to this set during the parent's
      * <code>visit()</code> method. It should then remove those children during
      * its own <code>endVisit()</code>.
-     *
+     * 
      * TODO: there's a latent bug here: some immutable nodes (such as literals)
      * can be multiply referenced in the AST. In theory, one reference to that
      * node could be put into this set while another reference actually contains
@@ -714,7 +712,7 @@
 
     /**
      * Evaluate <code>lhs == rhs</code>.
-     *
+     * 
      * @param lhs Any literal other than null.
      * @param rhs Any literal other than null.
      * @return Whether <code>lhs == rhs</code> will evaluate to
@@ -738,7 +736,7 @@
 
     /**
      * Static evaluation of a unary operation on a literal.
-     *
+     * 
      * @return Whether a change was made
      */
     private boolean evalOpOnLiteral(JUnaryOperator op, JValueLiteral exp,
@@ -787,7 +785,7 @@
 
     /**
      * Static evaluation of a binary operation on two literals.
-     *
+     * 
      * @return Whether a change was made
      */
     private boolean evalOpOnLiterals(JBinaryOperator op, JValueLiteral lhs,
@@ -1292,11 +1290,11 @@
 
     /**
      * Simplify short circuit AND expressions.
-     *
+     * 
      * <pre>
      * if (true && isWhatever()) -> if (isWhatever())
      * if (false && isWhatever()) -> if (false)
-     *
+     * 
      * if (isWhatever() && true) -> if (isWhatever())
      * if (isWhatever() && false) -> if (false), unless side effects
      * </pre>
@@ -1322,11 +1320,11 @@
 
     /**
      * Simplify short circuit OR expressions.
-     *
+     * 
      * <pre>
      * if (true || isWhatever()) -> if (true)
      * if (false || isWhatever()) -> if (isWhatever())
-     *
+     * 
      * if (isWhatever() || false) -> if (isWhatever())
      * if (isWhatever() || true) -> if (true), unless side effects
      * </pre>
@@ -1459,10 +1457,10 @@
 
     /**
      * Simplify the expression <code>-exp</code>.
-     *
+     * 
      * @param original An expression equivalent to <code>-exp</code>.
      * @param exp The expression to negate.
-     *
+     * 
      * @return A simplified expression equivalent to <code>- exp</code>.
      */
     private JExpression simplifyNegate(JExpression original, JExpression exp) {
@@ -1505,7 +1503,7 @@
 
     /**
      * Simplify XOR expressions.
-     *
+     * 
      * <pre>
      * true ^ x     -> !x
      * false ^ x    ->  x
@@ -1673,20 +1671,20 @@
         /*
          * If there are only two statements, we know it's a case statement and
          * something with an effect.
-         *
+         * 
          * TODO: make this more sophisticated; what we should really care about
          * is how many case statements it contains, not how many statements:
-         *
+         * 
          * switch(i) { default: a(); b(); c(); }
-         *
+         * 
          * becomes { a(); b(); c(); }
-         *
+         * 
          * switch(i) { case 1: a(); b(); c(); }
-         *
+         * 
          * becomes if (i == 1) { a(); b(); c(); }
-         *
+         * 
          * switch(i) { case 1: a(); b(); break; default: c(); d(); }
-         *
+         * 
          * becomes if (i == 1) { a(); b(); } else { c(); d(); }
          */
         JCaseStatement caseStatement = (JCaseStatement) body.getStatements().get(
@@ -1757,7 +1755,7 @@
   /**
    * Examines code to find out whether it contains any break or continue
    * statements.
-   *
+   * 
    * TODO: We could be more sophisticated with this. A nested while loop with an
    * unlabeled break should not cause this visitor to return false. Nor should a
    * labeled break break to another context.
@@ -1780,6 +1778,8 @@
     }
   }
 
+  public static final String NAME = DeadCodeElimination.class.getSimpleName();
+
   public static OptimizerStats exec(JProgram program) {
     return new DeadCodeElimination(program).execImpl(program);
   }
@@ -1810,11 +1810,11 @@
 
   private OptimizerStats execImpl(JNode node) {
     OptimizerStats stats = new OptimizerStats(NAME);
-    Event optimizeEvent =
-      SpeedTracerLogger.start(CompilerEventType.OPTIMIZE, "optimizer", NAME);
+    Event optimizeEvent = SpeedTracerLogger.start(CompilerEventType.OPTIMIZE,
+        "optimizer", NAME);
 
     // TODO(zundel): see if this loop can be removed and all work done in one
-    //   pass of the optimizer to improve performance.
+    // pass of the optimizer to improve performance.
     while (true) {
       DeadCodeVisitor deadCodeVisitor = new DeadCodeVisitor();
       deadCodeVisitor.accept(node);
@@ -1823,7 +1823,7 @@
         break;
       }
     }
-    
+
     optimizeEvent.end("didChange", "" + stats.didChange());
     return stats;
   }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
index d7fea50..edb1257 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2007 Google Inc.
- *
+ * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- *
+ * 
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -48,18 +48,17 @@
  * Inline methods that can be inlined. The current implementation limits the
  * methods that can be inlined to those that are composed of at most two
  * top-level expressions.
- *
+ * 
  * Future improvements will allow more complex methods to be inlined based on
  * the number of call sites, as well as adding support for more complex target
  * method expressions.
  */
 public class MethodInliner {
-  public static String NAME = MethodInliner.class.getSimpleName();
-
   /**
    * Clones an expression, ensuring no local or this refs.
    */
-  private static class CloneCalleeExpressionVisitor extends CloneExpressionVisitor {
+  private static class CloneCalleeExpressionVisitor extends
+      CloneExpressionVisitor {
     @Override
     public boolean visit(JLocalRef x, Context ctx) {
       throw new InternalCompilerException(
@@ -92,11 +91,6 @@
     }
 
     @Override
-    public void endVisit(JNewInstance x, Context ctx) {
-      // Do not inline new operations.
-    }
-
-    @Override
     public void endVisit(JMethodCall x, Context ctx) {
       JMethod method = x.getTarget();
 
@@ -140,6 +134,11 @@
     }
 
     @Override
+    public void endVisit(JNewInstance x, Context ctx) {
+      // Do not inline new operations.
+    }
+
+    @Override
     public boolean visit(JExpressionStatement x, Context ctx) {
       ignoringReturnValueFor = x.getExpr();
       return true;
@@ -203,7 +202,7 @@
      * Creates a JMultiExpression from a set of JExpressionStatements,
      * optionally terminated by a JReturnStatement. If the method doesn't match
      * this pattern, it returns <code>null</code>.
-     *
+     * 
      * If a method has a non-void return statement and can be represented as a
      * multi-expression, the output of the multi-expression will be the return
      * expression of the method. If the method is void, the output of the
@@ -280,7 +279,7 @@
        * Limit inlined methods to multiexpressions of length 2 for now. This
        * handles the simple { return JVariableRef; } or { expression; return
        * something; } cases.
-       *
+       * 
        * TODO: add an expression complexity analyzer.
        */
       if (targetExpr.exprs.size() > 2) {
@@ -312,7 +311,7 @@
       /*
        * There are a different number of parameters than args - this is likely a
        * result of parameter pruning. Don't consider this call site a candidate.
-       *
+       * 
        * TODO: would this be possible in the trivial delegation case?
        */
       if (x.getTarget().getParams().size() != x.getArgs().size()) {
@@ -383,7 +382,7 @@
    * Verifies that all the parameters are referenced once and only once, not
    * within a conditionally-executing expression, and any before trouble some
    * expressions evaluate. Examples of troublesome expressions include:
-   *
+   * 
    * <ul>
    * <li>assignments to any variable</li>
    * <li>expressions that throw exceptions</li>
@@ -443,7 +442,7 @@
    */
   private class ParameterReplacer extends JModVisitor {
     private final JMethodCall methodCall;
-    
+
     public ParameterReplacer(JMethodCall methodCall) {
       this.methodCall = methodCall;
     }
@@ -459,7 +458,7 @@
       JExpression arg = methodCall.getArgs().get(paramIndex);
       JExpression clone = cloner.cloneExpression(arg);
 
-      clone = maybeCast(clone, x.getType());      
+      clone = maybeCast(clone, x.getType());
       ctx.replaceMe(clone);
     }
   }
@@ -491,9 +490,11 @@
     CORRECT_ORDER, FAILS, NO_REFERENCES
   }
 
+  public static String NAME = MethodInliner.class.getSimpleName();
+
   public static OptimizerStats exec(JProgram program) {
-    Event optimizeEvent = SpeedTracerLogger.start(
-        CompilerEventType.OPTIMIZE, "optimizer", NAME);
+    Event optimizeEvent = SpeedTracerLogger.start(CompilerEventType.OPTIMIZE,
+        "optimizer", NAME);
     OptimizerStats stats = new MethodInliner(program).execImpl();
     optimizeEvent.end("didChange", "" + stats.didChange());
     return stats;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
index ff99b6d..28c6317 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2008 Google Inc.
- *
+ * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- *
+ * 
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -70,19 +70,17 @@
  * a global level based on method calls and new operations; it does not perform
  * any local code flow analysis. But, a local code flow optimization pass that
  * can eliminate method calls would allow Pruner to prune additional nodes.
- *
+ * 
  * Note: references to pruned types may still exist in the tree after this pass
  * runs, however, it should only be in contexts that do not rely on any code
  * generation for the pruned type. For example, it's legal to have a variable of
  * a pruned type, or to try to cast to a pruned type. These will cause natural
  * failures at run time; or later optimizations might be able to hard-code
  * failures at compile time.
- *
+ * 
  * Note: this class is limited to pruning parameters of static methods only.
  */
 public class Pruner {
-  private static final String NAME = Pruner.class.getSimpleName();
-
   /**
    * Remove assignments to pruned fields, locals and params. Nullify the return
    * type of methods declared to return a globally uninstantiable type. Replace
@@ -179,15 +177,6 @@
     }
 
     @Override
-    public void endVisit(JNewInstance x, Context ctx) {
-      // Did we prune the parameters of the method we're calling?
-      if (methodToOriginalParamsMap.containsKey(x.getTarget())) {
-        JMethodCall newCall = new JNewInstance(x);
-        replaceForPrunedParameters(x, newCall, ctx);
-      }
-    }
-
-    @Override
     public void endVisit(JNameOf x, Context ctx) {
       HasName node = x.getNode();
       boolean pruned;
@@ -207,6 +196,15 @@
     }
 
     @Override
+    public void endVisit(JNewInstance x, Context ctx) {
+      // Did we prune the parameters of the method we're calling?
+      if (methodToOriginalParamsMap.containsKey(x.getTarget())) {
+        JMethodCall newCall = new JNewInstance(x);
+        replaceForPrunedParameters(x, newCall, ctx);
+      }
+    }
+
+    @Override
     public void endVisit(JsniFieldRef x, Context ctx) {
       if (isPruned(x.getField())) {
         String ident = x.getIdent();
@@ -410,7 +408,7 @@
          * Don't prune parameters on unreferenced methods. The methods might not
          * be reachable through the current method traversal routines, but might
          * be used or checked elsewhere.
-         *
+         * 
          * Basically, if we never actually checked if the method parameters were
          * used or not, don't prune them. Doing so would leave a number of
          * dangling JParameterRefs that blow up in later optimizations.
@@ -501,7 +499,7 @@
       /*
        * Special case: if method is the static impl for a live instance method,
        * don't prune it unless this is the final prune.
-       *
+       * 
        * In some cases, the staticImpl can be inlined into the instance method
        * but still be needed at other call sites.
        */
@@ -520,8 +518,11 @@
     }
   }
 
+  private static final String NAME = Pruner.class.getSimpleName();
+
   public static OptimizerStats exec(JProgram program, boolean noSpecialTypes) {
-    Event optimizeEvent = SpeedTracerLogger.start(CompilerEventType.OPTIMIZE, "optimizer", NAME);
+    Event optimizeEvent = SpeedTracerLogger.start(CompilerEventType.OPTIMIZE,
+        "optimizer", NAME);
     OptimizerStats stats = new Pruner(program, noSpecialTypes).execImpl();
     optimizeEvent.end("didChange", "" + stats.didChange());
     return stats;
@@ -545,7 +546,7 @@
      * never be rescured. This in turn causes invalid references to static
      * methods, which violates otherwise good assumptions about compiler
      * operation.
-     *
+     * 
      * TODO: Remove this when ControlFlowAnalyzer doesn't special-case
      * CLH.clinit().
      */
@@ -587,7 +588,7 @@
        * never be rescured. This in turn causes invalid references to static
        * methods, which violates otherwise good assumptions about compiler
        * operation.
-       *
+       * 
        * TODO: Remove this when ControlFlowAnalyzer doesn't special-case
        * CLH.clinit().
        */
@@ -627,9 +628,9 @@
 
   private OptimizerStats execImpl() {
     OptimizerStats stats = new OptimizerStats(NAME);
-    
+
     // TODO(zundel): see if this loop can be removed and all work done in one
-    //   pass of the optimizer to improve performance.
+    // pass of the optimizer to improve performance.
     while (true) {
       ControlFlowAnalyzer livenessAnalyzer = new ControlFlowAnalyzer(program);
       if (saveCodeGenTypes) {