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/03/08 09:18:53 UTC

[royale-compiler] 01/03: allow override to be specified in a separate conditional compilation block to ease writing multi-platform AS

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 f765ce6e5b2e2decdc12f01b0db788cb5d6bf656
Author: Alex Harui <ah...@apache.org>
AuthorDate: Wed Mar 7 13:03:47 2018 -0800

    allow override to be specified in a separate conditional compilation block to ease writing multi-platform AS
---
 .../internal/as/codegen/ABCGeneratingReducer.java  | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/ABCGeneratingReducer.java b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/ABCGeneratingReducer.java
index 2d5e5e6..cbfba57 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/ABCGeneratingReducer.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/ABCGeneratingReducer.java
@@ -71,6 +71,7 @@ import org.apache.royale.compiler.problems.UnknownBreakTargetProblem;
 import org.apache.royale.compiler.problems.UnknownContinueTargetProblem;
 import org.apache.royale.compiler.problems.VoidTypeProblem;
 import org.apache.royale.compiler.projects.ICompilerProject;
+import org.apache.royale.compiler.tree.ASTNodeID;
 import org.apache.royale.compiler.tree.as.IASNode;
 import org.apache.royale.compiler.tree.as.IDynamicAccessNode;
 import org.apache.royale.compiler.tree.as.IBinaryOperatorNode;
@@ -6701,6 +6702,54 @@ public class ABCGeneratingReducer
 
     public InstructionList transform_name_to_expression(IASNode iNode, Binding name)
     {
+    	// hack to allow override as a separate keyword in a conditional compile block.
+    	// the AST thinks it is a property on the class named override.
+    	// This allows less coding when in SWF the base class has a method that needs
+    	// overriding but the JS base class does not.  Instead of writing
+    	// COMPILE::SWF
+    	// override public function foo() {
+    	//   method body
+    	// }
+    	// COMPILE::JS
+    	// public function foo() {
+    	//   an exact copy of method body
+    	// }
+    	// we want to allow:
+    	// COMPILE::SWF { override }
+        // public function foo() {
+    	//   method body
+    	// }
+    	if (iNode.getNodeID() == ASTNodeID.IdentifierID)
+    	{
+    		IdentifierNode node = (IdentifierNode)iNode;
+    		if (node.getName().equals("override"))
+    		{
+    			IASNode parent = node.getParent();
+    			if (parent.getNodeID() == ASTNodeID.ConfigBlockID)
+    			{
+    				IASNode parentOfMethods = parent.getParent();
+    				int functionCount = parentOfMethods.getChildCount();
+    				for (int i = 0; i < functionCount; i++)
+    				{
+    					IASNode child = parentOfMethods.getChild(i);
+    					if (child == parent)
+    					{
+    						// examine the next node
+    						child = parentOfMethods.getChild(i + 1);
+    						if (child instanceof IFunctionNode)
+    						{
+    							// convince the compiler that this is now an override
+    							IFunctionNode fnode = (IFunctionNode)child;
+    							FunctionDefinition fdef = (FunctionDefinition)fnode.getDefinition();
+    							fdef.setOverride();
+    							// return no instructions
+    							return new InstructionList();
+    						}    						
+    					}
+    				}
+    			}
+    		}
+    	}
         return generateAccess(name, determineAccessType(iNode));
     }
 

-- 
To stop receiving notification emails like this one, please contact
aharui@apache.org.