Author: dda
Date: 2007-12-13 13:59:55 -0800 (Thu, 13 Dec 2007)
New Revision: 7536

Modified:
   
openlaszlo/branches/devildog/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTModifiedDefinition.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
Log:
Change 20071213-dda-K by [EMAIL PROTECTED] on 2007-12-13 16:46:48 EST
    in /Users/dda/laszlo/src/svn/openlaszlo/branches/devildog
    for http://svn.openlaszlo.org/openlaszlo/branches/devildog

Summary:  SWF9: Fixes related to propogating through new AS3 keywords and 
getting buildlfc working further.

New Features: none

Bugs Fixed:  LPP-5434, LPP-5178

Technical Reviewer: ptw (pending)
QA Reviewer: hminsky (pending)
Doc Reviewer: (pending)

Documentation:  none

Release Notes: none

Details:
    Emit static, etc. keywords that appear before methods, vars, classes.
    Even though prelim work was done to parse these previously, needed to fix 
up a 
    few things:

  + when walking through the AST, the 'ModifiedDefinition' node was elided from 
the tree.
    Now, if we are parsing for SWF9, these nodes are kept in the tree.

  + added a visitModifiedDefinition in ParseTreePrinter that is modified in 
SWF9ParseTreePrinter

  + fixed some simple setters on ASTModifiedDefinition class.

   Now when we emit the 'static' keyword in front of the 'function' definition,
   the presence of the /* -*- file .... */ comment between these two - putting
   'static' and 'function' on two separate lines, triggered an apparent bug
   in the third party compiler.  Some extra work was needed to get 'static' and
   'function' next to each other on the same line.  (This will also be handled
   correctly for 'class' if we decide to emit the file comment there.)

Tests:
   just buildlfc



Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTModifiedDefinition.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTModifiedDefinition.java
  2007-12-13 21:59:34 UTC (rev 7535)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTModifiedDefinition.java
  2007-12-13 21:59:55 UTC (rev 7536)
@@ -69,7 +69,7 @@
     }
 
     public void setStatic(boolean value) {
-        isStatic = true;
+        isStatic = value;
     }
 
     public boolean isStatic() {
@@ -77,7 +77,7 @@
     }
 
     public void setFinal(boolean value) {
-        isFinal = true;
+        isFinal = value;
     }
 
     public boolean isFinal() {
@@ -85,7 +85,7 @@
     }
 
     public void setDynamic(boolean value) {
-        isDynamic = true;
+        isDynamic = value;
     }
 
     public boolean isDynamic() {
@@ -93,7 +93,7 @@
     }
 
     public void setOverride(boolean value) {
-        isOverride = true;
+        isOverride = value;
     }
 
     public boolean isOverride() {

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
  2007-12-13 21:59:34 UTC (rev 7535)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
  2007-12-13 21:59:55 UTC (rev 7536)
@@ -447,7 +447,12 @@
         } else if (n instanceof ASTPragmaDirective) {
           visitPragmaDirective(n, n.getChildren());
         } else {
-          stmts.add(n);
+          if (keepClassMethods && mod != null) {
+            stmts.add(mod);
+          }
+          else {
+            stmts.add(n);
+          }
         }
       }
     }

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
 2007-12-13 21:59:34 UTC (rev 7535)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
 2007-12-13 21:59:55 UTC (rev 7536)
@@ -331,6 +331,9 @@
     if (node instanceof ASTClassDefinition) {
       return lnum(node, visitClassDefinition(node, children));
     }
+    if (node instanceof ASTModifiedDefinition) {
+      return lnum(node, visitModifiedDefinition(node, children));
+    }
     return lnum(node, defaultVisitor(node, children));
   }
   
@@ -652,6 +655,12 @@
     return(sb.toString());
   }
   
+  // This is overridden for SWF9
+  public String visitModifiedDefinition(SimpleNode node, String[] children) {
+    // In JavascriptGenerator 'static' is handled elsewhere.
+    return children[0];
+  }
+  
   public String visitFunctionDeclaration(SimpleNode node, String[] children) {
     return doFunctionDeclaration(node, children, true);
   }

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2007-12-13 21:59:34 UTC (rev 7535)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2007-12-13 21:59:55 UTC (rev 7536)
@@ -171,6 +171,18 @@
 
   /**
    * Intercept JavascriptGenerator version.
+   * We preserve ModifiedDefinition nodes in our tree,
+   * while other runtimes remove them for simplicity.
+   */
+  public SimpleNode visitModifiedDefinition(SimpleNode node, SimpleNode[] 
children) {
+    assert children.length == 1;
+    ((ASTModifiedDefinition)node).verifyTopLevel(children[0]);
+    children[0] = visitStatement(children[0]);
+    return node;
+  }
+
+  /**
+   * Intercept JavascriptGenerator version.
    * We keep a copy of the original program so we can emit it
    * for debugging purposes.
    */

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
     2007-12-13 21:59:34 UTC (rev 7535)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
     2007-12-13 21:59:55 UTC (rev 7536)
@@ -48,6 +48,76 @@
       // never compress
       super(false, false);
   }
+
+  public static final String MULTILINE_COMMENT_BEGIN = "/*";
+  public static final String MULTILINE_COMMENT_END = "*/";
+
+  // workaround an apparent third party compiler bug.
+  //
+  //   static
+  //   /* -*- file: some/file.lzs#50.1 -*- */
+  //   function ....
+  //
+  // causes a parse error. whereas putting the static on
+  // the same line as 'function' does not (even with the comment
+  // in place).  To promote readability, we convert the above to:
+  //
+  //   /* -*- file: some/file.lzs#50.1 -*- */
+  //   static function ....
+  //
+  // TODO: [2007-12-13 dda] might be able to revisit how
+  // the file comments are emitted to fix this, or just
+  // replace this by mods + code.
+  //
+  protected String prependMods(String code, String mods)
+  {
+    if (mods.length() == 0)
+      return code;
+
+    mods += " ";
+    // simple 
+    int pos = 0;
+    int len = code.length();
+    pos = skipWhitespace(code, pos);
+    if (!code.substring(pos).startsWith(MULTILINE_COMMENT_BEGIN))
+      return mods + code;
+    pos = code.indexOf(MULTILINE_COMMENT_END, pos);
+    if (pos < 0)
+      return mods + code;
+    pos += MULTILINE_COMMENT_END.length();
+    pos = skipWhitespace(code, pos);
+    return code.substring(0, pos) + mods + code.substring(pos);
+  }
+
+  public static int skipWhitespace(String s, int pos)
+  {
+    int len = s.length();
+    while (pos < len) {
+      char ch = s.charAt(pos);
+      if (ANNOTATE_MARKER == ch) {
+        pos++;
+        while (pos < len) {
+          if (s.charAt(pos) == ANNOTATE_MARKER) {
+            pos++;
+            break;
+          }
+          pos++;
+        }
+      }
+      else if (Character.isWhitespace(ch)) {
+        pos++;
+      }
+      else
+        break;
+    }
+    return pos;
+  }
+
+  // override
+  public String visitModifiedDefinition(SimpleNode node, String[] children) {
+    String mods = ((ASTModifiedDefinition)node).toJavascriptString();
+    return prependMods(children[0], mods);
+  }
   
   public String visitClassDefinition(SimpleNode node, String[] children) {
     String classnm = unannotate(children[1]);


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to