flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [3/3] git commit: [flex-falcon] [refs/heads/develop] - handle memberaccess instead of identifier in param list
Date Fri, 21 Aug 2015 14:18:55 GMT
handle memberaccess instead of identifier in param list


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

Branch: refs/heads/develop
Commit: 1f9b06b4d32a4fe6fc82127a1cc858bb85a0082b
Parents: 16ed07e
Author: Alex Harui <aharui@apache.org>
Authored: Fri Aug 21 07:14:28 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Aug 21 07:14:28 2015 -0700

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSExpressions.java        |  10 +
 .../codegen/js/flexjs/JSFlexJSEmitter.java      |  20 ++
 .../codegen/js/jx/MemberAccessEmitter.java      | 182 +++++++++++--------
 3 files changed, 138 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f9b06b4/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index eea2525..daee543 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -666,6 +666,16 @@ public class TestFlexJSExpressions extends TestGoogExpressions
     }
     
     @Test
+    public void testThisMethodAsParam()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {public function b() { function c(f:Function):void {}; c(this.b);
}}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  org.apache.flex.utils.Language.closure(c, this, 'c')(org.apache.flex.utils.Language.closure(this.b,
this, 'b'));\n}");
+    }
+    
+    @Test
     public void testNativeGetter()
     {
         IFunctionNode node = (IFunctionNode) getNode(

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f9b06b4/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index 0d451d9..2dcb1ef 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -48,6 +48,9 @@ import org.apache.flex.compiler.internal.codegen.js.jx.PackageHeaderEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.SelfReferenceEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.SuperCallEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.VarDeclarationEmitter;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
@@ -408,6 +411,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
 	public void emitClosureStart()
     {
+        ICompilerProject project = getWalker().getProject();;
+        if (project instanceof FlexJSProject)
+        	((FlexJSProject)project).needLanguage = true;
         write(JSFlexJSEmitterTokens.CLOSURE_FUNCTION_NAME);
         write(ASEmitterTokens.PAREN_OPEN);
     }
@@ -420,9 +426,23 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     	write(ASEmitterTokens.SINGLE_QUOTE);
     	if (node.getNodeID() == ASTNodeID.IdentifierID)
     		write(((IIdentifierNode)node).getName());
+    	else if (node.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+    		writeChainName(node);
     	else
     		System.out.println("unexpected node in emitClosureEnd");
     	write(ASEmitterTokens.SINGLE_QUOTE);
         write(ASEmitterTokens.PAREN_CLOSE);
     }
+    
+    private void writeChainName(IASNode node)
+    {
+    	while (node.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+    	{    		
+    		node = ((IMemberAccessExpressionNode)node).getRightOperandNode();
+    	}
+    	if (node.getNodeID() == ASTNodeID.IdentifierID)
+    		write(((IdentifierNode)node).getName());
+    	else
+    		System.out.println("unexpected node in emitClosureEnd");
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f9b06b4/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
index 311c126..d0ac2a4 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.GetterNode;
 import org.apache.flex.compiler.internal.tree.as.UnaryOperatorAtNode;
@@ -60,91 +61,124 @@ public class MemberAccessEmitter extends JSSubEmitter implements
         boolean isStatic = false;
         if (def != null && def.isStatic())
             isStatic = true;
+        boolean needClosure = false;
+        if (def instanceof FunctionDefinition && (!(def instanceof AccessorDefinition)))
+        {
+        	IASNode parentNode = node.getParent();
+        	if (parentNode != null)
+        	{
+				ASTNodeID parentNodeId = parentNode.getNodeID();
+				// we need a closure if this MAE is the top-level in a chain
+				// of MAE and not in a function call.
+				needClosure = parentNodeId != ASTNodeID.FunctionCallID &&
+							parentNodeId != ASTNodeID.MemberAccessExpressionID;
+        		
+        	}
+        }
 
         boolean continueWalk = true;
         if (!isStatic)
         {
-            if (!(leftNode instanceof ILanguageIdentifierNode && ((ILanguageIdentifierNode)
leftNode)
-                    .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
-            {
-                IDefinition rightDef = null;
-                if (rightNode instanceof IIdentifierNode)
-                    rightDef = ((IIdentifierNode) rightNode)
-                            .resolve(getProject());
-
-                if (rightNode instanceof UnaryOperatorAtNode)
-                {
-                    // ToDo (erikdebruin): properly handle E4X
-
-                    write(ASEmitterTokens.THIS);
-                    write(ASEmitterTokens.MEMBER_ACCESS);
-                    getWalker().walk(node.getLeftOperandNode());
-                    write(ASEmitterTokens.SQUARE_OPEN);
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    write("E4XOperator");
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    write(ASEmitterTokens.SQUARE_CLOSE);
-                    continueWalk = false;
-                }
-                else if (node.getNodeID() == ASTNodeID.Op_DescendantsID)
-                {
-                    // ToDo (erikdebruin): properly handle E4X
-
-                    write(ASEmitterTokens.THIS);
-                    write(ASEmitterTokens.MEMBER_ACCESS);
-                    getWalker().walk(node.getLeftOperandNode());
-                    write(ASEmitterTokens.SQUARE_OPEN);
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    write("E4XSelector");
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    write(ASEmitterTokens.SQUARE_CLOSE);
-                    continueWalk = false;
-                }
-                else if (leftNode.getNodeID() != ASTNodeID.SuperID)
-                {
-                    getWalker().walk(node.getLeftOperandNode());
-                    write(node.getOperator().getOperatorText());
-                }
-                else if (leftNode.getNodeID() == ASTNodeID.SuperID
-                        && (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef
!= null && rightDef instanceof AccessorDefinition)))
-                {
-                    ICompilerProject project = this.getProject();
-                    if (project instanceof FlexJSProject)
-                    	((FlexJSProject)project).needLanguage = true;
-                    // setter is handled in binaryOperator
-                    write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
-                    write(ASEmitterTokens.MEMBER_ACCESS);
-                    write(JSFlexJSEmitterTokens.SUPERGETTER);
-                    write(ASEmitterTokens.PAREN_OPEN);
-                    IClassNode cnode = (IClassNode) node
-                            .getAncestorOfType(IClassNode.class);
-                    write(getEmitter().formatQualifiedName(
-                            cnode.getQualifiedName()));
-                    writeToken(ASEmitterTokens.COMMA);
-                    write(ASEmitterTokens.THIS);
-                    writeToken(ASEmitterTokens.COMMA);
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    if (rightDef != null)
-                        write(rightDef.getBaseName());
-                    else
-                        write(((GetterNode) rightNode).getName());
-                    write(ASEmitterTokens.SINGLE_QUOTE);
-                    write(ASEmitterTokens.PAREN_CLOSE);
-                    continueWalk = false;
-                }
-            }
-            else
-            {
-                write(ASEmitterTokens.THIS);
+        	if (needClosure)
+        		getEmitter().emitClosureStart();
+        	
+        	continueWalk = writeLeftSide(node, leftNode, rightNode);
+            if (continueWalk)
                 write(node.getOperator().getOperatorText());
-            }
         }
 
         if (continueWalk)
+        {
             getWalker().walk(node.getRightOperandNode());
-
+        }
+        
+        if (needClosure)
+        {
+        	write(ASEmitterTokens.COMMA);
+        	write(ASEmitterTokens.SPACE);
+        	writeLeftSide(node, leftNode, rightNode);
+        	getEmitter().emitClosureEnd(node);
+        }
+        
         if (ASNodeUtils.hasParenClose(node))
             write(ASEmitterTokens.PAREN_CLOSE);
     }
 
+    private boolean writeLeftSide(IMemberAccessExpressionNode node, IASNode leftNode, IASNode
rightNode)
+    {
+        if (!(leftNode instanceof ILanguageIdentifierNode && ((ILanguageIdentifierNode)
leftNode)
+                .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
+        {
+            IDefinition rightDef = null;
+            if (rightNode instanceof IIdentifierNode)
+                rightDef = ((IIdentifierNode) rightNode)
+                        .resolve(getProject());
+
+            if (rightNode instanceof UnaryOperatorAtNode)
+            {
+                // ToDo (erikdebruin): properly handle E4X
+
+                write(ASEmitterTokens.THIS);
+                write(ASEmitterTokens.MEMBER_ACCESS);
+                getWalker().walk(node.getLeftOperandNode());
+                write(ASEmitterTokens.SQUARE_OPEN);
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                write("E4XOperator");
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                write(ASEmitterTokens.SQUARE_CLOSE);
+                return false;
+            }
+            else if (node.getNodeID() == ASTNodeID.Op_DescendantsID)
+            {
+                // ToDo (erikdebruin): properly handle E4X
+
+                write(ASEmitterTokens.THIS);
+                write(ASEmitterTokens.MEMBER_ACCESS);
+                getWalker().walk(node.getLeftOperandNode());
+                write(ASEmitterTokens.SQUARE_OPEN);
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                write("E4XSelector");
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                write(ASEmitterTokens.SQUARE_CLOSE);
+                return false;
+            }
+            else if (leftNode.getNodeID() != ASTNodeID.SuperID)
+            {
+                getWalker().walk(node.getLeftOperandNode());
+            }
+            else if (leftNode.getNodeID() == ASTNodeID.SuperID
+                    && (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef
!= null && rightDef instanceof AccessorDefinition)))
+            {
+                ICompilerProject project = this.getProject();
+                if (project instanceof FlexJSProject)
+                	((FlexJSProject)project).needLanguage = true;
+                // setter is handled in binaryOperator
+                write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+                write(ASEmitterTokens.MEMBER_ACCESS);
+                write(JSFlexJSEmitterTokens.SUPERGETTER);
+                write(ASEmitterTokens.PAREN_OPEN);
+                IClassNode cnode = (IClassNode) node
+                        .getAncestorOfType(IClassNode.class);
+                write(getEmitter().formatQualifiedName(
+                        cnode.getQualifiedName()));
+                writeToken(ASEmitterTokens.COMMA);
+                write(ASEmitterTokens.THIS);
+                writeToken(ASEmitterTokens.COMMA);
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                if (rightDef != null)
+                    write(rightDef.getBaseName());
+                else
+                    write(((GetterNode) rightNode).getName());
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                write(ASEmitterTokens.PAREN_CLOSE);
+                return false;
+            }
+        }
+        else
+        {
+            write(ASEmitterTokens.THIS);
+        }
+        return true;
+    }
+    	
 }


Mime
View raw message