You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/08/08 17:39:20 UTC

[royale-compiler] branch develop updated (894460f -> f60899d)

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

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


    from 894460f  Fixed indent
     new 55bc913  allow/ignore some errors because the transpiler will generate some other code
     new c9f54f9  allow substitutions in method visibility
     new f60899d  handle simple XML expressions.  Sometimes we don't get an XMLLiteralNode, just a plain LiteralNode.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../royale/compiler/projects/ICompilerProject.java |  10 ++
 .../internal/codegen/js/jx/LiteralEmitter.java     | 124 +++++++++++----------
 .../royale/compiler/internal/parsing/as/ASParser.g |  26 +++++
 .../internal/parsing/as/ConfigProcessor.java       |  10 ++
 .../internal/projects/CompilerProject.java         |   4 +
 .../compiler/internal/projects/RoyaleProject.java  |  18 +++
 .../semantics/MethodBodySemanticChecker.java       |   2 +
 7 files changed, 138 insertions(+), 56 deletions(-)


[royale-compiler] 03/03: handle simple XML expressions. Sometimes we don't get an XMLLiteralNode, just a plain LiteralNode.

Posted by ah...@apache.org.
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

commit f60899dbd4c81fbef43769a3977f09d636f6bafe
Author: Alex Harui <ah...@apache.org>
AuthorDate: Wed Aug 8 10:39:01 2018 -0700

    handle simple XML expressions.  Sometimes we don't get an XMLLiteralNode, just a plain LiteralNode.
---
 .../internal/codegen/js/jx/LiteralEmitter.java     | 124 +++++++++++----------
 1 file changed, 68 insertions(+), 56 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 467e587..6c79341 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -75,67 +75,79 @@ public class LiteralEmitter extends JSSubEmitter implements
                         }
                     }
                 }
-                XMLLiteralNode xmlNode = (XMLLiteralNode) node;
-                if (jsx)
+                if (node instanceof XMLLiteralNode)
                 {
-                    emitJSX(xmlNode);
-                    return;
+                    XMLLiteralNode xmlNode = (XMLLiteralNode) node;
+	                if (jsx)
+	                {
+	                    emitJSX(xmlNode);
+	                    return;
+	                }
+	                else
+	                {
+	                    newlineReplacement = "\\\\\n";
+	                    if (xmlNode.getContentsNode().getChildCount() == 1)
+	                    {
+	                        if (s.contains("'"))
+	                            s = "\"" + s + "\"";
+	                        else
+	                            s = "'" + s + "'";
+	                    }
+	                    else
+	                    {
+	                        StringBuilder sb = new StringBuilder();
+	                        // probably contains {initializers}
+	                        boolean inAttribute = false;
+	                        int n = xmlNode.getContentsNode().getChildCount();
+	                        for (int i = 0; i < n; i++)
+	                        {
+	                            if (i > 0)
+	                                sb.append(" + ");
+	                            IASNode child = xmlNode.getContentsNode().getChild(i);
+	                            if (child instanceof LiteralNode)
+	                            {
+	                                s = ((LiteralNode)child).getValue(true);
+	                                if (s.contains("'"))
+	                                    sb.append("\"" + s + "\"");
+	                                else
+	                                    sb.append("'" + s + "'");
+	                            }
+	                            else
+	                            {
+	                                s = getEmitter().stringifyNode(child);
+	                                if (inAttribute)
+	                                {
+	                                    sb.append("'\"' + ");
+	
+	                                    sb.append(s);
+	
+	                                    sb.append(" + '\"'");
+	                                }
+	                                else
+	                                    sb.append(s);
+	                            }
+	                            inAttribute = s.endsWith("=");
+	                        }
+	                        s = sb.toString();
+	                    }
+	                    char c = s.charAt(0);
+	                    if (c == '"')
+	                    {
+	                        s = s.substring(1, s.length() - 1);
+	                        s = s.replace("\"", "__QUOTE_PLACEHOLDER__");
+	                        s = "\"" + s + "\"";
+	                    }
+	                    // use formatQualifiedName to get XML in the usedNames dependencies
+	                    s = "new " + getEmitter().formatQualifiedName("XML") + "( " + s + ")";
+	                }
                 }
                 else
                 {
-                    newlineReplacement = "\\\\\n";
-                    if (xmlNode.getContentsNode().getChildCount() == 1)
-                    {
-                        if (s.contains("'"))
-                            s = "\"" + s + "\"";
-                        else
-                            s = "'" + s + "'";
-                    }
-                    else
-                    {
-                        StringBuilder sb = new StringBuilder();
-                        // probably contains {initializers}
-                        boolean inAttribute = false;
-                        int n = xmlNode.getContentsNode().getChildCount();
-                        for (int i = 0; i < n; i++)
-                        {
-                            if (i > 0)
-                                sb.append(" + ");
-                            IASNode child = xmlNode.getContentsNode().getChild(i);
-                            if (child instanceof LiteralNode)
-                            {
-                                s = ((LiteralNode)child).getValue(true);
-                                if (s.contains("'"))
-                                    sb.append("\"" + s + "\"");
-                                else
-                                    sb.append("'" + s + "'");
-                            }
-                            else
-                            {
-                                s = getEmitter().stringifyNode(child);
-                                if (inAttribute)
-                                {
-                                    sb.append("'\"' + ");
-
-                                    sb.append(s);
-
-                                    sb.append(" + '\"'");
-                                }
-                                else
-                                    sb.append(s);
-                            }
-                            inAttribute = s.endsWith("=");
-                        }
-                        s = sb.toString();
-                    }
-                    char c = s.charAt(0);
-                    if (c == '"')
-                    {
-                        s = s.substring(1, s.length() - 1);
-                        s = s.replace("\"", "__QUOTE_PLACEHOLDER__");
+                	s = node.getValue();
+                    if (s.contains("'"))
                         s = "\"" + s + "\"";
-                    }
-                    // use formatQualifiedName to get XML in the usedNames dependencies
+                    else
+                        s = "'" + s + "'";
                     s = "new " + getEmitter().formatQualifiedName("XML") + "( " + s + ")";
                 }
             }


[royale-compiler] 01/03: allow/ignore some errors because the transpiler will generate some other code

Posted by ah...@apache.org.
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

commit 55bc913bef7c100d33ca898bb59925865128a501
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Aug 7 21:54:16 2018 -0700

    allow/ignore some errors because the transpiler will generate some other code
---
 .../royale/compiler/projects/ICompilerProject.java     | 10 ++++++++++
 .../compiler/internal/projects/CompilerProject.java    |  4 ++++
 .../compiler/internal/projects/RoyaleProject.java      | 18 ++++++++++++++++++
 .../internal/semantics/MethodBodySemanticChecker.java  |  2 ++
 4 files changed, 34 insertions(+)

diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
index 62fc5fb..85fc156 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
@@ -252,4 +252,14 @@ public interface ICompilerProject
 			IFunctionDefinition functionDefinition, ITypeDefinition type1,
 			ITypeDefinition type2, int i);
 
+    /**
+     * @param functionDefinition 
+     * @param formalCount The number of formal parameters.  
+     * @param actualCount The number of actual parameters used in the call.
+     * @return True if parameter count mismatch is allowed (because the transpiler will generate different code);
+     */
+	boolean isParameterCountMismatchAllowed(
+			IFunctionDefinition functionDefinition, int formalCount,
+			int actualCount);
+
 }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/CompilerProject.java b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/CompilerProject.java
index a7af708..88b42e6 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/CompilerProject.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/CompilerProject.java
@@ -1014,4 +1014,8 @@ public abstract class CompilerProject implements ICompilerProject
         return (baseDefinition == overrideDefinition);
 	}
 
+	public boolean isParameterCountMismatchAllowed(IFunctionDefinition func,
+			int formalCount, int actualCount) {
+        return false;
+	}
 }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
index 4a893d4..55f336d 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
@@ -1792,6 +1792,8 @@ public class RoyaleProject extends ASProject implements IRoyaleProject, ICompile
         return actionScriptFileEncoding;
     }
 
+    private boolean isTranspiling;
+    
     @Override
     public void setDefineDirectives(Map<String, String> defines)
     {
@@ -1799,6 +1801,10 @@ public class RoyaleProject extends ASProject implements IRoyaleProject, ICompile
         // TODO: This seems strange. Each call to the setter
         // adds new defines. How do you get rid of the old ones?
         addConfigVariables(defines);
+        if (defines.containsKey("COMPILE::SWF"))
+        {
+        	isTranspiling = defines.get("COMPILE::SWF").equalsIgnoreCase("false");
+        }
         clean();
     }
 
@@ -2471,4 +2477,16 @@ public class RoyaleProject extends ASProject implements IRoyaleProject, ICompile
 			}
 		}
 	}
+	
+	@Override
+	public boolean isParameterCountMismatchAllowed(IFunctionDefinition func,
+			int formalCount, int actualCount) {
+		if (!isTranspiling) return false;
+		if (func.getBaseName().equals("sort") &&
+				func.getParent().getQualifiedName().equals("Array") &&
+				formalCount == 1 && actualCount == 2)
+			return true;
+        return false;
+	}
+
 }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
index 1ed40b6..6663afc 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -742,6 +742,8 @@ public class MethodBodySemanticChecker
 
         if ( actuals.size() > formals.length && !last_is_rest )
         {
+        	if (project.isParameterCountMismatchAllowed(func, formals.length, actuals.size()))
+        		return;
             addProblem(new TooManyFunctionParametersProblem(iNode, formals.length));
         }
 


[royale-compiler] 02/03: allow substitutions in method visibility

Posted by ah...@apache.org.
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

commit c9f54f91a69829e9a2364e65c0965dec0200ec61
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Aug 7 21:54:36 2018 -0700

    allow substitutions in method visibility
---
 .../royale/compiler/internal/parsing/as/ASParser.g | 26 ++++++++++++++++++++++
 .../internal/parsing/as/ConfigProcessor.java       | 10 +++++++++
 2 files changed, 36 insertions(+)

diff --git a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
index 6a7ac9c..c9b1528 100644
--- a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
+++ b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
@@ -222,6 +222,7 @@ attributedDefinition[ContainerNode c]
 attribute [List<ModifierNode> modifiers, List<INamespaceDecorationNode> namespaceAttributes] 
 {
     ExpressionNodeBase namespaceNode = null; 
+    ExpressionNodeBase configAsNamespaceNode = null; 
     ModifierNode modifierNode = null;
 }
     :   modifierNode=modifierAttribute
@@ -234,8 +235,33 @@ attribute [List<ModifierNode> modifiers, List<INamespaceDecorationNode> namespac
             if (namespaceNode instanceof INamespaceDecorationNode)
                 namespaceAttributes.add((INamespaceDecorationNode) namespaceNode); 
         }
+    |   configAsNamespaceNode=configConditionAsNamespaceModifier
+        {
+            if (configAsNamespaceNode instanceof INamespaceDecorationNode)
+                namespaceAttributes.add((INamespaceDecorationNode) configAsNamespaceNode); 
+        }
     ;
 	
+configConditionAsNamespaceModifier returns [ExpressionNodeBase n]
+{
+    n = null; 
+}
+    :   ns:TOKEN_NAMESPACE_NAME op:TOKEN_OPERATOR_NS_QUALIFIER id:TOKEN_NAMESPACE_ANNOTATION
+        { final NamespaceIdentifierNode nsNode = new NamespaceIdentifierNode((ASToken)ns); 
+          nsNode.setIsConfigNamespace(isConfigNamespace(nsNode));
+	  final IdentifierNode idNode = new IdentifierNode((ASToken)id);
+	  final IdentifierNode idNode2 = (IdentifierNode)transformToNSAccessExpression(nsNode, (ASToken) op, idNode);
+          n = new NamespaceIdentifierNode(idNode2.getName());
+          n = n.copyForInitializer(null);
+	  n.setSourcePath(nsNode.getSourcePath());
+	  n.setLine(nsNode.getLine());
+	  n.setColumn(nsNode.getColumn());
+	  n.setEndLine(idNode.getEndLine());
+	  n.setEndColumn(idNode.getEndColumn());
+	  n.setStart(nsNode.getStart());
+	  n.setEnd(idNode.getEnd());
+        }
+    ;
 	
 /**
  * Matches a definition of variable, function, namespace, class or interface.
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
index 2cef61d..5966459 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
@@ -29,6 +29,7 @@ import java.util.List;
 import antlr.Token;
 
 import org.apache.royale.abc.ABCConstants;
+import org.apache.royale.abc.semantics.Namespace;
 import org.apache.royale.compiler.constants.IASLanguageConstants;
 import org.apache.royale.compiler.definitions.IDefinition;
 import org.apache.royale.compiler.internal.definitions.ConstantDefinition;
@@ -511,6 +512,15 @@ public class ConfigProcessor
         	IdentifierNode id = (IdentifierNode)result;
         	return id;
         }
+        else if (result instanceof Namespace)
+        {
+        	Namespace ns = (Namespace)result;
+        	String nsName = ns.getName();
+        	if (nsName.length() == 0)
+        		nsName = "public";
+        	
+        	return new IdentifierNode(nsName);
+        }
         return null;
     }