You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2022/01/18 22:45:55 UTC

[royale-compiler] branch develop updated: Support for addition operator with XMLish operands. Fix for #208

This is an automated email from the ASF dual-hosted git repository.

gregdove 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 02b56a7  Support for addition operator with XMLish operands. Fix for #208
02b56a7 is described below

commit 02b56a7fd7ff66731cf83ce1f044f6d946649c0c
Author: greg-dove <gr...@gmail.com>
AuthorDate: Wed Jan 19 10:49:33 2022 +1300

    Support for addition operator with XMLish operands. Fix for #208
---
 .../codegen/js/jx/BinaryOperatorEmitter.java       | 19 +++++++++++++++---
 .../compiler/internal/semantics/SemanticUtils.java | 23 +++++++++++++++++++++-
 2 files changed, 38 insertions(+), 4 deletions(-)

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 0b98f44..bfbdc2b 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
@@ -44,6 +44,8 @@ import org.apache.royale.compiler.tree.ASTNodeID;
 import org.apache.royale.compiler.tree.as.*;
 import org.apache.royale.compiler.utils.ASNodeUtils;
 
+import java.util.ArrayList;
+
 public class BinaryOperatorEmitter extends JSSubEmitter implements
         ISubEmitter<IBinaryOperatorNode>
 {
@@ -562,8 +564,12 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
 			}
             else getWalker().walk(node.getLeftOperandNode());
             startMapping(node, node.getLeftOperandNode());
-            
-            if (id != ASTNodeID.Op_CommaID)
+			boolean xmlAdd = false;
+            if (id == ASTNodeID.Op_AddID && SemanticUtils.isXMLish(node.getLeftOperandNode(),getProject()) && SemanticUtils.isXMLish(node.getRightOperandNode(),getProject())) {
+				//we need to use 'plus' method instead of '+'
+				xmlAdd = true;
+			}
+            if (id != ASTNodeID.Op_CommaID && !xmlAdd)
                 write(ASEmitterTokens.SPACE);
 
             // (erikdebruin) rewrite 'a &&= b' to 'a = a && b'
@@ -585,7 +591,11 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
             }
             else
             {
-                write(node.getOperator().getOperatorText());
+				if (xmlAdd) {
+					write(".plus(");
+				} else {
+					write(node.getOperator().getOperatorText());
+				}
             }
 
             write(ASEmitterTokens.SPACE);
@@ -612,6 +622,9 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
 					write(".propertyNames()");
 				}
 			}
+			if (xmlAdd) {
+				write(")");
+			}
         }
 
         if (ASNodeUtils.hasParenOpen(node))
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
index d22d291..7973e71 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
@@ -1002,6 +1002,9 @@ public class SemanticUtils
                         //method call on XML or XMLList instance
                         return resolvedDef;
                     }
+                } else {
+                    resolvedDef = functionCall.resolveType(project);
+                    if (resolvedDef != null && isXMLish(resolvedDef, project)) return resolvedDef;
                 }
             }
             return null;
@@ -1018,6 +1021,11 @@ public class SemanticUtils
                     //private/protected member inside the XML or XMLList class
                     return resolvedDef;
                 }
+            } else {
+                resolvedDef = identifierNode.resolveType(project);
+                if (resolvedDef != null && isXMLish(resolvedDef, project)) {
+                    return resolvedDef;
+                }
             }
         }
         if (iNode instanceof IMemberAccessExpressionNode)
@@ -1033,6 +1041,19 @@ public class SemanticUtils
      * Determine if the definition passed in is one of the XML types (XML or
      * XMLList) These classes are unrelated, but behave in similar manners.
      * 
+     * @param iNode the {@link IExpressionNode} to check
+     * @param project the {@link ICompilerProject} in which to look up types
+     * @return true if definition is the built-in XML or XMLList type.
+     */
+    public static boolean isXMLish(IExpressionNode iNode, ICompilerProject project)
+    {
+        return isXMLish(resolveXML(iNode, project), project);
+    }
+
+    /**
+     * Determine if the definition passed in is one of the XML types (XML or
+     * XMLList) These classes are unrelated, but behave in similar manners.
+     *
      * @param def the {@link IDefinition} to check
      * @param project the {@link ICompilerProject} in which to look up types
      * @return true if definition is the built-in XML or XMLList type.
@@ -1042,7 +1063,7 @@ public class SemanticUtils
         IDefinition xmlDef = project.getBuiltinType(IASLanguageConstants.BuiltinType.XML);
         IDefinition xmlListDef = project.getBuiltinType(IASLanguageConstants.BuiltinType.XMLLIST);
         return (xmlDef != null && def == xmlDef) ||
-               (xmlListDef != null && def == xmlListDef);
+                (xmlListDef != null && def == xmlListDef);
     }
     
     /**