flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - FLEX-35014 improve Vector support
Date Fri, 18 Nov 2016 00:24:48 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 5aa512f2b -> 7a6e27a07


FLEX-35014 improve Vector support


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/7a6e27a0
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/7a6e27a0
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/7a6e27a0

Branch: refs/heads/develop
Commit: 7a6e27a07b3003424046f91fea4c8001e4d7e9ba
Parents: 5aa512f
Author: Alex Harui <aharui@apache.org>
Authored: Thu Nov 17 16:19:13 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Nov 17 16:24:46 2016 -0800

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java      |  8 +++
 .../js/flexjs/JSFlexJSEmitterTokens.java        |  1 +
 .../codegen/js/jx/FunctionCallEmitter.java      | 54 +++++++++++++++-----
 .../js/flexjs/TestFlexJSGlobalClasses.java      | 21 ++++----
 .../js/flexjs/TestFlexJSGlobalFunctions.java    | 17 +++---
 .../flex/compiler/internal/test/TestBase.java   | 10 ++++
 6 files changed, 82 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index 6d6cb8c..4bcc3cf 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -38,6 +38,7 @@ import org.apache.flex.compiler.definitions.IPackageDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.definitions.metadata.IMetaTagAttribute;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.ImplicitBindableImplementation;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitter;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
@@ -106,6 +107,7 @@ import org.apache.flex.compiler.tree.as.INamespaceNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
 import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.utils.ASNodeUtils;
@@ -1251,4 +1253,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     	}
     	super.emitLabelStatement(node);
     }
+    
+    @Override
+    public void emitTypedExpression(ITypedExpressionNode node)
+    {
+        write(JSFlexJSEmitterTokens.VECTOR);
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
index 4a140e3..50e612b 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
@@ -56,6 +56,7 @@ public enum JSFlexJSEmitterTokens implements IEmitterTokens
     SKIP_AS_COERCIONS("skipAsCoercions"),
     SKIP_FUNCTION_COERCIONS("skipFunctionCoercions"),
     JSX("JSX"),
+    VECTOR("org.apache.flex.utils.Language.Vector"),
     ;
 
     private String token;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
index 4b31159..d125eeb 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
@@ -36,6 +36,8 @@ import org.apache.flex.compiler.internal.definitions.InterfaceDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.ContainerNode;
 import org.apache.flex.compiler.internal.tree.as.VectorLiteralNode;
+import org.apache.flex.compiler.problems.TooFewFunctionParametersProblem;
+import org.apache.flex.compiler.problems.TooManyFunctionParametersProblem;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -67,7 +69,8 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
         if (id != ASTNodeID.SuperID)
         {
             IDefinition def = null;
-            def = node.getNameNode().resolve(getProject());
+            IExpressionNode nameNode = node.getNameNode();
+            def = nameNode.resolve(getProject());
 
             boolean isClassCast = false;
 
@@ -75,7 +78,9 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
             {
                 if (!(node.getChild(1) instanceof VectorLiteralNode))
                 {
-                    if (def == null || !(def.getBaseName().equals(IASGlobalFunctionConstants._int)
|| def.getBaseName().equals(IASGlobalFunctionConstants.uint)))
+                    if (def == null || !(def.getBaseName().equals(IASGlobalFunctionConstants._int)
|| 
+                    					 def.getBaseName().equals(IASGlobalFunctionConstants.uint) ||
+                    					 def instanceof AppliedVectorDefinition))
                     {
 	                    startMapping(node.getNewKeywordNode());
 	                    writeToken(ASEmitterTokens.NEW);
@@ -113,7 +118,6 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
             if (node.isNewExpression())
             {
                 def = node.resolveCalledExpression(getProject());
-                IExpressionNode nameNode = node.getNameNode();
                 // all new calls to a class should be fully qualified names
                 if (def instanceof ClassDefinition)
                 {
@@ -151,7 +155,29 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
                         write(ASEmitterTokens.PAREN_CLOSE);                        
                 }
                 
-                getEmitter().emitArguments(node.getArgumentsNode());
+                if (def instanceof AppliedVectorDefinition)
+                {
+                	ContainerNode args = node.getArgumentsNode();
+                	if (args.getChildCount() == 0)
+                	{
+                    	getEmitter().emitArguments(node.getArgumentsNode());
+                	}
+                	else
+                	{
+                        startMapping(node);
+                        write(ASEmitterTokens.PAREN_OPEN);
+                        endMapping(node);
+                        getWalker().walk(args.getChild(0));
+                        write(ASEmitterTokens.COMMA);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        write(((AppliedVectorDefinition)def).resolveElementType(getWalker().getProject()).getBaseName());
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        write(ASEmitterTokens.PAREN_CLOSE);
+                	}
+                }
+                else
+                	getEmitter().emitArguments(node.getArgumentsNode());
             }
             else if (!isClassCast)
             {
@@ -217,16 +243,20 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
                     {
                         IExpressionNode[] argumentNodes = node.getArgumentNodes();
                         int len = argumentNodes.length;
-                        for (int i = 0; i < len; i++)
-                        {
-                            IExpressionNode argumentNode = argumentNodes[i];
+                    	if (len == 0)
+                    	{
+                    		getWalker().getProject().getProblems().add(new TooFewFunctionParametersProblem(node,
1));
+                    	}
+                    	else if (len > 1)
+                    	{
+                    		getWalker().getProject().getProblems().add(new TooManyFunctionParametersProblem(node,
1));                    		
+                    	}
+                    	else
+                    	{
+                            IExpressionNode argumentNode = argumentNodes[0];
                             getWalker().walk(argumentNode);
-                            if(i < len - 1)
-                            {
-                                write(", ");
-                            }
+                            write(".slice()");
                         }
-                        write(".slice()");
                         return;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index 58324bd..247fcd5 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -282,7 +282,8 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(['Hello',
'World']);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        //MXMLC does not report an error.  Should we?
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector(['Hello',
'World'], 'String')");
     }
 
     @Test
@@ -314,7 +315,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>();");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array()");
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector()");
     }
 
     @Test
@@ -322,8 +323,8 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>('Hello',
'World');");
         asBlockWalker.visitVariable(node);
-        // expected error?
-        assertOut("var /** @type {Array} */ a = new Array('Hello', 'World')");
+        //MXMLC does not report an error.  Should we?
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector('Hello',
'String')");
     }
 
     @Test
@@ -331,8 +332,8 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>('Hello',
'World', 'Three');");
         asBlockWalker.visitVariable(node);
-        // expected error?
-        assertOut("var /** @type {Array} */ a = new Array('Hello', 'World', 'Three')");
+        //MXMLC does not report an error.  Should we?
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector('Hello',
'String')");
     }
 
     @Test
@@ -340,7 +341,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(30);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(30)");
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector(30,
'String')");
     }
 
     @Test
@@ -348,7 +349,8 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(30,
40);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(30, 40)");
+        //MXMLC does not report an error.  Should we?
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector(30,
'String')");
     }
 
     @Test
@@ -356,7 +358,8 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(['Hello',
'World']);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        //MXMLC does not report an error.  Should we?
+        assertOut("var /** @type {Array} */ a = org.apache.flex.utils.Language.Vector(['Hello',
'World'], 'String')");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
index 66397d8..fc49825 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
@@ -162,36 +162,37 @@ public class TestFlexJSGlobalFunctions extends TestGoogGlobalFunctions
         assertOut("var /** @type {Array} */ a = ['Hello', 'World'].slice()");
     }
 
-    @Ignore
+    @Test
     public void testVectorNoArgs()
     {
         IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>();");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = Array()");
+        assertErrors("Incorrect number of arguments.  Expected 1");
     }
 
-    @Ignore
+    @Test
     public void testVectorStringArgs()
     {
         IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>('Hello',
'World');");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = Array('Hello', 'World')");
+        assertErrors("Incorrect number of arguments.  Expected no more than 1");
     }
 
-    @Ignore
+    @Test
     public void testVectorSizeArg()
     {
         IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(30);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = Array(30)");
+        // MXMLC doesn't report an error either.  Maybe we should. 
+        assertOut("var /** @type {Array} */ a = 30.slice()");
     }
 
-    @Ignore
+    @Test
     public void testVectorNumberArgs()
     {
         IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(30,
40);");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = Array(30, 40)");
+        assertErrors("Incorrect number of arguments.  Expected no more than 1");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7a6e27a0/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/TestBase.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/TestBase.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/TestBase.java
index aa495ca..c0234fa 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/TestBase.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/TestBase.java
@@ -154,6 +154,16 @@ public class TestBase implements ITestBase
         return null;
     }
 
+    protected void assertErrors(String errorReport)
+    {
+    	StringBuilder actualErrors = new StringBuilder();
+    	for (ICompilerProblem problem : errors)
+    	{
+    		actualErrors.append(problem.toString());
+    	}
+        assertThat(actualErrors.toString(), is(errorReport));
+    }
+    
     protected void assertOut(String code, boolean keepMetadata)
     {
     	mCode = removeGeneratedString(writer.toString());


Mime
View raw message