Author: [EMAIL PROTECTED]
Date: Wed Oct 29 07:43:52 2008
New Revision: 3884

Modified:
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardCompilationAnalysis.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/linker/soyc/SoycReportLinker.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/SourceInfo.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
     
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java

Log:
SOYC bug fixes.
   - Use enabled SourceInfos when initializing JProgram and JsProgram,  
before we know if SourceInfo collection should be turned on.
   - Be more robust in creating SourceInfos that comprise method bodies by  
using copyMissingFrom().
   - Fixes for classes in the default package.

Patch by: bobv
Reported by: kprobst


Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardCompilationAnalysis.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardCompilationAnalysis.java
        
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardCompilationAnalysis.java
        
Wed Oct 29 07:43:52 2008
@@ -293,6 +293,7 @@
      hardData.stories = Collections.unmodifiableSortedSet(mutableStories);

      try {
+      cacheDir.mkdirs();
        this.cacheFile = File.createTempFile("analysis", ".ser", cacheDir);
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
            cacheFile));

Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/linker/soyc/SoycReportLinker.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/linker/soyc/SoycReportLinker.java
       
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/core/linker/soyc/SoycReportLinker.java
       
Wed Oct 29 07:43:52 2008
@@ -282,8 +282,10 @@

      for (ClassMember classMember : report.getClasses()) {
        String sourceName = classMember.getSourceName();
-      String packageName = sourceName.substring(0,  
sourceName.lastIndexOf('.'));
-      String shortName = sourceName.substring(sourceName.lastIndexOf('.')  
+ 1);
+      int index = sourceName.lastIndexOf('.');
+      String packageName = index == -1 ? "" : sourceName.substring(0,  
index);
+      String shortName = index == -1 ? sourceName
+          : sourceName.substring(index + 1);

        Element packageElement = packages.get(packageName);
        if (packageElement == null) {

Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
        
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
        
Wed Oct 29 07:43:52 2008
@@ -337,10 +337,8 @@

      PerfLogger.start("Build AST");
      boolean enableDescendants = compilerOptions.getSoycOutputDir() != null;
-    JProgram jprogram = savedJProgram = new JProgram();
-    jprogram.setEnableSourceInfoDescendants(enableDescendants);
-    JsProgram jsProgram = savedJsProgram = new JsProgram();
-    jsProgram.setEnableSourceInfoDescendants(enableDescendants);
+    JProgram jprogram = savedJProgram = new JProgram(enableDescendants);
+    JsProgram jsProgram = savedJsProgram = new  
JsProgram(enableDescendants);

      long memoryDelta;
      try {

Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/SourceInfo.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/SourceInfo.java
      
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/SourceInfo.java
      
Wed Oct 29 07:43:52 2008
@@ -334,7 +334,7 @@
      }

      for (SourceInfo info : sourceInfos) {
-      if (this == info) {
+      if (this == info || !info.accumulateData) {
          continue;
        }


Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
    
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
    
Wed Oct 29 07:43:52 2008
@@ -138,6 +138,15 @@
      return traceMethods.size() > 0;
    }

+  /**
+   * This method is used to create SourceInfos for fields in JProgram. This
+   * method always creates a SourceInfo that has collection enabled.
+   */
+  private static SourceInfo createSourceInfoEnabled(String description) {
+    return new SourceInfoJava(-1, -1, 0, JProgram.class.getName(),  
true).makeChild(
+        JProgram.class, description);
+  }
+
    private static String dotify(char[][] name) {
      StringBuffer result = new StringBuffer();
      for (int i = 0; i < name.length; ++i) {
@@ -175,7 +184,7 @@
     */
    private final ArrayList<HashMap<JType, JArrayType>> dimensions = new  
ArrayList<HashMap<JType, JArrayType>>();

-  private boolean enableSourceInfoDescendants;
+  private final boolean enableSourceInfoDescendants;

    private final Map<String, JField> indexedFields = new HashMap<String,  
JField>();

@@ -188,25 +197,25 @@
    private List<JsonObject> jsonTypeTable;

    private final JAbsentArrayDimension literalAbsentArrayDim = new  
JAbsentArrayDimension(
-      this, createSourceInfoSynthetic(JProgram.class, "Absent array  
dimension"));
+      this, createSourceInfoEnabled("Absent array dimension"));

    private final JBooleanLiteral literalFalse = new JBooleanLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "false literal"), false);
+      createSourceInfoEnabled("false literal"), false);

    private final JIntLiteral literalIntNegOne = new JIntLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "-1 literal"), -1);
+      createSourceInfoEnabled("-1 literal"), -1);

    private final JIntLiteral literalIntOne = new JIntLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "1 literal"), 1);
+      createSourceInfoEnabled("1 literal"), 1);

    private final JIntLiteral literalIntZero = new JIntLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "0 literal"), 0);
+      createSourceInfoEnabled("0 literal"), 0);

    private final JNullLiteral literalNull = new JNullLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "null literal"));
+      createSourceInfoEnabled("null literal"));

    private final JBooleanLiteral literalTrue = new JBooleanLiteral(this,
-      createSourceInfoSynthetic(JProgram.class, "true literal"), true);
+      createSourceInfoEnabled("true literal"), true);

    private JField nullField;

@@ -253,7 +262,7 @@
    private final Map<String, JReferenceType> typeNameMap = new  
HashMap<String, JReferenceType>();

    private final JNullType typeNull = new JNullType(this,
-      createSourceInfoSynthetic(JProgram.class, "null type"));
+      createSourceInfoEnabled("null type"));

    private final JPrimitiveType typeShort = new  
JPrimitiveType(this, "short",
        "S", "java.lang.Short", literalIntZero);
@@ -267,21 +276,35 @@
    private final JPrimitiveType typeVoid = new  
JPrimitiveType(this, "void", "V",
        "java.lang.Void", null);

-  private final SourceInfo stringPoolSourceInfo =  
createSourceInfoSynthetic(
-      JProgram.class, "String pool");
+  private final SourceInfo stringPoolSourceInfo;

    private final Map<String, JStringLiteral> stringLiteralMap = new  
HashMap<String, JStringLiteral>();

    public JProgram() {
+    this(false);
+  }
+
+  /**
+   * Constructor.
+   *
+   * @param enableSourceInfoDescendants Controls whether or not SourceInfo  
nodes
+   *          created via the JProgram will record descendant information.
+   *          Enabling this feature will collect extra data during the
+   *          compilation cycle, but at a cost of memory and object  
allocations.
+   */
+  public JProgram(boolean enableSourceInfoDescendants) {
      super(null, SourceInfoJava.INTRINSIC.makeChild(JProgram.class,
          "Top-level program"));

+    this.enableSourceInfoDescendants = enableSourceInfoDescendants;
       
literalFalse.getSourceInfo().addCorrelation(Correlation.by(Literal.BOOLEAN));
       
literalIntNegOne.getSourceInfo().addCorrelation(Correlation.by(Literal.INT));
       
literalIntOne.getSourceInfo().addCorrelation(Correlation.by(Literal.INT));
       
literalIntZero.getSourceInfo().addCorrelation(Correlation.by(Literal.INT));
       
literalNull.getSourceInfo().addCorrelation(Correlation.by(Literal.NULL));
       
literalTrue.getSourceInfo().addCorrelation(Correlation.by(Literal.BOOLEAN));
+    stringPoolSourceInfo = createSourceInfoSynthetic(JProgram.class,
+        "String pool");
      stringPoolSourceInfo.addCorrelation(Correlation.by(Literal.STRING));
    }

@@ -858,16 +881,6 @@

    public void recordQueryIds(Map<JReferenceType, Integer> queryIds) {
      this.queryIds = queryIds;
-  }
-
-  /**
-   * Controls whether or not SourceInfo nodes created via the JProgram will
-   * record descendant information. Enabling this feature will collect  
extra
-   * data during the compilation cycle, but at a cost of memory and object
-   * allocations.
-   */
-  public void setEnableSourceInfoDescendants(boolean enable) {
-    enableSourceInfoDescendants = enable;
    }

    /**

Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
    
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
    
Wed Oct 29 07:43:52 2008
@@ -15,7 +15,6 @@
   */
  package com.google.gwt.dev.jjs.impl;

-import com.google.gwt.dev.jjs.Correlation;
  import com.google.gwt.dev.jjs.HasSourceInfo;
  import com.google.gwt.dev.jjs.InternalCompilerException;
  import com.google.gwt.dev.jjs.SourceInfo;
@@ -2246,10 +2245,10 @@
        SourceInfo toReturn = program.createSourceInfo(x.sourceStart,
            x.sourceEnd, startLine, currentFileName);
        if (currentClass != null) {
-        toReturn.addCorrelation(Correlation.by(currentClass));
+        toReturn.copyMissingCorrelationsFrom(currentClass.getSourceInfo());
        }
        if (currentMethod != null) {
-        toReturn.addCorrelation(Correlation.by(currentMethod));
+         
toReturn.copyMissingCorrelationsFrom(currentMethod.getSourceInfo());
        }
        return toReturn;
      }

Modified:  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java
==============================================================================
---  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java
    
(original)
+++  
changes/bobv/soyc-reports-r3772/dev/core/src/com/google/gwt/dev/js/ast/JsProgram.java
    
Wed Oct 29 07:43:52 2008
@@ -26,20 +26,30 @@
   * A JavaScript program.
   */
  public final class JsProgram extends JsNode<JsProgram> {
+  /**
+   * This method is used to create SourceInfos for fields in JsProgram.  
This
+   * method always creates a SourceInfo that has collection enabled.
+   */
+  private static SourceInfo createSourceInfoEnabled(String description) {
+    return new SourceInfoJs(-1, -1, 0, JsProgram.class.getName(),  
true).makeChild(
+        JsProgram.class, description);
+  }

    private final JsStatement debuggerStmt = new JsDebugger(
-      createSourceInfoSynthetic(JsProgram.class, "debugger statement"));
+      createSourceInfoEnabled("debugger statement"));
+
+  private final JsEmpty emptyStmt = new JsEmpty(
+      createSourceInfoEnabled("Empty statement"));

-  private final JsEmpty emptyStmt = new JsEmpty(createSourceInfoSynthetic(
-      JsProgram.class, "Empty statement"));
+  private final boolean enableSourceInfoDescendants;

    private final JsBooleanLiteral falseLiteral = new JsBooleanLiteral(
-      createSourceInfoSynthetic(JsProgram.class, "false literal"), false);
+      createSourceInfoEnabled("false literal"), false);

    private final JsGlobalBlock globalBlock;

    private final JsNullLiteral nullLiteral = new JsNullLiteral(
-      createSourceInfoSynthetic(JsProgram.class, "null literal"));
+      createSourceInfoEnabled("null literal"));

    private final Map<Double, JsNumberLiteral> numberLiteralMap = new  
HashMap<Double, JsNumberLiteral>();

@@ -49,22 +59,30 @@

    private final Map<String, JsStringLiteral> stringLiteralMap = new  
HashMap<String, JsStringLiteral>();

-  private final SourceInfo stringPoolSourceInfo =  
createSourceInfoSynthetic(
-      JsProgram.class, "String pool");
+  private final SourceInfo stringPoolSourceInfo;

    private final JsScope topScope;

    private final JsBooleanLiteral trueLiteral = new JsBooleanLiteral(
-      createSourceInfoSynthetic(JsProgram.class, "true literal"), true);
+      createSourceInfoEnabled("true literal"), true);

-  private boolean enableSourceInfoDescendants;
+  public JsProgram() {
+    this(false);
+  }

    /**
     * Constructs a JavaScript program object.
+   *
+   * @param enableSourceInfoDescendants Controls whether or not SourceInfo  
nodes
+   *          created via the JsProgram will record descendant information.
+   *          Enabling this feature will collect extra data during the
+   *          compilation cycle, but at a cost of memory and object  
allocations.
     */
-  public JsProgram() {
+  public JsProgram(boolean enableSourceInfoDescendants) {
      super(SourceInfoJs.INTRINSIC.makeChild(JsProgram.class,
          "JavaScript program"));
+    this.enableSourceInfoDescendants = enableSourceInfoDescendants;
+
      rootScope = new JsRootScope(this);
      globalBlock = new  
JsGlobalBlock(createSourceInfoSynthetic(JsProgram.class,
          "global block"));
@@ -75,6 +93,8 @@
       
nullLiteral.getSourceInfo().addCorrelation(Correlation.by(Literal.JS_NULL));
      trueLiteral.getSourceInfo().addCorrelation(
          Correlation.by(Literal.JS_BOOLEAN));
+    stringPoolSourceInfo = createSourceInfoSynthetic(JsProgram.class,
+        "String pool");
      stringPoolSourceInfo.addCorrelation(Correlation.by(Literal.JS_STRING));
    }

@@ -191,16 +211,6 @@
          "undefined reference");
      info.addCorrelation(Correlation.by(Literal.JS_UNDEFINED));
      return rootScope.findExistingName("undefined").makeRef(info);
-  }
-
-  /**
-   * Controls whether or not SourceInfo nodes created via the JsProgram  
will
-   * record descendant information. Enabling this feature will collect  
extra
-   * data during the compilation cycle, but at a cost of memory and object
-   * allocations.
-   */
-  public void setEnableSourceInfoDescendants(boolean enable) {
-    enableSourceInfoDescendants = enable;
    }

    public void traverse(JsVisitor v, JsContext<JsProgram> ctx) {

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to