flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject [2/3] git commit: [flex-falcon] [refs/heads/develop] - - Refactored more shared utility methods. - Moved writeIndent() to ASEmitter.
Date Sun, 31 May 2015 19:08:29 GMT
- Refactored more shared utility methods.
- Moved writeIndent() to ASEmitter.


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

Branch: refs/heads/develop
Commit: f4404cef5a2330f62f588b04b0f464eae5bccda4
Parents: a26406d
Author: Michael Schmalle <mschmalle@apache.org>
Authored: Sun May 31 14:28:16 2015 -0400
Committer: Michael Schmalle <mschmalle@apache.org>
Committed: Sun May 31 14:28:16 2015 -0400

----------------------------------------------------------------------
 .../compiler/internal/codegen/as/ASEmitter.java |  26 ++--
 .../internal/codegen/js/goog/JSGoogEmitter.java | 124 ++-----------------
 .../internal/codegen/js/utils/EmitterUtils.java |  42 ++++++-
 .../codegen/js/vf2js/JSVF2JSEmitter.java        |  12 +-
 4 files changed, 78 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f4404cef/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
index 26b1100..7f5f46f 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
@@ -147,12 +147,17 @@ public class ASEmitter implements IASEmitter, IEmitter
         return currentIndent;
     }
 
+    protected void writeIndent()
+    {
+        write(ASEmitterTokens.INDENT);
+    }
+
     private IASBlockWalker walker;
 
     @Override
     public IBlockWalker getWalker()
     {
-        return (IBlockWalker) walker;
+        return walker;
     }
 
     @Override
@@ -1367,7 +1372,8 @@ public class ASEmitter implements IASEmitter, IEmitter
     }
 
     @Override
-    public void emitNamespaceAccessExpression(INamespaceAccessExpressionNode node)
+    public void emitNamespaceAccessExpression(
+            INamespaceAccessExpressionNode node)
     {
         getWalker().walk(node.getLeftOperandNode());
         write(node.getOperator().getOperatorText());
@@ -1379,7 +1385,7 @@ public class ASEmitter implements IASEmitter, IEmitter
     {
         if (ASNodeUtils.hasParenOpen(node))
             write(ASEmitterTokens.PAREN_OPEN);
-        
+
         if (node.getNodeID() == ASTNodeID.Op_PreIncrID
                 || node.getNodeID() == ASTNodeID.Op_PreDecrID
                 || node.getNodeID() == ASTNodeID.Op_BitwiseNotID
@@ -1397,7 +1403,7 @@ public class ASEmitter implements IASEmitter, IEmitter
             }
             else
             {
-                getWalker().walk(node.getOperandNode());            
+                getWalker().walk(node.getOperandNode());
             }
         }
 
@@ -1420,7 +1426,7 @@ public class ASEmitter implements IASEmitter, IEmitter
             getWalker().walk(node.getOperandNode());
             write(ASEmitterTokens.PAREN_CLOSE);
         }
-        
+
         if (ASNodeUtils.hasParenClose(node))
             write(ASEmitterTokens.PAREN_CLOSE);
     }
@@ -1455,23 +1461,27 @@ public class ASEmitter implements IASEmitter, IEmitter
     {
     }
 
+    @Override
     public void emitContainer(IContainerNode node)
     {
     }
 
+    @Override
     public void emitE4XFilter(IMemberAccessExpressionNode node)
     {
-    	// ToDo (erikdebruin)
+        // ToDo (erikdebruin)
     }
 
+    @Override
     public void emitUseNamespace(IUseNamespaceNode node)
     {
-    	// ToDo (erikdebruin)
+        // ToDo (erikdebruin)
     }
 
+    @Override
     public String stringifyNode(IASNode node)
     {
-    	boolean oldBufferWrite = isBufferWrite();
+        boolean oldBufferWrite = isBufferWrite();
         StringBuilder oldBuilder = this.builder;
         this.builder = new StringBuilder();
         setBufferWrite(true);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f4404cef/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
index c431553..7dd7cdb 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
@@ -21,7 +21,6 @@ package org.apache.flex.compiler.internal.codegen.js.goog;
 
 import java.io.FilterWriter;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -41,7 +40,6 @@ import org.apache.flex.compiler.internal.codegen.js.JSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
 import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
-import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.internal.scopes.PackageScope;
 import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
@@ -66,7 +64,6 @@ import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
-import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.ITypeNode;
 import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
@@ -98,11 +95,6 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         return docEmitter;
     }
 
-    protected void writeIndent()
-    {
-        write(ASEmitterTokens.INDENT);
-    }
-
     //--------------------------------------------------------------------------
     // 
     //--------------------------------------------------------------------------
@@ -142,7 +134,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         if (type == null)
             return;
 
-        List<String> list = resolveImports(type);
+        List<String> list = EmitterUtils.resolveImports(type);
         for (String imp : list)
         {
             if (imp.indexOf(JSGoogEmitterTokens.AS3.getToken()) != -1)
@@ -485,7 +477,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
 
         emitParameters(node.getParameterNodes());
 
-        boolean hasSuperClass = hasSuperClass(node);
+        boolean hasSuperClass = EmitterUtils.hasSuperClass(project, node);
 
         if (isConstructor && node.getScopedNode().getChildCount() == 0)
         {
@@ -621,11 +613,12 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         boolean isLocal = false;
         if (node.getFunctionClassification() == IFunctionDefinition.FunctionClassification.LOCAL)
             isLocal = true;
-        if (hasBody(node) && !isStatic && !isLocal)
+        if (EmitterUtils.hasBody(node) && !isStatic && !isLocal)
             emitSelfReference(node);
 
-        if (node.isConstructor() && hasSuperClass(node)
-                && !hasSuperCall(node.getScopedNode()))
+        if (node.isConstructor()
+                && EmitterUtils.hasSuperClass(getWalker().getProject(), node)
+                && !EmitterUtils.hasSuperCall(node.getScopedNode()))
             emitSuperCall(node, JSSessionModel.CONSTRUCTOR_FULL);
 
         emitRestParameterCodeBlock(node);
@@ -662,7 +655,8 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
                         .getAncestorOfType(IFunctionNode.class);
         }
 
-        if (fnode.isConstructor() && !hasSuperClass(fnode))
+        if (fnode.isConstructor()
+                && !EmitterUtils.hasSuperClass(getWalker().getProject(), fnode))
             return;
 
         IClassNode cnode = (IClassNode) node
@@ -741,13 +735,14 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         if (pnodes.length == 0)
             return;
 
-        Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
+        Map<Integer, IParameterNode> defaults = EmitterUtils
+                .getDefaults(pnodes);
 
         if (defaults != null)
         {
             final StringBuilder code = new StringBuilder();
 
-            if (!hasBody(node))
+            if (!EmitterUtils.hasBody(node))
             {
                 indentPush();
                 writeIndent();
@@ -790,7 +785,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
 
                     write(code.toString());
 
-                    if (i == n - 1 && !hasBody(node))
+                    if (i == n - 1 && !EmitterUtils.hasBody(node))
                         indentPop();
 
                     writeNewline();
@@ -803,7 +798,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
     {
         IParameterNode[] pnodes = node.getParameterNodes();
 
-        IParameterNode rest = getRest(pnodes);
+        IParameterNode rest = EmitterUtils.getRest(pnodes);
         if (rest != null)
         {
             final StringBuilder code = new StringBuilder();
@@ -900,42 +895,6 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         super(out);
     }
 
-    protected Map<Integer, IParameterNode> getDefaults(IParameterNode[] nodes)
-    {
-        Map<Integer, IParameterNode> result = new HashMap<Integer, IParameterNode>();
-        int i = 0;
-        boolean hasDefaults = false;
-        for (IParameterNode node : nodes)
-        {
-            if (node.hasDefaultValue())
-            {
-                hasDefaults = true;
-                result.put(i, node);
-            }
-            else
-            {
-                result.put(i, null);
-            }
-            i++;
-        }
-
-        if (!hasDefaults)
-            return null;
-
-        return result;
-    }
-
-    private IParameterNode getRest(IParameterNode[] nodes)
-    {
-        for (IParameterNode node : nodes)
-        {
-            if (node.isRest())
-                return node;
-        }
-
-        return null;
-    }
-
     private static ITypeDefinition getTypeDefinition(IDefinitionNode node)
     {
         ITypeNode tnode = (ITypeNode) node.getAncestorOfType(ITypeNode.class);
@@ -951,38 +910,6 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         return superClass;
     }
 
-    protected boolean hasSuperClass(IDefinitionNode node)
-    {
-        ICompilerProject project = getWalker().getProject();
-        IClassDefinition superClassDefinition = getSuperClassDefinition(node,
-                project);
-        // XXX (mschmalle) this is nulling for MXML super class, figure out why
-        if (superClassDefinition == null)
-            return false;
-        String qname = superClassDefinition.getQualifiedName();
-        return superClassDefinition != null
-                && !qname.equals(IASLanguageConstants.Object);
-    }
-
-    protected boolean hasSuperCall(IScopedNode node)
-    {
-        for (int i = node.getChildCount() - 1; i > -1; i--)
-        {
-            IASNode cnode = node.getChild(i);
-            if (cnode.getNodeID() == ASTNodeID.FunctionCallID
-                    && cnode.getChild(0).getNodeID() == ASTNodeID.SuperID)
-                return true;
-        }
-
-        return false;
-    }
-
-    protected static boolean hasBody(IFunctionNode node)
-    {
-        IScopedNode scope = node.getScopedNode();
-        return scope.getChildCount() > 0;
-    }
-
     protected void emitObjectDefineProperty(IAccessorNode node)
     {
         /*
@@ -1139,29 +1066,4 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         if (ASNodeUtils.hasParenOpen(node))
             write(ASEmitterTokens.PAREN_CLOSE);
     }
-
-    //--------------------------------------------------------------------------
-    // 
-    //--------------------------------------------------------------------------
-
-    private List<String> resolveImports(ITypeDefinition type)
-    {
-        ArrayList<String> list = new ArrayList<String>();
-        IScopedNode scopeNode = type.getContainedScope().getScopeNode();
-        if (scopeNode != null)
-        {
-            scopeNode.getAllImports(list);
-        }
-        else
-        {
-            // MXML
-            ClassDefinition cdefinition = (ClassDefinition) type;
-            String[] implicitImports = cdefinition.getImplicitImports();
-            for (String imp : implicitImports)
-            {
-                list.add(imp);
-            }
-        }
-        return list;
-    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f4404cef/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
index 07da145..4f8482f 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -21,9 +21,11 @@ package org.apache.flex.compiler.internal.codegen.js.utils;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.flex.compiler.constants.IASLanguageConstants;
@@ -50,6 +52,7 @@ import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ITypeNode;
 
@@ -167,13 +170,50 @@ public class EmitterUtils
         return (tnode != null) ? tnode.getDefinition() : null;
     }
 
+    public static IParameterNode getRest(IParameterNode[] nodes)
+    {
+        for (IParameterNode node : nodes)
+        {
+            if (node.isRest())
+                return node;
+        }
+
+        return null;
+    }
+
+    public static Map<Integer, IParameterNode> getDefaults(
+            IParameterNode[] nodes)
+    {
+        Map<Integer, IParameterNode> result = new HashMap<Integer, IParameterNode>();
+        int i = 0;
+        boolean hasDefaults = false;
+        for (IParameterNode node : nodes)
+        {
+            if (node.hasDefaultValue())
+            {
+                hasDefaults = true;
+                result.put(i, node);
+            }
+            else
+            {
+                result.put(i, null);
+            }
+            i++;
+        }
+
+        if (!hasDefaults)
+            return null;
+
+        return result;
+    }
+
     public static boolean writeThis(ICompilerProject project,
             JSSessionModel model, IIdentifierNode node)
     {
         IClassNode classNode = (IClassNode) node
                 .getAncestorOfType(IClassNode.class);
 
-        IDefinition nodeDef = ((IIdentifierNode) node).resolve(project);
+        IDefinition nodeDef = node.resolve(project);
 
         IASNode parentNode = node.getParent();
         ASTNodeID parentNodeId = parentNode.getNodeID();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f4404cef/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
index dab4472..b436b8a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
@@ -267,7 +267,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
         boolean isLocal = false;
         if (node.getFunctionClassification() == IFunctionDefinition.FunctionClassification.LOCAL)
             isLocal = true;
-        if (hasBody(node) && !isStatic && !isLocal)
+        if (EmitterUtils.hasBody(node) && !isStatic && !isLocal)
             emitSelfReference(node);
 
         emitRestParameterCodeBlock(node);
@@ -280,7 +280,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
         }
 
         if (node.isConstructor() && hasSuperClass(node)
-                && !hasSuperCall(node.getScopedNode()))
+                && !EmitterUtils.hasSuperCall(node.getScopedNode()))
             emitSuperCall(node, JSSessionModel.CONSTRUCTOR_FULL);
     }
 
@@ -578,7 +578,6 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
         }
     }
 
-    @Override
     protected boolean hasSuperClass(IDefinitionNode node)
     {
         ICompilerProject project = getWalker().getProject();
@@ -1182,13 +1181,14 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
         if (pnodes.length == 0)
             return;
 
-        Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
+        Map<Integer, IParameterNode> defaults = EmitterUtils
+                .getDefaults(pnodes);
 
         if (defaults != null)
         {
             final StringBuilder code = new StringBuilder();
 
-            if (!hasBody(node))
+            if (!EmitterUtils.hasBody(node))
             {
                 indentPush();
                 write(JSFlexJSEmitterTokens.INDENT);
@@ -1231,7 +1231,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
 
                     write(code.toString());
 
-                    if (i == n - 1 && !hasBody(node))
+                    if (i == n - 1 && !EmitterUtils.hasBody(node))
                         indentPop();
 
                     writeNewline();


Mime
View raw message