You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/03/19 23:04:08 UTC

[royale-compiler] 01/02: JSRoyaleEmitter: flag that emitter is emitting local functions is stored in emitter instead of the IFunctionNode

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 30e173892621ce38785a51808e5251bb649ce4e8
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 19 10:46:11 2019 -0700

    JSRoyaleEmitter: flag that emitter is emitting local functions is stored in emitter instead of the IFunctionNode
    
    The IFunctionNode probably shouldn't know that the emitter exists, let alone whether it is emitting local functions. It makes more sense to store it in the emitter, where it matters.
---
 .../royale/compiler/tree/as/IFunctionNode.java     | 12 ---------
 .../codegen/js/royale/JSRoyaleEmitter.java         | 29 +++++++++++++++++++---
 .../compiler/internal/tree/as/FunctionNode.java    | 14 -----------
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/tree/as/IFunctionNode.java b/compiler-common/src/main/java/org/apache/royale/compiler/tree/as/IFunctionNode.java
index e85cb07..64755fd 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/tree/as/IFunctionNode.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/tree/as/IFunctionNode.java
@@ -172,16 +172,4 @@ public interface IFunctionNode extends IScopedDefinitionNode, IDocumentableDefin
      * JS codegen needs to know about them.
      */
     void rememberLocalFunction(IFunctionNode localFunction);
-    
-    /**
-     * flag to determine whether to emit the local function
-     * or a reference to it
-     */
-    boolean getEmittingLocalFunctions();
-    
-    /**
-     * flag to determine whether to emit the local function
-     * or a reference to it
-     */
-    void setEmittingLocalFunctions(boolean emit);
 }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
index 4c987f1..d1b9dc6 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
@@ -23,7 +23,9 @@ import java.io.File;
 import java.io.FilterWriter;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.royale.compiler.codegen.js.royale.IJSRoyaleEmitter;
@@ -155,6 +157,8 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
     public ArrayList<String> staticUsedNames = new ArrayList<String>();
     private boolean needNamespace;
 
+    private Set<IFunctionNode> emittingLocalFunctions = new HashSet<IFunctionNode>();
+
     @Override
     public String postProcess(String output)
     {
@@ -404,17 +408,34 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
     public void emitLocalNamedFunction(IFunctionNode node)
     {
         IFunctionNode parentFnNode = (IFunctionNode) node.getAncestorOfType(IFunctionNode.class);
-        if (parentFnNode == null || parentFnNode.getEmittingLocalFunctions())
+        if (parentFnNode == null || isEmittingLocalFunctions(parentFnNode))
     	{
             // emit named functions only when allowed
     		super.emitLocalNamedFunction(node);
         }
     }
 
+    protected Boolean isEmittingLocalFunctions(IFunctionNode node)
+    {
+        return emittingLocalFunctions.contains(node);
+    }
+
+    protected void setEmittingLocalFunctions(IFunctionNode node, boolean emit)
+    {
+        if (emit)
+        {
+            emittingLocalFunctions.add(node);
+        }
+        else
+        {
+            emittingLocalFunctions.remove(node);
+        }
+    }
+
     @Override
     public void emitFunctionBlockHeader(IFunctionNode node)
     {
-    	node.setEmittingLocalFunctions(true);
+    	setEmittingLocalFunctions(node, true);
     	super.emitFunctionBlockHeader(node);
     	if (node.isConstructor())
     	{
@@ -446,7 +467,7 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
                 }
             }
         }
-    	node.setEmittingLocalFunctions(false);
+    	setEmittingLocalFunctions(node, false);
     }
 
     @Override
@@ -454,7 +475,7 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
     {
 		IFunctionNode parentFnNode = (IFunctionNode) node.getAncestorOfType(IFunctionNode.class);
         IFunctionNode localFnNode = node.getFunctionNode();
-    	if (parentFnNode == null || parentFnNode.getEmittingLocalFunctions())
+    	if (parentFnNode == null || isEmittingLocalFunctions(parentFnNode))
     	{
             // emit named functions only when allowed
     		super.emitFunctionObject(node);
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
index 83cc6cc..c07a8be 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
@@ -1068,19 +1068,5 @@ public class FunctionNode extends BaseTypedDefinitionNode implements IFunctionNo
             localFunctions = new ArrayList<IFunctionNode>();
         
         localFunctions.add(value);
-    }  
-
-    private boolean emitLocalFunctions;
-    
-    @Override
-    public boolean getEmittingLocalFunctions()
-    {
-        return emitLocalFunctions;
-    }
-    
-    @Override
-    public void setEmittingLocalFunctions(boolean emit)
-    {
-        emitLocalFunctions = emit;
     }
 }