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] - XML support for assignment and for loops
Date Thu, 19 Nov 2015 07:02:22 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 1fb6f371f -> 22fa6defa


XML support for assignment and for loops


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

Branch: refs/heads/develop
Commit: 22fa6defa3ed2896de4eba1a5a1b316e1e3c2b0f
Parents: 1fb6f37
Author: Alex Harui <aharui@apache.org>
Authored: Wed Nov 18 23:02:05 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Wed Nov 18 23:02:05 2015 -0800

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSGlobalClasses.java      | 42 ++++++++++++++++++++
 .../flex/compiler/internal/test/ASTestBase.java |  6 +++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 19 +++++++++
 .../codegen/js/jx/BinaryOperatorEmitter.java    | 36 +++++++++++++++++
 .../internal/codegen/js/jx/ForEachEmitter.java  | 41 ++++++++++++++++---
 5 files changed, 139 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/22fa6def/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index c837390..322ee63 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -23,6 +23,8 @@ import org.apache.flex.compiler.driver.IBackend;
 import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogGlobalClasses;
 import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
@@ -341,6 +343,46 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         assertOut("var /** @type {XMLList} */ b = a.descendants('grandchild').filter(function(node){return
(node.attribute('attr2') == 'fish')})");
     }
     
+    @Test
+    public void testXMLSetChild()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.foo
= a.child");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setChild('foo', a.child('child'))");
+    }
+    
+    @Test
+    public void testXMLListConcat()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.foo
+= a.child");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.child('foo').concat(a.child('child'))");
+    }
+    
+    @Test
+    public void testXMLListAddAndAssign()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.foo
= a.child + a..grandchild");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setChild('foo', a.child('child').copy().concat(a.descendants('grandchild')))");
+    }
+    
+    @Test
+    public void testXMLForLoop()
+    {
+        IForLoopNode node = getForLoopNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");for
(var p:* in a) delete a[p];");
+        asBlockWalker.visitForLoop(node);
+        assertOut("for (var /** @type {*} */ p in a.elementNames())\n  a.removeChild(p);");
+    }
+    
+    @Test
+    public void testXMLForEachLoop()
+    {
+    	IForLoopNode node = getForLoopNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");for
each (var p:XMLList in a) var i:int = p.length();");
+        asBlockWalker.visitForLoop(node);
+        assertOut("for (var foreachiter0 in a.elementNames()) \n{\nvar p = a.child(foreachiter0);\n\n
 var /** @type {number} */ i = p.length();}\n");
+    }
+    
     @Ignore
     public void testNamespaceNoArg()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/22fa6def/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/ASTestBase.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/ASTestBase.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/ASTestBase.java
index 8da5a9a..8cb7b11 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/ASTestBase.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/ASTestBase.java
@@ -29,6 +29,7 @@ import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
@@ -152,6 +153,11 @@ public class ASTestBase extends TestBase
         return (IBinaryOperatorNode) getNode(code, IBinaryOperatorNode.class);
     }
 
+    protected IForLoopNode getForLoopNode(String code)
+    {
+        return (IForLoopNode) getNode(code, IForLoopNode.class);
+    }
+
     protected INamespaceAccessExpressionNode getNamespaceAccessExpressionNode(
             String code)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/22fa6def/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index c87cadc..f0431af 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -486,6 +486,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         		        return;
         			}
         		}
+        		else if (node.getChild(0).getChild(0).getNodeID() == ASTNodeID.IdentifierID)
+        		{
+        			if (isXML((IdentifierNode)(node.getChild(0).getChild(0))))
+        			{
+        		        if (ASNodeUtils.hasParenOpen(node))
+        		            write(ASEmitterTokens.PAREN_OPEN);
+        		        
+        	            getWalker().walk(node.getChild(0).getChild(0));
+        	            DynamicAccessNode dan = (DynamicAccessNode)(node.getChild(0));
+        	            IASNode indexNode = dan.getChild(1);
+        	            write(".removeChild(");
+        	            getWalker().walk(indexNode);
+        	            write(")");
+        		        if (ASNodeUtils.hasParenClose(node))
+        		            write(ASEmitterTokens.PAREN_CLOSE);
+        		        return;        				
+        			}
+        		}
+
         	}
         	else if (node.getChild(0).getNodeID() == ASTNodeID.MemberAccessExpressionID)
     		{

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/22fa6def/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 4a7d1e7..38935e2 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -28,6 +28,7 @@ import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -142,6 +143,36 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
                         return;
                     }
                 }
+                else if (((JSFlexJSEmitter)getEmitter()).isXMLList((MemberAccessExpressionNode)leftSide))
+                {
+                	MemberAccessExpressionNode xmlNode = (MemberAccessExpressionNode)leftSide;
+                	if (node.getNodeID() == ASTNodeID.Op_AssignId)
+                	{
+	                    getWalker().walk(xmlNode.getLeftOperandNode());
+	                    write(".setChild('");
+	                    getWalker().walk(xmlNode.getRightOperandNode());
+	                    write("', ");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+                	else if (node.getNodeID() == ASTNodeID.Op_AddAssignID)
+                	{
+	                    getWalker().walk(xmlNode);
+	                    write(".concat(");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+                	else if (node.getNodeID() == ASTNodeID.Op_AddID)
+                	{
+	                    getWalker().walk(xmlNode);
+	                    write(".copy().concat(");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+                }
             }
 
             super_emitBinaryOperator(node);
@@ -278,6 +309,11 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
         	}
         	else */
         		getWalker().walk(node.getRightOperandNode());
+                if (node.getNodeID() == ASTNodeID.Op_InID &&
+                        ((JSFlexJSEmitter)getEmitter()).isXML(node.getRightOperandNode()))
+                {
+                	write(".elementNames()");
+                }   
         }
 
         if (ASNodeUtils.hasParenOpen(node))

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/22fa6def/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
index 1b33061..cf151b5 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
@@ -23,6 +23,10 @@ import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IForLoopNode;
@@ -58,7 +62,25 @@ public class ForEachEmitter extends JSSubEmitter implements
         write(ASEmitterTokens.SPACE);
         write(ASEmitterTokens.IN);
         write(ASEmitterTokens.SPACE);
-        getWalker().walk(bnode.getChild(1));
+        IASNode obj = bnode.getChild(1);
+        getWalker().walk(obj);
+        boolean isXML = false;
+        if (obj.getNodeID() == ASTNodeID.IdentifierID)
+        {
+        	if (((JSFlexJSEmitter)getEmitter()).isXML((IdentifierNode)obj))
+        	{
+        		write(".elementNames()");
+        		isXML = true;
+        	}
+        }
+        else if (obj.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+        {
+            if (((JSFlexJSEmitter)getEmitter()).isXMLList((MemberAccessExpressionNode)obj))
+            {
+                write(".elementNames()");
+                isXML = true;
+            }
+        }
         writeToken(ASEmitterTokens.PAREN_CLOSE);
         writeNewline();
         write(ASEmitterTokens.BLOCK_OPEN);
@@ -74,10 +96,19 @@ public class ForEachEmitter extends JSSubEmitter implements
         write(ASEmitterTokens.SPACE);
         write(ASEmitterTokens.EQUAL);
         write(ASEmitterTokens.SPACE);
-        getWalker().walk(bnode.getChild(1));
-        write(ASEmitterTokens.SQUARE_OPEN);
-        write(iterName);
-        write(ASEmitterTokens.SQUARE_CLOSE);
+        getWalker().walk(obj);
+        if (isXML)
+        {
+        	write(".child(");
+        	write(iterName);
+        	write(")");
+        }
+        else
+        {
+	        write(ASEmitterTokens.SQUARE_OPEN);
+	        write(iterName);
+	        write(ASEmitterTokens.SQUARE_CLOSE);
+        }
         write(ASEmitterTokens.SEMICOLON);
         writeNewline();
         getWalker().walk(node.getStatementContentsNode());


Mime
View raw message