incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1425974 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/ compiler.jx/src/org/apache/flex/compiler/as/ compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ compiler.j...
Date Wed, 26 Dec 2012 17:32:30 GMT
Author: mschmalle
Date: Wed Dec 26 17:32:29 2012
New Revision: 1425974

URL: http://svn.apache.org/viewvc?rev=1425974&view=rev
Log:
Flex:FalconJx
- Initial Goog parameter production

Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSDocEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSSharedData.java

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
Wed Dec 26 17:32:29 2012
@@ -25,8 +25,11 @@ import org.apache.flex.compiler.clients.
 import org.apache.flex.compiler.internal.driver.JSBackend;
 import org.apache.flex.compiler.internal.js.codgen.JSEmitter;
 import org.apache.flex.compiler.internal.js.codgen.JSGoogEmitter;
+import org.apache.flex.compiler.internal.js.codgen.JSSharedData;
 import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.js.internal.driver.TestWalkerBase;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -59,6 +62,38 @@ public class TestGoogEmiter extends Test
         //assertOut("");
     }
 
+    @Test
+    public void testSimpleParameterReturnType()
+    {
+        JSSharedData.OUTPUT_JSDOC = false;
+        IFunctionNode node = getMethod("function foo(bar:int):int{\n}");
+        visitor.visitFunction(node);
+        assertOut("foo.bar.A = function(bar) {\n}");
+        JSSharedData.OUTPUT_JSDOC = true;
+    }
+
+    @Test
+    public void testSimpleMultipleParameter()
+    {
+        JSSharedData.OUTPUT_JSDOC = false;
+        IFunctionNode node = getMethod("function foo(bar:int, baz:String, goo:A):void{\n}");
+        visitor.visitFunction(node);
+        assertOut("foo.bar.A = function(bar, baz, goo) {\n}");
+        JSSharedData.OUTPUT_JSDOC = true;
+    }
+
+    @Ignore
+    @Test
+    public void testSimpleMultipleParameter_JSDoc()
+    {
+        // jsdoc still needs to be sorted out before tests are executing
+        IFunctionNode node = getMethod("function foo(bar:int, baz:String, goo:A):void{\n}");
+        visitor.visitFunction(node);
+        assertOut("/**\n * @this {foo.bar.A}\n * @param {int} bar\n * @param {String} baz\n"
+                + " * @param {A} goo\n * @return {void}\n */\nfoo.bar.A = "
+                + "function(bar, baz, goo) {\n}");
+    }
+
     protected IBackend createBackend()
     {
         return new GoogBackend();
@@ -72,4 +107,13 @@ public class TestGoogEmiter extends Test
             return new JSGoogEmitter(out);
         }
     }
+
+    protected IFunctionNode getMethod(String code)
+    {
+        String source = "package foo.bar {public class A {" + code + "}}";
+        IFileNode node = getFileNode(source);
+        IFunctionNode child = (IFunctionNode) findFirstDescendantOfType(node,
+                IFunctionNode.class);
+        return child;
+    }
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java
Wed Dec 26 17:32:29 2012
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.visitor.IASBlockWalker;
@@ -127,6 +128,8 @@ public interface IASEmitter
      */
     void emitSetAccessor(ISetterNode node);
 
+    void emitParameter(IParameterNode node);
+
     //--------------------------------------------------------------------------
     // Expressions
     //--------------------------------------------------------------------------

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Wed Dec 26 17:32:29 2012
@@ -435,6 +435,7 @@ public class ASEmitter implements IASEmi
         for (int i = 0; i < len; i++)
         {
             IParameterNode node = nodes[i];
+            // this will call emitParameter(node)
             getWalker().walk(node);
             if (i < len - 1)
                 write(", ");
@@ -442,6 +443,20 @@ public class ASEmitter implements IASEmi
         write(")");
     }
 
+    @Override
+    public void emitParameter(IParameterNode node)
+    {
+        getWalker().walk(node.getNameExpressionNode());
+        write(":");
+        getWalker().walk(node.getVariableTypeNode());
+        IExpressionNode anode = node.getAssignedValueNode();
+        if (anode != null)
+        {
+            write(" = ");
+            getWalker().walk(anode);
+        }
+    }
+    
     protected void emitType(IExpressionNode node)
     {
         // TODO (mschmalle) node.getVariableTypeNode() will return "*" if undefined, what
to use?
@@ -507,4 +522,6 @@ public class ASEmitter implements IASEmi
         }
         return null;
     }
+
+
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
Wed Dec 26 17:32:29 2012
@@ -471,15 +471,7 @@ public class ASBlockWalker implements IA
     public void visitParameter(IParameterNode node)
     {
         debug("visitParameter()");
-        walk(node.getNameExpressionNode());
-        emitter.write(":");
-        walk(node.getVariableTypeNode());
-        IExpressionNode anode = node.getAssignedValueNode();
-        if (anode != null)
-        {
-            emitter.write(" = ");
-            walk(anode);
-        }
+        emitter.emitParameter(node);
     }
 
     @Override

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSDocEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSDocEmitter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSDocEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSDocEmitter.java
Wed Dec 26 17:32:29 2012
@@ -32,6 +32,12 @@ import org.apache.flex.compiler.tree.as.
 public class JSDocEmitter implements IJSDocEmitter
 {
 
+    public void write(String value)
+    {
+        if (JSSharedData.OUTPUT_JSDOC)
+            emitter.write(value);
+    }
+
     private JSEmitter emitter;
 
     public JSDocEmitter(JSEmitter emitter)
@@ -49,7 +55,7 @@ public class JSDocEmitter implements IJS
     @Override
     public void emitConstructor(IFunctionNode node)
     {
-        emitter.write(" * @constructor\n");
+        write(" * @constructor\n");
     }
 
     @Override
@@ -76,8 +82,7 @@ public class JSDocEmitter implements IJS
     @Override
     public void emitExtends(IClassDefinition superDefinition)
     {
-        emitter.write(" * @extends {" + superDefinition.getQualifiedName()
-                + "}\n");
+        write(" * @extends {" + superDefinition.getQualifiedName() + "}\n");
     }
 
     @Override
@@ -111,8 +116,8 @@ public class JSDocEmitter implements IJS
     @Override
     public void emitParam(IParameterNode node)
     {
-        emitter.write(" * @param {" + node.getVariableType() + "} "
-                + node.getName() + "\n");
+        write(" * @param {" + node.getVariableType() + "} " + node.getName()
+                + "\n");
     }
 
     @Override
@@ -135,13 +140,13 @@ public class JSDocEmitter implements IJS
         // TODO convert js types
         String rtype = node.getReturnType();
         if (rtype != null)
-            emitter.write(" * @return {" + rtype + "}\n");
+            write(" * @return {" + rtype + "}\n");
     }
 
     @Override
     public void emitThis(ITypeDefinition type)
     {
-        emitter.write(" * @this {" + type.getQualifiedName() + "}\n");
+        write(" * @this {" + type.getQualifiedName() + "}\n");
     }
 
     @Override
@@ -149,7 +154,7 @@ public class JSDocEmitter implements IJS
     {
         //String type = SemanticUtils.getTypeOfStem(node, emitter.getProject());
         String type = ((IVariableNode) node).getVariableType(); // XXX need to map to js
types
-        emitter.write(" * @type {" + type + "}\n");
+        write(" * @type {" + type + "}\n");
     }
 
     @Override
@@ -164,18 +169,18 @@ public class JSDocEmitter implements IJS
     public void emmitPackageHeader(IPackageNode node)
     {
         begin();
-        emitter.write(" * " + JSSharedData.getTimeStampString());
+        write(" * " + JSSharedData.getTimeStampString());
         end();
     }
 
     public void begin()
     {
-        emitter.write("/**\n");
+        write("/**\n");
     }
 
     public void end()
     {
-        emitter.write(" */\n");
+        write(" */\n");
     }
 
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSEmitter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSEmitter.java
Wed Dec 26 17:32:29 2012
@@ -41,7 +41,7 @@ public class JSEmitter extends ASEmitter
 {
     public static boolean javascriptMode = false;
 
-    private JSDocEmitter jsdoc;
+    protected JSDocEmitter jsdoc;
 
     public JSEmitter(FilterWriter out)
     {

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
Wed Dec 26 17:32:29 2012
@@ -24,13 +24,16 @@ import java.util.ArrayList;
 
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.ITypeNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 
@@ -69,9 +72,12 @@ public class JSGoogEmitter extends JSEmi
         ITypeNode type = findTypeNode(node);
         IClassNode cnode = (IClassNode) type;
         classDefinition = cnode.getDefinition();
+
         // constructor
         emitConstructor((IFunctionNode) classDefinition.getConstructor()
                 .getNode());
+        write(";\n");
+        write("\n");
 
         IDefinitionNode[] members = cnode.getAllMemberNodes();
         for (IDefinitionNode dnode : members)
@@ -79,6 +85,8 @@ public class JSGoogEmitter extends JSEmi
             if (dnode instanceof IVariableNode)
             {
                 emitField((IVariableNode) dnode);
+                write(";\n");
+                write("\n");
             }
         }
 
@@ -86,7 +94,12 @@ public class JSGoogEmitter extends JSEmi
         {
             if (dnode instanceof IFunctionNode)
             {
-                emitMethod((IFunctionNode) dnode);
+                if (!((IFunctionNode) dnode).isConstructor())
+                {
+                    emitMethod((IFunctionNode) dnode);
+                    write(";\n");
+                    write("\n");
+                }
             }
         }
     }
@@ -101,9 +114,9 @@ public class JSGoogEmitter extends JSEmi
     {
         FunctionNode fn = (FunctionNode) node;
         fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
-        
+
         emitJSDocConstructor(node, getWalker().getProject());
-        
+
         String qname = classDefinition.getQualifiedName();
         write(qname);
         write(" ");
@@ -112,8 +125,6 @@ public class JSGoogEmitter extends JSEmi
         write("function");
         emitParamters(node.getParameterNodes());
         emitMethodScope(node.getScopedNode());
-        write("\n");
-        write("\n");
     }
 
     public void emitField(IVariableNode node)
@@ -127,8 +138,42 @@ public class JSGoogEmitter extends JSEmi
             write(" = ");
             getWalker().walk(vnode);
         }
-        write(";\n");
-        write("\n");
+    }
+
+    public void emitJSDoc(IFunctionNode node, ICompilerProject project,
+            boolean isConstructor, ITypeDefinition type)
+    {
+        // TODO (mschmalle) change method signature, remove type
+        // this is a temp override until I change the method signature
+        // unit testing dosn't have access to the type, we need to use the AST to get the
definition
+        if (type == null)
+        {
+            ITypeNode tnode = (ITypeNode) node
+                    .getAncestorOfType(ITypeNode.class);
+            type = (ITypeDefinition) tnode.getDefinition();
+        }
+
+        if (node instanceof IFunctionNode)
+        {
+            if (isConstructor)
+            {
+                emitJSDocConstructor(node, project);
+            }
+            else
+            {
+                jsdoc.begin();
+                jsdoc.emitThis(type);
+                // @param
+                IParameterNode[] parameters = node.getParameterNodes();
+                for (IParameterNode pnode : parameters)
+                {
+                    jsdoc.emitParam(pnode);
+                }
+                // @return
+                jsdoc.emitReturn(node);
+                jsdoc.end();
+            }
+        }
     }
 
     @Override
@@ -136,12 +181,12 @@ public class JSGoogEmitter extends JSEmi
     {
         if (node.isConstructor())
             return;
-        
+
         emitJSDoc(node, getWalker().getProject(), false, classDefinition);
         FunctionNode fn = (FunctionNode) node;
         fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
 
-        String qname = classDefinition.getQualifiedName();
+        String qname = getTypeDefinition(node).getQualifiedName();
         write(qname);
         write(" ");
         write("=");
@@ -149,8 +194,13 @@ public class JSGoogEmitter extends JSEmi
         write("function");
         emitParamters(node.getParameterNodes());
         emitMethodScope(node.getScopedNode());
-        write("\n");
-        write("\n");
+    }
+
+    @Override
+    public void emitParameter(IParameterNode node)
+    {
+        // only the name gets output in JS
+        getWalker().walk(node.getNameExpressionNode());
     }
 
     public JSGoogEmitter(FilterWriter out)
@@ -158,4 +208,13 @@ public class JSGoogEmitter extends JSEmi
         super(out);
     }
 
+    private ITypeDefinition getTypeDefinition(IDefinitionNode node)
+    {
+        if (classDefinition != null)
+            return classDefinition;
+
+        ITypeNode tnode = (ITypeNode) node.getAncestorOfType(ITypeNode.class);
+        return (ITypeDefinition) tnode.getDefinition();
+    }
+
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSSharedData.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSSharedData.java?rev=1425974&r1=1425973&r2=1425974&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSSharedData.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSSharedData.java
Wed Dec 26 17:32:29 2012
@@ -36,6 +36,10 @@ public class JSSharedData
     public static final String COMPILER_VERSION = "329449.1";
 
     public final static JSSharedData instance = new JSSharedData();
+    
+    // TODO (mschmalle) Temp until I figure out the correct place for configuration
+    public static boolean OUTPUT_JSDOC = true;
+    
     public static IBackend backend;
     public static String OUTPUT_EXTENSION;
     public static Workspace workspace;



Mime
View raw message