This patch is based on work Alex did to implement assertions.  While I'm not implementing asserts right now, what I am doing is pruning them out of the AST early so they don't block any optimizations, which they are currently doing.

Suggested by: alex.tkachman
Review by: mmendez

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@446 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
index 5d887e7..f78c8db 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
@@ -32,6 +32,7 @@
 import com.google.gwt.dev.jjs.ast.JReferenceType;
 import com.google.gwt.dev.jjs.ast.JSourceInfo;
 import com.google.gwt.dev.jjs.impl.ArrayNormalizer;
+import com.google.gwt.dev.jjs.impl.AssertionRemover;
 import com.google.gwt.dev.jjs.impl.BuildTypeMap;
 import com.google.gwt.dev.jjs.impl.CastNormalizer;
 import com.google.gwt.dev.jjs.impl.CatchBlockNormalizer;
@@ -170,8 +171,6 @@
     program.addEntryMethod(bootStrapMethod);
   }
 
-  private final Set/* <IProblem> */problemSet = new HashSet/* <IProblem> */();
-
   private final String[] declEntryPoints;
 
   private final CompilationUnitDeclaration[] goldenCuds;
@@ -182,6 +181,8 @@
 
   private final boolean prettyNames;
 
+  private final Set/* <IProblem> */problemSet = new HashSet/* <IProblem> */();
+
   public JavaToJavaScriptCompiler(final TreeLogger logger,
       final WebModeCompilerFrontEnd compiler, final String[] declEntryPts)
       throws UnableToCompleteException {
@@ -305,6 +306,13 @@
         throw new UnableToCompleteException();
       }
 
+      // TODO: figure out how to have a debug mode.
+      boolean isDebugEnabled = false;
+      if (!isDebugEnabled) {
+        // Remove all assert statements.
+        AssertionRemover.exec(jprogram);
+      }
+
       // Compute which classes have clinits
       jprogram.typeOracle.computeAfterAST();
 
@@ -354,6 +362,9 @@
       // (5) "Normalize" the high-level Java tree into a lower-level tree more
       // suited for JavaScript code gen. Don't go reordering these willy-nilly
       // because there are some subtle interdependencies.
+      if (isDebugEnabled) {
+        // AssertionNormalizer.exec(jprogram);
+      }
       CatchBlockNormalizer.exec(jprogram);
       CompoundAssignmentNormalizer.exec(jprogram);
       JavaScriptObjectCaster.exec(jprogram);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java
new file mode 100644
index 0000000..89c6836
--- /dev/null
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionRemover.java
@@ -0,0 +1,63 @@
+/*

+ * Copyright 2006 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

+ * License for the specific language governing permissions and limitations under

+ * the License.

+ */

+package com.google.gwt.dev.jjs.impl;

+

+import com.google.gwt.dev.jjs.ast.Context;

+import com.google.gwt.dev.jjs.ast.JAssertStatement;

+import com.google.gwt.dev.jjs.ast.JBlock;

+import com.google.gwt.dev.jjs.ast.JModVisitor;

+import com.google.gwt.dev.jjs.ast.JProgram;

+import com.google.gwt.dev.jjs.ast.JStatement;

+

+/**

+ * Removes all assertion statements from the AST.

+ */

+public class AssertionRemover {

+

+  /**

+   * Removes all asserts.

+   */

+  public class AssertVisitor extends JModVisitor {

+

+    public void endVisit(JAssertStatement x, Context ctx) {

+      removeMe(x, ctx);

+    }

+

+    private void removeMe(JStatement stmt, Context ctx) {

+      if (ctx.canRemove()) {

+        ctx.removeMe();

+      } else {

+        // empty block statement

+        ctx.replaceMe(new JBlock(program, stmt.getSourceInfo()));

+      }

+    }

+  }

+

+  public static void exec(JProgram program) {

+    new AssertionRemover(program).execImpl();

+  }

+

+  private final JProgram program;

+

+  public AssertionRemover(JProgram program) {

+    this.program = program;

+  }

+

+  private void execImpl() {

+    AssertVisitor assertVisitor = new AssertVisitor();

+    assertVisitor.accept(program);

+  }

+}

diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index 804a097..ed18bfc 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -384,12 +384,7 @@
 
     // @Override
     public void endVisit(JAssertStatement x, Context ctx) {
-      // TODO(later): implement assert
-      if (x.getArg() != null) {
-        pop(); // arg
-      }
-      pop(); // testExpr
-      push(jsProgram.getEmptyStmt());
+      throw new InternalCompilerException("Should not get here.");
     }
 
     // @Override