You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/06/04 05:33:16 UTC

git commit: [flex-falcon] [refs/heads/develop] - special case array.sort() with flags. The externs are typed as taking a sortFunction so Falcon wants to generate a compile error. This code prevents that error, and for FalconJX, outputs a call to Langua

Repository: flex-falcon
Updated Branches:
  refs/heads/develop 334ca29ea -> febeb16be


special case array.sort() with flags.  The externs are typed as taking a sortFunction so Falcon wants to generate a compile error.  This code prevents that error, and for FalconJX, outputs a call to Language.sort() instead


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

Branch: refs/heads/develop
Commit: febeb16be22cf5ab2a16d178b71f3f3a48bbd8df
Parents: 334ca29
Author: Alex Harui <ah...@apache.org>
Authored: Fri Jun 3 22:33:00 2016 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Fri Jun 3 22:33:00 2016 -0700

----------------------------------------------------------------------
 .../codegen/js/jx/FunctionCallEmitter.java      | 26 +++++++++++++++
 .../internal/projects/CompilerProject.java      |  7 ++++
 .../compiler/internal/projects/FlexProject.java | 25 ++++++++++++++
 .../semantics/MethodBodySemanticChecker.java    | 35 +++++++++++---------
 .../compiler/projects/ICompilerProject.java     | 12 +++++++
 5 files changed, 89 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/febeb16b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
index 043daa8..57d8c3f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.internal.codegen.js.jx;
 import org.apache.flex.compiler.codegen.IASGlobalFunctionConstants;
 import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
@@ -164,6 +165,31 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
                             return;
             			}
             		}
+                    else if (def != null && def.getBaseName().equals("sort"))
+                	{
+                		if (def.getParent() != null &&
+                    		def.getParent().getQualifiedName().equals("Array"))
+                		{
+                			IExpressionNode args[] = node.getArgumentNodes();
+                			if (args.length > 0)
+                			{
+	                			IExpressionNode param1 = args[0];
+	                            ICompilerProject project = this.getProject();
+	                			IDefinition paramDef1 = param1.resolveType(project);
+	                			if (paramDef1.getBaseName().equals(IASLanguageConstants._int))
+	                			{
+		                            if (project instanceof FlexJSProject)
+		                                ((FlexJSProject) project).needLanguage = true;
+		                            write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+		                            write(ASEmitterTokens.MEMBER_ACCESS);
+		                            write("sort");
+		                            IContainerNode newArgs = EmitterUtils.insertArgumentsBefore(node.getArgumentsNode(), cnode);
+		                            fjs.emitArguments(newArgs);
+		                            return;
+	                			}
+                			}
+            			}
+            		}
 
                     else if (def instanceof AppliedVectorDefinition)
                     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/febeb16b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/CompilerProject.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/CompilerProject.java b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/CompilerProject.java
index bf00fa8..400a951 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/CompilerProject.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/CompilerProject.java
@@ -42,6 +42,7 @@ import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.INamespaceDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.definitions.NamespaceDefinition;
 import org.apache.flex.compiler.internal.embedding.EmbedData;
 import org.apache.flex.compiler.internal.parsing.as.IProjectConfigVariables;
@@ -1001,4 +1002,10 @@ public abstract class CompilerProject implements ICompilerProject
     {
         return (baseDefinition == overrideDefinition);
     }
+    
+    public boolean isValidTypeConversion(IASNode node, IDefinition actualDefinition, IDefinition expectedDefinition, FunctionDefinition func)
+    {
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/febeb16b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
index 6b44dd2..ee7fd5c 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
@@ -39,6 +39,7 @@ import org.apache.flex.compiler.asdoc.IASDocBundleDelegate;
 import org.apache.flex.compiler.common.DependencyTypeSet;
 import org.apache.flex.compiler.common.XMLName;
 import org.apache.flex.compiler.config.RSLSettings;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.css.ICSSManager;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
@@ -60,6 +61,7 @@ import org.apache.flex.compiler.internal.as.codegen.BindableHelper;
 import org.apache.flex.compiler.internal.css.CSSManager;
 import org.apache.flex.compiler.internal.css.codegen.CSSCompilationSession;
 import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.definitions.NamespaceDefinition;
 import org.apache.flex.compiler.internal.definitions.PackageDefinition;
 import org.apache.flex.compiler.internal.mxml.MXMLDialect;
@@ -72,6 +74,8 @@ import org.apache.flex.compiler.internal.scopes.PackageScope;
 import org.apache.flex.compiler.internal.targets.AppSWFTarget;
 import org.apache.flex.compiler.internal.targets.FlexAppSWFTarget;
 import org.apache.flex.compiler.internal.targets.SWCTarget;
+import org.apache.flex.compiler.internal.tree.as.ExpressionNodeBase;
+import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
 import org.apache.flex.compiler.internal.tree.mxml.MXMLImplicitImportNode;
 import org.apache.flex.compiler.internal.workspaces.Workspace;
 import org.apache.flex.compiler.mxml.IMXMLLanguageConstants;
@@ -83,6 +87,8 @@ import org.apache.flex.compiler.targets.ISWCTarget;
 import org.apache.flex.compiler.targets.ISWFTarget;
 import org.apache.flex.compiler.targets.ITargetProgressMonitor;
 import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IImportNode;
 import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.units.requests.IOutgoingDependenciesRequestResult;
@@ -2183,4 +2189,23 @@ public class FlexProject extends ASProject implements IFlexProject
         return false;
     }
 
+    @Override
+    public boolean isValidTypeConversion(IASNode node, IDefinition actualDefinition, IDefinition expectedDefinition, FunctionDefinition func)
+    {
+        if (actualDefinition.getBaseName().equals(IASLanguageConstants._int) &&
+                expectedDefinition.getBaseName().equals(IASLanguageConstants.Function))
+        {
+            // see if this is a call to Array.sort with sort flags
+            if (node.getParent().getNodeID() == ASTNodeID.ContainerID &&
+                node.getParent().getParent().getNodeID() == ASTNodeID.FunctionCallID)
+            {
+                if (func.getParent().getQualifiedName().equals(IASLanguageConstants.Array) &&
+                        func.getBaseName().equals("sort"))
+                {
+                    return true;                    
+                }
+            }
+        }
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/febeb16b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
index 2d1f9f1..c91fcf4 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -243,7 +243,7 @@ public class MethodBodySemanticChecker
             
             IASNode rightNode = SemanticUtils.getNthChild(iNode, 1);
        
-            checkImplicitConversion(rightNode, leftType);
+            checkImplicitConversion(rightNode, leftType, null);
             checkAssignmentValue(leftDef, rightNode);
         }
     }
@@ -280,7 +280,7 @@ public class MethodBodySemanticChecker
     {
         //  Check the assignment's type logic.
         if ( binding.getDefinition() != null )
-            checkImplicitConversion(SemanticUtils.getNthChild(iNode, 2), binding.getDefinition().resolveType(project));
+            checkImplicitConversion(SemanticUtils.getNthChild(iNode, 2), binding.getDefinition().resolveType(project), null);
     }
     
     /**
@@ -323,8 +323,8 @@ public class MethodBodySemanticChecker
             case ABCConstants.OP_bitand:
             case ABCConstants.OP_bitor:
             case ABCConstants.OP_bitxor:
-                checkImplicitConversion(left, utils.numberType());
-                checkImplicitConversion(right, utils.numberType());
+                checkImplicitConversion(left, utils.numberType(), null);
+                checkImplicitConversion(right, utils.numberType(), null);
                 break;
 
             case ABCConstants.OP_istypelate:
@@ -355,7 +355,7 @@ public class MethodBodySemanticChecker
      *  @param expected_type - the type to convert to.
      */
     
-    public void checkImplicitConversion(IASNode iNode, IDefinition expected_type)
+    public void checkImplicitConversion(IASNode iNode, IDefinition expected_type, FunctionDefinition func)
     {
         if (iNode instanceof BinaryOperatorLogicalOrNode ||
              iNode instanceof BinaryOperatorLogicalAndNode ||
@@ -364,14 +364,14 @@ public class MethodBodySemanticChecker
             // For these logical nodes, just check both sides with a recursive call.
             // Note that we need to recurse, because this may be a tree of binary logical nodes
             final IExpressionNode leftOp = ((IBinaryOperatorNode)iNode).getLeftOperandNode();
-            checkImplicitConversion(leftOp, expected_type);
+            checkImplicitConversion(leftOp, expected_type, null);
             final IExpressionNode rightOp = ((IBinaryOperatorNode)iNode).getRightOperandNode();
-            checkImplicitConversion(rightOp, expected_type);
+            checkImplicitConversion(rightOp, expected_type, null);
         }
 
         else if (iNode instanceof ExpressionNodeBase)
         {
-            checkImplicitConversion(iNode, ((ExpressionNodeBase)iNode).resolveType(project), expected_type);
+            checkImplicitConversion(iNode, ((ExpressionNodeBase)iNode).resolveType(project), expected_type, func);
         }
     }
 
@@ -541,13 +541,13 @@ public class MethodBodySemanticChecker
 
             if ( ! SemanticUtils.isValidImplicitOpAssignment(lhsType, compoundType, opcode, this.project, this.currentScope.getInInvisibleCompilationUnit()) )
             {
-                checkImplicitConversion(binop.getRightOperandNode(), lhsType);
+                checkImplicitConversion(binop.getRightOperandNode(), lhsType, null);
             }
             else if ( opcode == ABCConstants.OP_iffalse || opcode == ABCConstants.OP_iftrue )
             {
                 //  check the RHS type of a logical operation on its own;
                 //  this is rather strange behavior, but it replicates ASC's logic.
-                checkImplicitConversion(binop.getRightOperandNode(), lhsType);
+                checkImplicitConversion(binop.getRightOperandNode(), lhsType, null);
             }
         }
     }
@@ -557,10 +557,13 @@ public class MethodBodySemanticChecker
      *  @param actual_type   - the type of the expression being checked.
      *  @param expected_type - the type to convert to.
      */
-    private void checkImplicitConversion(IASNode iNode, IDefinition actual_type, IDefinition expected_type)
+    private void checkImplicitConversion(IASNode iNode, IDefinition actual_type, IDefinition expected_type, FunctionDefinition func)
     {
         if ( !SemanticUtils.isValidTypeConversion(expected_type, actual_type, this.project, this.currentScope.getInInvisibleCompilationUnit()) )
         {
+            if (project.isValidTypeConversion(iNode, actual_type, expected_type, func))
+                return;
+            
             // If we're assigning to a class, this will generate an "Illegal assignment to class" error,
             // so we don't need another error for implicit coercion
             if( !(expected_type instanceof ClassTraitsDefinition) )
@@ -761,7 +764,7 @@ public class MethodBodySemanticChecker
             for ( int i = 0; i < actuals_container.getChildCount() && i < formals.length; i++ )
             {
                 if ( !formals[i].isRest() )
-                    checkImplicitConversion( actuals_container.getChild(i), formals[i].resolveType(project) );
+                    checkImplicitConversion( actuals_container.getChild(i), formals[i].resolveType(project), func );
             }
         }
     }
@@ -1781,7 +1784,7 @@ public class MethodBodySemanticChecker
     {
         IASNode operand = ((IUnaryOperatorNode)iNode).getOperandNode();
 
-        checkImplicitConversion(operand, utils.numberType());
+        checkImplicitConversion(operand, utils.numberType(), null);
 
         IDefinition def = utils.getDefinition(operand);
         
@@ -2075,7 +2078,7 @@ public class MethodBodySemanticChecker
                 }
                 else
                 {
-                    checkImplicitConversion(returnExpression, return_type);
+                    checkImplicitConversion(returnExpression, return_type, null);
                 }
             }
             catch ( Exception namerezo_problem )
@@ -2252,7 +2255,7 @@ public class MethodBodySemanticChecker
             case ABCConstants.OP_negate:
             case ABCConstants.OP_convert_d:
             case ABCConstants.OP_bitnot:
-                checkImplicitConversion(((IUnaryOperatorNode)iNode).getOperandNode(), utils.numberType());
+                checkImplicitConversion(((IUnaryOperatorNode)iNode).getOperandNode(), utils.numberType(), null);
                 break;
         }
     }
@@ -2681,7 +2684,7 @@ public class MethodBodySemanticChecker
                         }
                     }
                 }
-                checkImplicitConversion(literal_element, type_def);
+                checkImplicitConversion(literal_element, type_def, null);
             }
         }
         return;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/febeb16b/compiler/src/main/java/org/apache/flex/compiler/projects/ICompilerProject.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/projects/ICompilerProject.java b/compiler/src/main/java/org/apache/flex/compiler/projects/ICompilerProject.java
index d4ef3ef..f7093f7 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/projects/ICompilerProject.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/projects/ICompilerProject.java
@@ -27,12 +27,14 @@ import org.apache.flex.compiler.common.DependencyTypeSet;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.scopes.ASScope;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.scopes.IASScope;
 import org.apache.flex.compiler.targets.ISWFTarget;
 import org.apache.flex.compiler.targets.ITargetProgressMonitor;
 import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.workspaces.IWorkspace;
 
@@ -229,4 +231,14 @@ public interface ICompilerProject
      * @return True if compatible (default is if they are the same)
      */
     boolean isCompatibleOverrideReturnType(ITypeDefinition overrideDefinition, ITypeDefinition baseDefinition);
+    
+    /**
+     * @param node The node being converted.
+     * @param actualDefinition The actual definition.  
+     * @param expectedDefinition The expected definition.
+     * @param func The function being called.
+     * @return True if valid
+     */
+    boolean isValidTypeConversion(IASNode node, IDefinition actualDefinition, IDefinition expectedDefinition, FunctionDefinition func);
+
 }