royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-compiler] branch develop updated: more cases that fixes #52
Date Thu, 11 Oct 2018 19:11:39 GMT
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new c678251  more cases that fixes #52
c678251 is described below

commit c6782512a0ca9c85323a9ec65c46bcfeaaa368df
Author: Alex Harui <aharui@apache.org>
AuthorDate: Thu Oct 11 12:09:52 2018 -0700

    more cases that fixes #52
---
 .../codegen/js/jx/BinaryOperatorEmitter.java       | 132 +++++++++++++++++++++
 .../codegen/js/royale/TestRoyaleGlobalClasses.java |  32 +++++
 2 files changed, 164 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index d24da15..756c3d8 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -23,6 +23,7 @@ import org.apache.royale.compiler.codegen.ISubEmitter;
 import org.apache.royale.compiler.codegen.js.IJSEmitter;
 import org.apache.royale.compiler.constants.IASLanguageConstants;
 import org.apache.royale.compiler.definitions.IDefinition;
+import org.apache.royale.compiler.definitions.ITypeDefinition;
 import org.apache.royale.compiler.definitions.metadata.IMetaTag;
 import org.apache.royale.compiler.definitions.metadata.IMetaTagAttribute;
 import org.apache.royale.compiler.internal.codegen.as.ASEmitterTokens;
@@ -107,6 +108,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
                 IDefinition rnodeDef = (rnode instanceof IIdentifierNode) ? 
                 		((IIdentifierNode) rnode).resolve(getWalker().getProject()) :
                 		null;
+                boolean isDynamicAccess = rnode instanceof DynamicAccessNode;
                 if (lnode.getNodeID() == ASTNodeID.SuperID
                         && rnodeDef instanceof AccessorDefinition)
                 {
@@ -208,6 +210,72 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
 	                    return;
                 	}
                 }
+                else if (isDynamicAccess && ((JSRoyaleEmitter)getEmitter()).isXML((IExpressionNode)lnode))
+                {
+                	DynamicAccessNode dyn = (DynamicAccessNode)rnode;
+                	ITypeDefinition type = dyn.getRightOperandNode().resolveType(getProject());
+                	if (type.isInstanceOf("String", getProject()) || type.isInstanceOf("Object",
getProject()))
+        			{
+                		String field;
+                    	if (node.getNodeID() == ASTNodeID.Op_AssignId)
+                    	{
+    	                    getWalker().walk(lnode);
+    	                    IExpressionNode dynLeft = dyn.getLeftOperandNode();
+    	                    IExpressionNode dynRight = dyn.getRightOperandNode();
+    	                    if (dynLeft instanceof UnaryOperatorAtNode)
+    	                    {
+    		                    write(".setAttribute(");
+    							field = fjs.stringifyNode(dyn.getRightOperandNode());
+    	                    }
+    	                    else if (dynRight instanceof UnaryOperatorAtNode)
+    	                    {
+    		                    write(".setAttribute(");
+    							field = fjs.stringifyNode(dynRight.getChild(0));
+    	                    }
+    	                    else
+    	                    {
+    		                    write(".setChild(");
+    							field = fjs.stringifyNode(dynLeft);
+    	                    }
+    	                    write(field + ", ");
+    	                    getWalker().walk(node.getRightOperandNode());
+    	                    write(ASEmitterTokens.PAREN_CLOSE);
+    	                    return;
+                    	}
+                    	else if (node.getNodeID() == ASTNodeID.Op_AddAssignID)
+                    	{
+    	                    getWalker().walk(lnode);
+    	                    IExpressionNode rightSide = dyn.getRightOperandNode();
+    	                    if (rightSide instanceof UnaryOperatorAtNode)
+    	                    {
+    		                    write(".setAttribute('");
+    							field = fjs.stringifyNode(((UnaryOperatorAtNode)rightSide).getChild(0));
+    							field = field.replace("\"", ""); // remove wrapping double-quotes
+    	                    }
+    	                    else
+    	                    {
+    		                    write(".setChild('");
+    							field = fjs.stringifyNode(rightSide);
+    							field = field.replace("\"", ""); // remove wrapping double-quotes
+    	                    }
+    	                    write(field + "', ");
+                            getWalker().walk(node.getLeftOperandNode());
+    	                    write(".plus(");
+    	                    getWalker().walk(node.getRightOperandNode());
+    	                    write(ASEmitterTokens.PAREN_CLOSE);
+    	                    write(ASEmitterTokens.PAREN_CLOSE);
+    	                    return;
+                    	}
+                    	else if (node.getNodeID() == ASTNodeID.Op_AddID)
+                    	{
+    	                    getWalker().walk(dyn);
+    	                    write(".plus(");
+    	                    getWalker().walk(node.getRightOperandNode());
+    	                    write(ASEmitterTokens.PAREN_CLOSE);
+    	                    return;
+                    	}
+        			}
+                }
                 else if (((JSRoyaleEmitter)getEmitter()).isProxy(((MemberAccessExpressionNode)leftSide).getLeftOperandNode())
&& leftDef == null)
                 {
                 	MemberAccessExpressionNode proxyNode = (MemberAccessExpressionNode)leftSide;
@@ -264,6 +332,70 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
                 	}
                 }
             }
+            else if (leftSide.getNodeID() == ASTNodeID.ArrayIndexExpressionID) // dynamic
access
+            {
+            	DynamicAccessNode dyn = (DynamicAccessNode)leftSide;
+            	IExpressionNode dynLeft = dyn.getLeftOperandNode();
+            	ITypeDefinition type = dyn.getRightOperandNode().resolveType(getProject());
+            	if (((JSRoyaleEmitter)getEmitter()).isXML(dynLeft) && type.isInstanceOf("String",
getProject()))
+    			{
+            		String field;
+                	if (node.getNodeID() == ASTNodeID.Op_AssignId)
+                	{
+	                    getWalker().walk(dynLeft);
+	                    IExpressionNode rightSide = dyn.getRightOperandNode();
+	                    if (rightSide instanceof UnaryOperatorAtNode)
+	                    {
+		                    write(".setAttribute('");
+							field = fjs.stringifyNode(((UnaryOperatorAtNode)rightSide).getChild(0));
+							field = field.replace("\"", ""); // remove wrapping double-quotes
+	                    }
+	                    else
+	                    {
+		                    write(".setChild('");
+							field = fjs.stringifyNode(rightSide);
+							field = field.replace("\"", ""); // remove wrapping double-quotes
+	                    }
+	                    write(field + "', ");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+                	else if (node.getNodeID() == ASTNodeID.Op_AddAssignID)
+                	{
+	                    getWalker().walk(dynLeft);
+	                    IExpressionNode rightSide = dyn.getRightOperandNode();
+	                    if (rightSide instanceof UnaryOperatorAtNode)
+	                    {
+		                    write(".setAttribute('");
+							field = fjs.stringifyNode(((UnaryOperatorAtNode)rightSide).getChild(0));
+							field = field.replace("\"", ""); // remove wrapping double-quotes
+	                    }
+	                    else
+	                    {
+		                    write(".setChild('");
+							field = fjs.stringifyNode(rightSide);
+							field = field.replace("\"", ""); // remove wrapping double-quotes
+	                    }
+	                    write(field + "', ");
+                        getWalker().walk(node.getLeftOperandNode());
+	                    write(".plus(");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+                	else if (node.getNodeID() == ASTNodeID.Op_AddID)
+                	{
+	                    getWalker().walk(dyn);
+	                    write(".plus(");
+	                    getWalker().walk(node.getRightOperandNode());
+	                    write(ASEmitterTokens.PAREN_CLOSE);
+	                    return;
+                	}
+
+    			}
+            }
 
             boolean leftIsNumber = (leftDef != null && (leftDef.getQualifiedName().equals(IASLanguageConstants.Number)
||
 					  leftDef.getQualifiedName().equals(IASLanguageConstants._int) ||
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
index 74fb242..7f59087 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
@@ -766,6 +766,30 @@ public class TestRoyaleGlobalClasses extends TestGoogGlobalClasses
     }
     
     @Test
+    public void testXMLSetAttributeBracket()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.@[\"bar\"]
= 'foo'");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setAttribute(\"bar\", 'foo')");
+    }
+    
+    @Test
+    public void testXMLSetAttributeBracketProp()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var z:String = 'prop';var a:XML = new XML(\"<top
attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.@[z]
= 'foo'");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setAttribute(z, 'foo')");
+    }
+    
+    @Test
+    public void testXMLSetAttributeBracketPropObject()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var z:Object = 'prop';var a:XML = new XML(\"<top
attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.@[z]
= 'foo'");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setAttribute(z, 'foo')");
+    }
+    
+    @Test
     public void testXMLListSetAttribute()
     {
         IBinaryOperatorNode node = getBinaryNode("var a:XMLList;a[1].@bar = 'foo'");
@@ -798,6 +822,14 @@ public class TestRoyaleGlobalClasses extends TestGoogGlobalClasses
     }
     
     @Test
+    public void testXMLSetChildBracket()
+    {
+        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 testXMLSetChildToObjectMember()
     {
     	BinaryOperatorAssignmentNode node = (BinaryOperatorAssignmentNode) getNode(


Mime
View raw message