flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [6/7] git commit: [flex-falcon] [refs/heads/develop] - try to only emit 'self' when anonymous functions are in a function
Date Tue, 23 Dec 2014 07:40:52 GMT
try to only emit 'self' when anonymous functions are in a function


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

Branch: refs/heads/develop
Commit: 8144acb965a0f7a1ca358b68065ac6eb0bb47a06
Parents: 5c41aef
Author: Alex Harui <aharui@apache.org>
Authored: Mon Dec 22 10:59:23 2014 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Dec 22 10:59:23 2014 -0800

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java       | 12 +++++++++++-
 .../compiler/internal/tree/as/FunctionNode.java  | 19 +++++++++++++++++++
 .../internal/tree/as/FunctionObjectNode.java     |  5 +++++
 .../flex/compiler/tree/as/IFunctionNode.java     | 10 ++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8144acb9/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 e7f69c8..2a970c3 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
@@ -80,6 +80,7 @@ import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IForLoopNode;
 import org.apache.flex.compiler.tree.as.IFunctionCallNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
@@ -555,6 +556,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     protected void emitSelfReference(IFunctionNode node)
     {
         // we don't want 'var self = this;' in FlexJS
+    	// unless there are anonymous functions
+    	if (node.containsAnonymousFunctions())
+    		super.emitSelfReference(node);
     }
 
     private boolean writeThis(IIdentifierNode node)
@@ -723,7 +727,13 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
 
             if (writeThis(node))
             {
-                write(ASEmitterTokens.THIS);
+                IFunctionObjectNode functionObjectNode = (IFunctionObjectNode) node.getParent()
+                		.getAncestorOfType(IFunctionObjectNode.class);
+
+                if (functionObjectNode != null)
+                	write(JSGoogEmitterTokens.SELF);
+                else
+                	write(ASEmitterTokens.THIS);
 
                 write(ASEmitterTokens.MEMBER_ACCESS);
             }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8144acb9/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionNode.java b/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionNode.java
index 90d7960..af63395 100644
--- a/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionNode.java
+++ b/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionNode.java
@@ -137,6 +137,11 @@ public class FunctionNode extends BaseTypedDefinitionNode implements
IFunctionNo
     private ASToken openT = null;
     
     /**
+     * True if the function body has anonymous functions.
+     */
+    private boolean hasAnonymousFunctions = false;
+
+    /**
      * True if the function body is a deferred node.
      */
     private boolean isBodyDeferred = false;
@@ -1009,4 +1014,18 @@ public class FunctionNode extends BaseTypedDefinitionNode implements
IFunctionNo
         else
             this.functionBodyText = bodyCache.toString();
     }
+    
+    @Override
+    public boolean containsAnonymousFunctions()
+    {
+        return hasAnonymousFunctions;
+    }
+
+
+    @Override
+    public void setAnonymousFunctionsFlag(boolean value)
+    {
+        hasAnonymousFunctions = value;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8144acb9/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionObjectNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionObjectNode.java
b/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionObjectNode.java
index 4d7e481..4750272 100644
--- a/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionObjectNode.java
+++ b/compiler/src/org/apache/flex/compiler/internal/tree/as/FunctionObjectNode.java
@@ -30,6 +30,7 @@ import org.apache.flex.compiler.problems.ICompilerProblem;
 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.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
 
 /**
@@ -92,6 +93,10 @@ public class FunctionObjectNode extends ExpressionNodeBase implements IFunctionO
     @Override
     protected void analyze(EnumSet<PostProcessStep> set, ASScope scope, Collection<ICompilerProblem>
problems)
     {
+        final IFunctionNode parentFunctionNode = (IFunctionNode)getAncestorOfType(IFunctionNode.class);
+        if (parentFunctionNode != null)
+            parentFunctionNode.setAnonymousFunctionsFlag(true);
+    
         EnumSet<PostProcessStep> stepsToRunOnChildren;
         if (set.contains(PostProcessStep.RECONNECT_DEFINITIONS))
         {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8144acb9/compiler/src/org/apache/flex/compiler/tree/as/IFunctionNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/tree/as/IFunctionNode.java b/compiler/src/org/apache/flex/compiler/tree/as/IFunctionNode.java
index 0a61fb4..a7e5ee6 100644
--- a/compiler/src/org/apache/flex/compiler/tree/as/IFunctionNode.java
+++ b/compiler/src/org/apache/flex/compiler/tree/as/IFunctionNode.java
@@ -154,4 +154,14 @@ public interface IFunctionNode extends IScopedDefinitionNode, IDocumentableDefin
      * Does this function have a non-empty body
      */
     boolean hasBody();
+    
+    /**
+     * Does this function have a anonymous functions within
+     */
+    boolean containsAnonymousFunctions();
+    
+    /**
+     * Set containsAnonymousFunction()
+     */
+    void setAnonymousFunctionsFlag(boolean value);
 }


Mime
View raw message