flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [4/5] git commit: [flex-falcon] [refs/heads/develop] - parameter overriding/overloading
Date Mon, 05 Dec 2016 18:16:12 GMT
parameter overriding/overloading


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

Branch: refs/heads/develop
Commit: deb47fc800dcf6e08f3304af9f3acbe9febc8c61
Parents: 05054cf
Author: Alex Harui <aharui@apache.org>
Authored: Fri Dec 2 12:08:44 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Dec 5 09:12:17 2016 -0800

----------------------------------------------------------------------
 .../constants/IMetaAttributeConstants.java      |  1 +
 .../definitions/FunctionDefinition.java         |  5 +-
 .../internal/projects/CompilerProject.java      |  6 ++
 .../compiler/internal/projects/FlexProject.java | 39 +++++++++++++
 .../compiler/internal/targets/SWFTarget.java    | 60 ++++++++++++++++++++
 .../compiler/projects/ICompilerProject.java     | 11 ++++
 6 files changed, 121 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/compiler/src/main/java/org/apache/flex/compiler/constants/IMetaAttributeConstants.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/constants/IMetaAttributeConstants.java
b/compiler/src/main/java/org/apache/flex/compiler/constants/IMetaAttributeConstants.java
index 3d7913b..b30948c 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/constants/IMetaAttributeConstants.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/constants/IMetaAttributeConstants.java
@@ -199,6 +199,7 @@ public interface IMetaAttributeConstants
 	// [SWFOverride]
     static final String ATTRIBUTE_SWFOVERRIDE = "SWFOverride";
     static final String NAME_SWFOVERRIDE_RETURNS = "returns";
+    static final String NAME_SWFOVERRIDE_PARAMS = "params";
     
 	// [VisualContentHolder]
     static final String ATTRIBUTE_VISUALCONTENTHOLDER = "VisualContentHolder";

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/compiler/src/main/java/org/apache/flex/compiler/internal/definitions/FunctionDefinition.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/definitions/FunctionDefinition.java
b/compiler/src/main/java/org/apache/flex/compiler/internal/definitions/FunctionDefinition.java
index b99c44e..0106213 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/definitions/FunctionDefinition.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/definitions/FunctionDefinition.java
@@ -479,7 +479,10 @@ public class FunctionDefinition extends ScopedDefinitionBase implements
IFunctio
             ITypeDefinition type1 = param1.resolveType(project);
             ITypeDefinition type2 = param2.resolveType(project);
             if (type1 != type2)
-                return false;
+            {
+                if (!project.isCompatibleOverrideParameterType(this, type1, type2, i))
+                    return false;
+            }
 
             // Compare ith parameter 'rest' flag.
             boolean rest1 = param1.isRest();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/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 328915e..8176060 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
@@ -1009,4 +1009,10 @@ public abstract class CompilerProject implements ICompilerProject
         return false;
     }
 
+	public boolean isCompatibleOverrideParameterType(IFunctionDefinition func,
+			ITypeDefinition overrideDefinition, ITypeDefinition baseDefinition,
+			int i) {
+        return (baseDefinition == overrideDefinition);
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/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 16246c9..602de21 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
@@ -2229,6 +2229,44 @@ public class FlexProject extends ASProject implements IFlexProject
     }
 
     @Override
+	public boolean isCompatibleOverrideParameterType(
+			IFunctionDefinition func, ITypeDefinition overrideDefinition,
+			ITypeDefinition baseDefinition, int i)
+    {
+        if (baseDefinition == overrideDefinition)
+            return true;
+        if (targetSettings != null && targetSettings.getAllowSubclassOverrides()
&& overrideDefinition != null && baseDefinition != null)
+        {
+        	if (overrideDefinition.isInstanceOf(baseDefinition.getQualifiedName(), this))
+        		return true;
+    		FunctionDefinition f = (FunctionDefinition)func;
+    		IMetaTag[] metas = f.getAllMetaTags();
+    		for (IMetaTag meta : metas)
+    		{
+    			if (meta.getTagName().equals(IMetaAttributeConstants.ATTRIBUTE_SWFOVERRIDE))
+    			{
+    				IMetaTagAttribute attr = meta.getAttribute(IMetaAttributeConstants.NAME_SWFOVERRIDE_PARAMS);
+    				if (attr != null)
+    				{
+    					String paramList = attr.getValue();
+    					String[] parts;
+    					if (paramList.contains(","))
+    						parts = paramList.split(",");
+    					else
+    					{
+    						parts = new String[1];
+    						parts[0] = paramList;
+    					}
+    					if (parts[i].equals(baseDefinition.getQualifiedName()))
+    						return true;
+    				}
+    			}
+        	}
+        }
+        return false;
+    }
+
+    @Override
     public boolean isValidTypeConversion(IASNode node, IDefinition actualDefinition, IDefinition
expectedDefinition, FunctionDefinition func)
     {
         if (actualDefinition.getBaseName().equals(IASLanguageConstants._int) &&
@@ -2247,4 +2285,5 @@ public class FlexProject extends ASProject implements IFlexProject
         }
         return false;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/compiler/src/main/java/org/apache/flex/compiler/internal/targets/SWFTarget.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/targets/SWFTarget.java
b/compiler/src/main/java/org/apache/flex/compiler/internal/targets/SWFTarget.java
index 832c116..56df579 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/targets/SWFTarget.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/targets/SWFTarget.java
@@ -495,6 +495,66 @@ public abstract class SWFTarget extends Target implements ISWFTarget
                                             				break metas;
                                         				}
                                         			}
+                                        			else if (keys[i].equals(IMetaAttributeConstants.NAME_SWFOVERRIDE_PARAMS))
+                                        			{
+                                        				String paramList = meta.getValues()[i];
+                                    					String[] parts;
+                                    					if (paramList.contains(","))
+                                    						parts = paramList.split(",");
+                                    					else
+                                    					{
+                                    						parts = new String[1];
+                                    						parts[0] = paramList;
+                                    					}
+                                    					Vector<Name> newList = new Vector<Name>();
+                                    					for (String part : parts)
+                                    					{
+	                                        				int c = part.lastIndexOf(".");
+	                                        				String packageName = "";
+	                                        				String baseName = part;
+	                                        				if (c != -1)
+	                                        				{
+	                                        					packageName = part.substring(0, c);
+	                                        					baseName = part.substring(c + 1);
+	                                        				}
+	                                        				
+	                                        				Pool<Name> namePool = emitter.getNamePool();
+	                                        				List<Name> nameList = namePool.getValues();
+	                                        				boolean foundName = false;
+	                                        				for (Name name : nameList)
+	                                        				{
+	                                        					String base = name.getBaseName();
+	                                        					if (base == null) continue;
+	                                        					Namespace ns = name.getSingleQualifier();
+	                                        					if (ns == null) continue;
+	                                        					String nsName = ns.getName();
+	                                        					if (nsName == null) continue;
+	                                        					if (base.equals(baseName) &&
+	                                        							nsName.equals(packageName))
+	                                        					{
+	                                        						newList.add(name);
+	                                                				foundName = true;
+	                                                				changedABC = true;
+	                                                				break;
+	                                        					}
+	                                        				}
+	                                        				if (!foundName)
+	                                        				{
+	                                            				Pool<String> stringPool = emitter.getStringPool();
+	                                            				stringPool.add(packageName);// theoretically,
it won't be added if already there
+	                                            				stringPool.add(baseName);	// theoretically,
it won't be added if already there
+	                                        					Namespace ns = new Namespace(ABCConstants.CONSTANT_PackageNs,
packageName);
+	                                        					Pool<Namespace> nsPool = emitter.getNamespacePool();
+	                                        					nsPool.add(ns);
+	                                        					Name name = new Name(ns, baseName);
+	                                        					namePool.add(name);
+	                                        					newList.add(name);
+	                                        					changedABC = true;
+	                                        				}
+	                                        			}
+                                    					method.setParamTypes(newList);
+                                    					break metas;
+                                        			}
                                         		}
                                         	}
                                         }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/deb47fc8/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 91bfea8..abe9588 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
@@ -243,4 +243,15 @@ public interface ICompilerProject
      */
     boolean isValidTypeConversion(IASNode node, IDefinition actualDefinition, IDefinition
expectedDefinition, FunctionDefinition func);
 
+    /**
+     * @param functionDefinition 
+     * @param overrideDefinition The definition overriding the base definition.  
+     * @param baseDefinition The definition being overridden.
+     * @param zero-based index of parameter in list  
+     * @return True if compatible (default is if they are the same)
+     */
+	boolean isCompatibleOverrideParameterType(
+			IFunctionDefinition functionDefinition, ITypeDefinition type1,
+			ITypeDefinition type2, int i);
+
 }


Mime
View raw message