royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-compiler] 01/03: allow/ignore some errors because the transpiler will generate some other code
Date Wed, 08 Aug 2018 17:39:21 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

commit 55bc913bef7c100d33ca898bb59925865128a501
Author: Alex Harui <aharui@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));
         }
 


Mime
View raw message