Author: ptw
Date: 2007-11-28 08:10:45 -0800 (Wed, 28 Nov 2007)
New Revision: 7402

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ASTVisitor.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
   
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
   
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
Log:
Change 20071127-ptw-C by [EMAIL PROTECTED] on 2007-11-27 16:41:07 EST
    in /Users/ptw/OpenLaszlo/ringding-2
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Correct handling of comma-separated var expressions

Bugs Fixed:
LPP-5129 ' lzo's compile differently? for (var i = 0, len = childNodes.length; 
i < len; i++) { causes error'

Technical Reviewer: [EMAIL PROTECTED] (Message-Id: <[EMAIL PROTECTED]>)
QA Reviewer: hminsky (pending)

Details:
    JavascriptGenerator: Handle variableStatement, consolidate
    isExpression

    CommonGenerator: Handle new AST type VariableDeclarationList, mov
    base isExpression here

    ASTVisitor: Add interfaces for VariableDeclaration and
    VariableDeclarationList

    Compiler: A VariableStatement cannot be handled as a Statement.
    Implement correct unparsing of VariableStatement,
    VariableDeclarationList, and VariableDeclaration.

    CodeGenerator: consolidate isExpression

    Parser: Parse comma-separated variable declarations into new AST
    VariableDeclarationList

Tests:
    smokecheck

    observed that test case in bug report is correctly passed through
    for dhtml



Modified: 
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt     
2007-11-28 02:40:05 UTC (rev 7401)
+++ openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt     
2007-11-28 16:10:45 UTC (rev 7402)
@@ -643,7 +643,7 @@
     "var" VariableDeclarationList() Sc()
 }
 
-void VariableDeclarationList() #StatementList(>1) : {}
+void VariableDeclarationList() #VariableDeclarationList(>1) : {}
 {
     VariableDeclaration() ("," VariableDeclaration())*
 }
@@ -755,7 +755,7 @@
 
 void ForVarStatement() #ForVarStatement : {}
 {
-     "for" "(" "var"  { setAllowIn(false); } VariableDeclarationList() { 
setAllowIn(true); } ";"
+     "for" "(" "var"  ({ setAllowIn(false); } VariableDeclarationList() { 
setAllowIn(true); }) #VariableStatement ";"
                ([Expression()]) #EmptyExpression(jjtree.nodeArity()==0) ";"
                ([Expression()]) #EmptyExpression(jjtree.nodeArity()==0) ")"
          Statement()

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ASTVisitor.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ASTVisitor.java   
2007-11-28 02:40:05 UTC (rev 7401)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ASTVisitor.java   
2007-11-28 16:10:45 UTC (rev 7402)
@@ -68,6 +68,8 @@
   SimpleNode visitTryStatement(SimpleNode node, SimpleNode[] children);
   SimpleNode visitUnaryExpression(SimpleNode node, boolean isReferenced, 
SimpleNode[] children);
   SimpleNode visitVariableDeclaration(SimpleNode node, SimpleNode[] children);
+  SimpleNode visitVariableDeclarationList(SimpleNode node, SimpleNode[] 
children);
+  SimpleNode visitVariableStatement(SimpleNode node, SimpleNode[] children);
   SimpleNode visitWhileStatement(SimpleNode node, SimpleNode[] children);
   SimpleNode visitWithStatement(SimpleNode node, SimpleNode[] children);
 }

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
===================================================================
--- 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java    
    2007-11-28 02:40:05 UTC (rev 7401)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java    
    2007-11-28 16:10:45 UTC (rev 7402)
@@ -1059,18 +1059,6 @@
   // Expressions
   //
 
-  boolean isExpressionType(SimpleNode node) {
-    // There are several AST types that end with each of the names that
-    // endsWith tests for.
-    String name = node.getClass().getName();
-    return name.endsWith("Expression") ||
-      name.endsWith("ExpressionList") ||
-      name.endsWith("ExpressionSequence") ||
-      name.endsWith("Identifier") ||
-      name.endsWith("Literal") ||
-      name.endsWith("Reference");
-  }
-
   public SimpleNode visitExpression(SimpleNode node) {
     return visitExpression(node, true);
   }

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
===================================================================
--- 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java  
    2007-11-28 02:40:05 UTC (rev 7401)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java  
    2007-11-28 16:10:45 UTC (rev 7402)
@@ -491,6 +491,9 @@
     else if (node instanceof ASTVariableDeclaration) {
       newNode = visitVariableDeclaration(node, children);
     }
+    else if (node instanceof ASTVariableDeclarationList) {
+      newNode = visitVariableDeclarationList(node, children);
+    }
     else if (node instanceof ASTVariableStatement) {
       newNode = visitVariableStatement(node, children);
     }
@@ -577,6 +580,13 @@
     return node;
   }
 
+  public SimpleNode visitVariableDeclarationList(SimpleNode node, SimpleNode[] 
children) {
+    for (int i = 0, len = children.length ; i < len; i++) {
+      children[i] = visitStatement(children[i]);
+    }
+    return node;
+  }
+
   // for function prefix/suffix parsing
   public SimpleNode visitDirectiveBlock(SimpleNode node, SimpleNode[] 
children) {
     return visitStatementList(node, children);
@@ -698,6 +708,19 @@
     return visitChildren(node);
   }
 
+  boolean isExpressionType(SimpleNode node) {
+    // There are several AST types that end with each of the names that
+    // endsWith tests for.
+    String name = node.getClass().getName();
+    return name.endsWith("Expression") ||
+      name.endsWith("FunctionCallParameters") ||
+      name.endsWith("ExpressionList") ||
+      name.endsWith("ExpressionSequence") ||
+      name.endsWith("Identifier") ||
+      name.endsWith("Literal") ||
+      name.endsWith("Reference");
+  }
+
   public SimpleNode dispatchExpression(SimpleNode node, boolean isReferenced) {
     // Are we doing OO programming yet?
     SimpleNode[] children = node.getChildren();

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java     
2007-11-28 02:40:05 UTC (rev 7401)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java     
2007-11-28 16:10:45 UTC (rev 7402)
@@ -814,6 +814,10 @@
       this.CLOSECURLY = NEWLINE + "}";
     }
 
+    public void print(SimpleNode node) {
+      print(node, System.out);
+    }
+
     public void print(SimpleNode node, OutputStream output) {
       PrintStream where = new PrintStream(output);
       print(node, where);
@@ -823,10 +827,6 @@
       where.println(visit(node));
     }
 
-    public void print(SimpleNode node) {
-      print(node, System.out);
-    }
-
     public String delimit(String phrase, boolean force) {
       if (phrase.length() > 0) {
         return ((('(' != phrase.charAt(0)) && force)?" ":SPACE) + phrase;
@@ -873,8 +873,7 @@
       if (node instanceof ASTProgram ||
           node instanceof ASTStatementList ||
           node instanceof ASTDirectiveBlock ||
-          node instanceof ASTStatement ||
-          node instanceof ASTVariableStatement) {
+          node instanceof ASTStatement) {
         // Conditional join
         StringBuffer sb = new StringBuffer();
         String sep = "";
@@ -1009,9 +1008,15 @@
       if (node instanceof ASTOperator) {
         return visitOperator(node, children);
       }
+      if (node instanceof ASTVariableStatement) {
+        return visitVariableStatement(node, children);
+      }
       if (node instanceof ASTVariableDeclaration) {
         return visitVariableDeclaration(node, children);
       }
+      if (node instanceof ASTVariableDeclarationList) {
+        return visitVariableDeclarationList(node, children);
+      }
       if (node instanceof ASTTryStatement) {
         return visitTryStatement(node, children);
       }
@@ -1433,17 +1438,26 @@
       return OperatorNames[operator];
     }
 
+    public String visitVariableStatement(SimpleNode node, String[] children) {
+      assert children.length == 1;
+      return "var " + children[0];
+    }
+
     public String visitVariableDeclaration(SimpleNode node, String[] children) 
{
       if (children.length > 1) {
         int thisPrec = prec(Ops.ASSIGN, false);
         assert children.length == 2;
         children[1] = maybeAddParens(thisPrec, node.get(1), children[1], true);
-        return "var " + children[0] + ASSIGN + children[1];
+        return children[0] + ASSIGN + children[1];
       } else {
-        return "var " + children[0];
+        return children[0];
       }
     }
 
+    public String visitVariableDeclarationList(SimpleNode node, String[] 
children) {
+      return join(COMMA, children);
+    }
+
     public String visitTryStatement(SimpleNode node, String[] children) {
       if (children.length == 2) {
         return "try" + SPACE + OPENCURLY + children[0] + CLOSECURLY + NEWLINE 
+ children[1];

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
===================================================================
--- 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
  2007-11-28 02:40:05 UTC (rev 7401)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
  2007-11-28 16:10:45 UTC (rev 7402)
@@ -375,6 +375,18 @@
   // Statements
   //
 
+  public SimpleNode visitVariableStatement(SimpleNode node, SimpleNode[] 
children) {
+    boolean scriptElement = options.getBoolean(Compiler.SCRIPT_ELEMENT);
+    if (scriptElement) {
+      assert children.length == 1;
+      // In script, variables are declared at the top of the function
+      // so we convert the variableStatement into a Statement here.
+      node = new ASTStatement(0);
+      node.set(0, children[0]);
+    }
+    return visitChildren(node);
+  }
+
   public SimpleNode visitVariableDeclaration(SimpleNode node, SimpleNode[] 
children) {
     ASTIdentifier id = (ASTIdentifier)children[0];
     boolean scriptElement = options.getBoolean(Compiler.SCRIPT_ELEMENT);
@@ -636,18 +648,7 @@
     if (node instanceof Compiler.PassThroughNode) {
       node = ((Compiler.PassThroughNode)node).realNode;
     }
-    // There are several AST types that end with each of the names that
-    // endsWith tests for.
-    String name = node.getClass().getName();
-    return name.endsWith("Expression") ||
-      name.endsWith("FunctionCallParameters") ||
-      // TODO: [2006-01-11 ptw] Noone can explain this vestigial code, remove 
it
-      //         name.substring(5).equals("Identifier") ||
-      name.endsWith("ExpressionList") ||
-      name.endsWith("ExpressionSequence") ||
-      name.endsWith("Identifier") ||
-      name.endsWith("Literal") ||
-      name.endsWith("Reference");
+    return super.isExpressionType(node);
   }
 
   public SimpleNode visitExpression(SimpleNode node) {


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

Reply via email to