flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1442091 - in /flex/falcon/trunk: compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/ compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/ compil...
Date Mon, 04 Feb 2013 12:29:04 GMT
Author: mschmalle
Date: Mon Feb  4 12:29:03 2013
New Revision: 1442091

URL: http://svn.apache.org/viewvc?rev=1442091&view=rev
Log:
Flex:FalconJx
- starting the impl on AMD, added PackageTest
- moved findType into ASEmitter

Added:
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java
  (with props)
Modified:
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDEmiter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/JSAMDEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java

Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDEmiter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDEmiter.java?rev=1442091&r1=1442090&r2=1442091&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDEmiter.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDEmiter.java
Mon Feb  4 12:29:03 2013
@@ -24,6 +24,7 @@ import org.apache.flex.compiler.internal
 import org.apache.flex.compiler.internal.js.driver.amd.AMDBackend;
 import org.apache.flex.compiler.tree.as.IFileNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -36,11 +37,10 @@ import org.junit.Test;
  */
 public class TestAMDEmiter extends TestWalkerBase
 {
+    @Ignore
 	@Test
     public void testSimple()
     {
-		// (erikdebruin) this test isn't outputting JS; ignoring for now, as
-		//               we are not (yet) working on AMD JS output
         String code = "package com.example.components {"
                 + "import org.apache.flex.html.staticControls.TextButton;"
                 + "public class MyTextButton extends TextButton {"

Added: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java?rev=1442091&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java
(added)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java
Mon Feb  4 12:29:03 2013
@@ -0,0 +1,140 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.js.codegen.amd;
+
+import org.apache.flex.compiler.clients.IBackend;
+import org.apache.flex.compiler.internal.as.codegen.TestPackage;
+import org.apache.flex.compiler.internal.js.driver.amd.AMDBackend;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for AS package.
+ * 
+ * @author Michael Schmalle
+ */
+public class TestAMDPackage extends TestPackage
+{
+    /*
+     * $0 = defineClass|defineInterface
+     * $1 = "./I", "as3/trace", "as3/bind"
+     * $2 = I,       trace,       bind_
+     * 
+     * 
+define(["runtime/$0", $1],
+    function($0,     $2) {
+    "use strict";
+    
+    // constructor 
+    function A(arg/~:String~/) {
+        A.$$ && A.$$(); // execute static code once on first usage
+L#      this.msg = msg;
+    }
+    
+    // private method
+    function secret(n) {
+L#      return this.msg + n; // add 'this'
+    }
+    
+    return definedClass(A, { implements_: I,
+        members: {
+        }
+        },
+        
+        staticMembers: {
+        },
+        
+        staticCode: function() {
+        
+        }
+    });
+    
+  });
+     */
+
+    @Override
+    @Test
+    public void testPackage_Simple()
+    {
+        IFileNode node = getFileNode("package{}");
+        visitor.visitFile(node);
+        assertOut("define();");
+    }
+
+    @Override
+    @Test
+    public void testPackage_SimpleName()
+    {
+        IFileNode node = getFileNode("package foo {}");
+        visitor.visitFile(node);
+        assertOut("define();");
+    }
+
+    @Override
+    @Test
+    public void testPackage_Name()
+    {
+        IFileNode node = getFileNode("package foo.bar.baz {}");
+        visitor.visitFile(node);
+        assertOut("define();");
+    }
+
+    @Override
+    @Test
+    public void testPackageSimple_Class()
+    {
+        IFileNode node = getFileNode("package {public class A{}}");
+        visitor.visitFile(node);
+        //assertOut("");
+    }
+
+    @Override
+    @Test
+    public void testPackageQualified_Class()
+    {
+        IFileNode node = getFileNode("package foo.bar.baz {public class A{}}");
+        visitor.visitFile(node);
+        //assertOut("");
+    }
+
+    @Override
+    @Test
+    public void testPackageQualified_ClassBody()
+    {
+        IFileNode node = getFileNode("package foo.bar.baz {public class A{public function
A(){}}}");
+        visitor.visitFile(node);
+        //assertOut("");
+    }
+
+    @Override
+    @Test
+    public void testPackageQualified_ClassBodyMethodContents()
+    {
+        IFileNode node = getFileNode("package foo.bar.baz {public class A{public function
A(){if (a){for (var i:Object in obj){doit();}}}}}");
+        visitor.visitFile(node);
+        //assertOut("");
+    }
+
+    @Override
+    protected IBackend createBackend()
+    {
+        return new AMDBackend();
+    }
+}

Propchange: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/amd/TestAMDPackage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1442091&r1=1442090&r2=1442091&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Mon Feb  4 12:29:03 2013
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.interna
 import java.io.FilterWriter;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.flex.compiler.as.codegen.IASEmitter;
@@ -34,6 +35,7 @@ import org.apache.flex.compiler.constant
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.definitions.IVariableDefinition;
 import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
@@ -1082,7 +1084,17 @@ public class ASEmitter implements IASEmi
         }
         return null;
     }
-
+    
+    protected ITypeDefinition findType(Collection<IDefinition> definitions)
+    {
+        for (IDefinition definition : definitions)
+        {
+            if (definition instanceof ITypeDefinition)
+                return (ITypeDefinition) definition;
+        }
+        return null;
+    }
+    
     protected void walkArguments(IExpressionNode[] nodes)
     {
         int len = nodes.length;

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/JSAMDEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/JSAMDEmitter.java?rev=1442091&r1=1442090&r2=1442091&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/JSAMDEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/amd/JSAMDEmitter.java
Mon Feb  4 12:29:03 2013
@@ -30,12 +30,14 @@ import org.apache.flex.compiler.common.A
 import org.apache.flex.compiler.constants.IASKeywordConstants;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 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.js.codegen.JSEmitter;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.js.codegen.amd.IJSAMDDocEmitter;
 import org.apache.flex.compiler.js.codegen.amd.IJSAMDEmitter;
 import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.scopes.IASScope;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
@@ -54,6 +56,46 @@ public class JSAMDEmitter extends JSEmit
         return (IJSAMDDocEmitter) getDocEmitter();
     }
 
+    @Override
+    public void emitPackageHeader(IPackageDefinition definition)
+    {
+        write("define(");
+
+        IASScope containedScope = definition.getContainedScope();
+        ITypeDefinition type = findType(containedScope.getAllLocalDefinitions());
+        if (type == null)
+            return;
+
+        // runtime
+        writeRuntimeList(type);
+
+    }
+
+    private void writeRuntimeList(ITypeDefinition type)
+    {
+        // [defineClass|Interface, deps
+
+    }
+
+    @Override
+    public void emitPackageHeaderContents(IPackageDefinition definition)
+    {
+        // nothing
+    }
+
+    @Override
+    public void emitPackageContents(IPackageDefinition definition)
+    {
+        // walk IClassNode | IInterfaceNode
+    }
+
+    @Override
+    public void emitPackageFooter(IPackageDefinition definition)
+    {
+        //write("}"); // end returned function
+        write(");"); // end define()
+    }
+
     //--------------------------------------------------------------------------
     // 
     //--------------------------------------------------------------------------
@@ -121,15 +163,15 @@ public class JSAMDEmitter extends JSEmit
 
         if (defaults != null)
         {
-        	boolean hasBody = node.getScopedNode().getChildCount() > 0;
-            
+            boolean hasBody = node.getScopedNode().getChildCount() > 0;
+
             if (!hasBody)
             {
                 indentPush();
                 write(INDENT);
             }
 
-        	final StringBuilder code = new StringBuilder();
+            final StringBuilder code = new StringBuilder();
 
             List<IParameterNode> parameters = new ArrayList<IParameterNode>(
                     defaults.values());
@@ -142,7 +184,7 @@ public class JSAMDEmitter extends JSEmit
                 if (pnode != null)
                 {
                     code.setLength(0);
-                    
+
                     code.append(IASKeywordConstants.IF);
                     code.append(SPACE);
                     code.append(PARENTHESES_OPEN);
@@ -156,9 +198,9 @@ public class JSAMDEmitter extends JSEmit
                     code.append(PARENTHESES_CLOSE);
                     code.append(SPACE);
                     code.append(CURLYBRACE_OPEN);
-                    
+
                     write(code.toString());
-                    
+
                     indentPush();
                     writeNewline();
                 }
@@ -168,12 +210,12 @@ public class JSAMDEmitter extends JSEmit
             Collections.reverse(parameters);
             for (int i = 0, n = parameters.size(); i < n; i++)
             {
-            	IParameterNode pnode = parameters.get(i);
-            	
+                IParameterNode pnode = parameters.get(i);
+
                 if (pnode != null)
                 {
                     code.setLength(0);
-                    
+
                     code.append(pnode.getName());
                     code.append(SPACE);
                     code.append(EQUALS);
@@ -184,12 +226,12 @@ public class JSAMDEmitter extends JSEmit
 
                     indentPop();
                     writeNewline();
-                    
+
                     write(CURLYBRACE_CLOSE);
 
                     if (i == n - 1 && !hasBody)
-                    	indentPop();
-                    
+                        indentPop();
+
                     writeNewline();
                 }
             }

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1442091&r1=1442090&r2=1442091&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
Mon Feb  4 12:29:03 2013
@@ -21,7 +21,6 @@ package org.apache.flex.compiler.interna
 
 import java.io.FilterWriter;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -122,16 +121,6 @@ public class JSGoogEmitter extends JSEmi
         writeNewline();
     }
 
-    private ITypeDefinition findType(Collection<IDefinition> definitions)
-    {
-        for (IDefinition definition : definitions)
-        {
-            if (definition instanceof ITypeDefinition)
-                return (ITypeDefinition) definition;
-        }
-        return null;
-    }
-
     @Override
     public void emitPackageHeaderContents(IPackageDefinition definition)
     {



Mime
View raw message