flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1434094 - in /flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler: as/codegen/IASEmitter.java internal/as/codegen/ASBlockWalker.java internal/as/codegen/ASEmitter.java
Date Wed, 16 Jan 2013 18:30:48 GMT
Author: mschmalle
Date: Wed Jan 16 18:30:48 2013
New Revision: 1434094

URL: http://svn.apache.org/viewvc?rev=1434094&view=rev
Log:
Flex:FalconJx
- Refactored for and for each statements into ASEmitter

Modified:
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java?rev=1434094&r1=1434093&r2=1434094&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java
(original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java
Wed Jan 16 18:30:48 2013
@@ -27,6 +27,7 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IBlockNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 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.IGetterNode;
@@ -159,7 +160,7 @@ public interface IASEmitter
     void emitSetAccessor(ISetterNode node);
 
     void emitParameter(IParameterNode node);
-    
+
     /**
      * Emit a namespace member.
      * 
@@ -168,6 +169,31 @@ public interface IASEmitter
     void emitNamespace(INamespaceNode node);
 
     //--------------------------------------------------------------------------
+    // Statements
+    //--------------------------------------------------------------------------
+
+    /**
+     * Emit a statement found within an {@link IBlockNode}.
+     * 
+     * @param node The {@link IASNode} statement.
+     */
+    void emitStatement(IASNode node);
+
+    /**
+     * Emit a <code>for each</code> statement.
+     * 
+     * @param node The {@link IForLoopNode} node.
+     */
+    void emitForEachLoop(IForLoopNode node);
+
+    /**
+     * Emit a <code>for</code> statement.
+     * 
+     * @param node The {@link IForLoopNode} node.
+     */
+    void emitForLoop(IForLoopNode node);
+
+    //--------------------------------------------------------------------------
     // Expressions
     //--------------------------------------------------------------------------
 
@@ -186,28 +212,21 @@ public interface IASEmitter
      * @param node The anonymous {@link FunctionObjectNode}.
      */
     void emitFunctionObject(IExpressionNode node);
-    
+
     /**
      * Emit a header at the start of a function block.
      * 
      * @param node The {@link IFunctionNode} node.
      */
     void emitFunctionBlockHeader(IFunctionNode node);
-    
+
     /**
      * Emit a function call like <code>new Foo()</code> or <code>foo(42)</code>.
      * 
      * @param node The {@link IFunctionCallNode} node.
      */
     void emitFunctionCall(IFunctionCallNode node);
-    
-    /**
-     * Emit a statement found within an {@link IBlockNode}.
-     * 
-     * @param node The {@link IASNode} statement.
-     */
-    void emitStatement(IASNode node);
-    
+
     //--------------------------------------------------------------------------
     // Operators
     //--------------------------------------------------------------------------
@@ -219,8 +238,4 @@ public interface IASEmitter
      */
     void emitBinaryOperator(IBinaryOperatorNode node);
 
-    
-
-    
-
 }

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java?rev=1434094&r1=1434093&r2=1434094&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
(original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
Wed Jan 16 18:30:48 2013
@@ -72,7 +72,6 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IReturnNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
-import org.apache.flex.compiler.tree.as.IStatementNode;
 import org.apache.flex.compiler.tree.as.ISwitchNode;
 import org.apache.flex.compiler.tree.as.ITerminalNode;
 import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
@@ -369,82 +368,13 @@ public class ASBlockWalker implements IA
     protected void visitForEach(IForLoopNode node)
     {
         debug("visitForEach()");
-        IContainerNode xnode = (IContainerNode) node.getChild(1);
-        emitter.write("for");
-        emitter.write(" ");
-        emitter.write("each");
-        emitter.write(" ");
-        emitter.write("(");
-
-        IContainerNode cnode = node.getConditionalsContainerNode();
-        visitForInBody(cnode);
-
-        emitter.write(")");
-        if (!isImplicit(xnode))
-            emitter.write(" ");
-
-        walk(node.getStatementContentsNode());
+        emitter.emitForEachLoop(node);
     }
 
     protected void visitFor(IForLoopNode node)
     {
         debug("visitFor()");
-        IContainerNode xnode = (IContainerNode) node.getChild(1);
-
-        emitter.write("for");
-        emitter.write(" ");
-        emitter.write("(");
-
-        IContainerNode cnode = node.getConditionalsContainerNode();
-        final IASNode node0 = cnode.getChild(0);
-        if (node0.getNodeID() == ASTNodeID.Op_InID)
-        {
-            visitForInBody(cnode);
-        }
-        else
-        {
-            visitForBody(cnode);
-        }
-
-        emitter.write(")");
-        if (!isImplicit(xnode))
-            emitter.write(" ");
-
-        walk(node.getStatementContentsNode());
-    }
-
-    protected void visitForInBody(IContainerNode node)
-    {
-        walk(node.getChild(0));
-    }
-
-    protected void visitForBody(IContainerNode node)
-    {
-        final IASNode node0 = node.getChild(0);
-        final IASNode node1 = node.getChild(1);
-        final IASNode node2 = node.getChild(2);
-
-        // initializer
-        if (node0 != null)
-        {
-            walk(node0);
-            emitter.write(";");
-            if (node1.getNodeID() != ASTNodeID.NilID)
-                emitter.write(" ");
-        }
-        // condition or target
-        if (node1 != null)
-        {
-            walk(node1);
-            emitter.write(";");
-            if (node2.getNodeID() != ASTNodeID.NilID)
-                emitter.write(" ");
-        }
-        // iterator
-        if (node2 != null)
-        {
-            walk(node2);
-        }
+        emitter.emitForLoop(node);
     }
 
     @Override

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1434094&r1=1434093&r2=1434094&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Wed Jan 16 18:30:48 2013
@@ -41,8 +41,10 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 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.IGetterNode;
@@ -56,6 +58,7 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IStatementNode;
 import org.apache.flex.compiler.tree.as.ITypeNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
 import org.apache.flex.compiler.visitor.IASBlockWalker;
 
 /**
@@ -712,6 +715,10 @@ public class ASEmitter implements IASEmi
         emitMethodScope(node);
     }
 
+    //--------------------------------------------------------------------------
+    // Statements
+    //--------------------------------------------------------------------------
+
     @Override
     public void emitStatement(IASNode node)
     {
@@ -727,8 +734,55 @@ public class ASEmitter implements IASEmi
             write("\n");
     }
 
+    @Override
+    public void emitForEachLoop(IForLoopNode node)
+    {
+        IContainerNode xnode = (IContainerNode) node.getChild(1);
+        write("for");
+        write(" ");
+        write("each");
+        write(" ");
+        write("(");
+
+        IContainerNode cnode = node.getConditionalsContainerNode();
+        getWalker().walk(cnode.getChild(0));
+
+        write(")");
+        if (!isImplicit(xnode))
+            write(" ");
+
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitForLoop(IForLoopNode node)
+    {
+        IContainerNode xnode = (IContainerNode) node.getChild(1);
+
+        write("for");
+        write(" ");
+        write("(");
+
+        IContainerNode cnode = node.getConditionalsContainerNode();
+        final IASNode node0 = cnode.getChild(0);
+        if (node0.getNodeID() == ASTNodeID.Op_InID)
+        {
+            getWalker().walk(cnode.getChild(0));
+        }
+        else
+        {
+            visitForBody(cnode);
+        }
+
+        write(")");
+        if (!isImplicit(xnode))
+            write(" ");
+
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
     //--------------------------------------------------------------------------
-    // 
+    // Expressions
     //--------------------------------------------------------------------------
 
     @Override
@@ -825,4 +879,39 @@ public class ASEmitter implements IASEmi
         }
         return -1;
     }
+
+    private static final boolean isImplicit(IContainerNode node)
+    {
+        return node.getContainerType() == ContainerType.IMPLICIT
+                || node.getContainerType() == ContainerType.SYNTHESIZED;
+    }
+
+    protected void visitForBody(IContainerNode node)
+    {
+        final IASNode node0 = node.getChild(0);
+        final IASNode node1 = node.getChild(1);
+        final IASNode node2 = node.getChild(2);
+
+        // initializer
+        if (node0 != null)
+        {
+            getWalker().walk(node0);
+            write(";");
+            if (node1.getNodeID() != ASTNodeID.NilID)
+                write(" ");
+        }
+        // condition or target
+        if (node1 != null)
+        {
+            getWalker().walk(node1);
+            write(";");
+            if (node2.getNodeID() != ASTNodeID.NilID)
+                write(" ");
+        }
+        // iterator
+        if (node2 != null)
+        {
+            getWalker().walk(node2);
+        }
+    }
 }



Mime
View raw message