Author: dda
Date: 2007-11-12 14:17:51 -0800 (Mon, 12 Nov 2007)
New Revision: 7217

Added:
   openlaszlo/trunk/test/typevar.lzx
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/ASTIdentifier.java
Log:
Change 20071107-dda-g by [EMAIL PROTECTED] on 2007-11-07 18:14:27 EST
    in /Users/dda/laszlo/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Allow type information for vars, even though ignored in SWF7/8 and 
DHTML.

New Features:
    Allow type information accepted in ActionScript 3.0, that is:
      var x:int;
      var y:String = "hello";
      var z:?String = null;   // ? means can set to null (default)
      var z:String! = "bonjour";   // ! means cannot set to null
    the following nonsensical case is not accepted:
      var w:?String! = "namaste";   // cannot mark both nullable and 
non-nullable

    Please note that the type information is merely accepted as part of the 
language, and ignored for now.

Bugs Fixed: LPP-5059

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

Documentation:
   Requires documentation if we describe in detail our language (or subset).  
If we point
   users to the published standards, then we can continue to do that.
   We should note that type information is ignored except for the (upcoming) 
SWF9 runtime.

Release Notes:
    Variables declared using the 'var' statement now allow type specifications 
as
    described by Ecmascript 4 (that is, ActionScript 3.0).

Details:
    No type checking is done by the SWF7/8 and DHTML runtimes (nor is planned), 
any
    type information is thrown away.  However, when SWF9 is available, the type 
information
    will be accepted and passed through to the 3rd party SWF9 compiler, which 
will do type
    checking for any variable with type information.  This change allows users 
and developers
    to write code that can be useful with either runtime.  Even if they don't 
use with SWF9,
    this is a useful feature for self documenting usage of variables.

    We currently allow type information on 'var' declarations, also method 
parameters and
    method return values.  I believe only information for 'var' declarations 
can be done
    in .lzx, but the latter two are also accepted (and ignored for current 
runtimes) in .lzs files.

Tests:
    Ran new test test/typevar.lzx for both SWF7/8 and DHTML, to make sure 
syntax is accepted.
    Ran smokecheck.lzx to assure there are no regressions.



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-12 21:14:39 UTC (rev 7216)
+++ openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt     
2007-11-12 22:17:51 UTC (rev 7217)
@@ -348,10 +348,10 @@
      {jjtThis.setFloatingPointValue(t.image);}
 }
 
-void Identifier() #Identifier : {Token t;}
+ASTIdentifier Identifier() #Identifier : {Token t;}
 {
   t=<IDENTIFIER>
-    {jjtThis.setName(t.image);}
+    {jjtThis.setName(t.image); return jjtThis;}
 }
 
 void IdentifierOrKeyword() #Identifier : {Token t;}
@@ -648,11 +648,44 @@
     VariableDeclaration() ("," VariableDeclaration())*
 }
 
-void VariableDeclaration() #VariableDeclaration : {}
+void VariableDeclaration() #VariableDeclaration : { ASTIdentifier id; 
ASTIdentifier.Type type; }
 {
-    Identifier() [Initializer()]
+    id = Identifier() [type = TypeAndInitializer() { id.setType(type); }]
 }
 
+ASTIdentifier.Type TypeAndInitializer() #void : { ASTIdentifier.Type type = 
null; }
+{
+  (
+    ":" type = TypeIdentifier() [Initializer()]
+  | Initializer()
+  ) {
+    return type;
+  }
+}
+
+ASTIdentifier.Type TypeIdentifier() #void : { Token t; ASTIdentifier.Type type 
= new ASTIdentifier.Type(); }
+{
+  (
+    Nullable() {type.nullable = true; }
+    t = <IDENTIFIER> {type.typeName = t.image;}
+  |
+    t = <IDENTIFIER> {type.typeName = t.image;}
+    [NotNullable() {type.notnullable = true; }]
+  ) {
+    return type;
+  }
+}
+
+void Nullable() #void : {}
+{
+   "?"
+}
+
+void NotNullable() #void : {}
+{
+   "!"
+}
+
 void Initializer() #void : {}
 {
  //    "=" Expression()
@@ -803,9 +836,11 @@
 
 // Function declaration
 
-void FunctionDeclaration() #FunctionDeclaration : {}
+void FunctionDeclaration() #FunctionDeclaration : {ASTIdentifier id; 
ASTIdentifier.Type type;}
 {
-    "function" Identifier() ("(" [FormalParameterList()] ")") 
#FormalParameterList(jjtree.nodeArity()==0)
+    "function" id = Identifier() 
+    [":" type = TypeIdentifier() { id.setType(type); }]
+    ("(" [FormalParameterList()] ")") 
#FormalParameterList(jjtree.nodeArity()==0)
     Block()
 }
 
@@ -816,10 +851,14 @@
 
 SimpleNode FormalParameterList() #FormalParameterList : {Token t;}
 {
-   Identifier() ("," Identifier())*
+   FormalParameter() ("," FormalParameter())*
      { return jjtThis; }
 }
 
+void FormalParameter() #void : {ASTIdentifier id; ASTIdentifier.Type type;}
+{
+    id = Identifier() [":" type = TypeIdentifier() { id.setType(type); }]
+}
 
 // Program structuring/
 

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTIdentifier.java
===================================================================
--- 
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTIdentifier.java
      2007-11-12 21:14:39 UTC (rev 7216)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ASTIdentifier.java
      2007-11-12 22:17:51 UTC (rev 7217)
@@ -3,7 +3,7 @@
 * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -11,8 +11,15 @@
 
 public class ASTIdentifier extends SimpleNode {
     private String name = null;
+    private Type type = null;
     private int hash = 0;
-  
+
+    public static class Type {
+        public String typeName = null;
+        public boolean nullable = false; // has "?"
+        public boolean notnullable = false; // has "!"
+    }
+
     public ASTIdentifier(int id) {
         super(id);
     }
@@ -46,8 +53,25 @@
     public String getName() {
         return name;
     }
-  
+
+    public Type getType() {
+        return type;
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
     public String toString() {
-        return "ASTIdentifier(" + name + ")";
+        String typesuffix = "";
+        if (type != null) {
+            typesuffix = ": ";
+            if (type.nullable)
+                typesuffix += "?";
+            typesuffix += type.typeName;
+            if (type.notnullable)
+                typesuffix += "!";
+        }
+        return "ASTIdentifier(" + name + typesuffix + ")";
     }
 }

Added: openlaszlo/trunk/test/typevar.lzx


Property changes on: openlaszlo/trunk/test/typevar.lzx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native


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

Reply via email to