flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - FLEX-34984 try a different pattern for for-each conversion
Date Fri, 11 Dec 2015 19:41:53 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop b5e8f73d1 -> f00f85951


FLEX-34984 try a different pattern for for-each conversion


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

Branch: refs/heads/develop
Commit: f00f85951d52d68f445f001504dfa03ad8e1ee8c
Parents: b5e8f73
Author: Alex Harui <aharui@apache.org>
Authored: Fri Dec 11 11:41:42 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Dec 11 11:41:42 2015 -0800

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSGlobalClasses.java      |  2 +-
 .../codegen/js/flexjs/TestFlexJSStatements.java | 24 ++++++++++++++------
 .../internal/codegen/js/jx/ForEachEmitter.java  | 17 +++++++++++---
 3 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f00f8595/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index 322ee63..3b130f5 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -380,7 +380,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
     	IForLoopNode node = getForLoopNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");for
each (var p:XMLList in a) var i:int = p.length();");
         asBlockWalker.visitForLoop(node);
-        assertOut("for (var foreachiter0 in a.elementNames()) \n{\nvar p = a.child(foreachiter0);\n\n
 var /** @type {number} */ i = p.length();}\n");
+        assertOut("var foreachiter0_target = a;\nfor (var foreachiter0 in foreachiter0_target.elementNames())
\n{\nvar p = foreachiter0_target.child(foreachiter0);\n\n  var /** @type {number} */ i = p.length();}\n");
     }
     
     @Ignore

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f00f8595/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
index e635630..bbf5d16 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
@@ -141,7 +141,7 @@ public class TestFlexJSStatements extends TestGoogStatements
         IForLoopNode node = (IForLoopNode) getNode(
                 "for each(var i:int in obj) { break; }", IForLoopNode.class);
         asBlockWalker.visitForLoop(node);
-        assertOut("for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n{\n  break;\n}}\n");
+        assertOut("var foreachiter0_target = obj;\nfor (var foreachiter0 in foreachiter0_target)
\n{\nvar i = foreachiter0_target[foreachiter0];\n{\n  break;\n}}\n");
     }
 
     @Override
@@ -151,7 +151,16 @@ public class TestFlexJSStatements extends TestGoogStatements
         IForLoopNode node = (IForLoopNode) getNode(
                 "for each(var i:int in obj)  break; ", IForLoopNode.class);
         asBlockWalker.visitForLoop(node);
-        assertOut("for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n\n  break;}\n");
+        assertOut("var foreachiter0_target = obj;\nfor (var foreachiter0 in foreachiter0_target)
\n{\nvar i = foreachiter0_target[foreachiter0];\n\n  break;}\n");
+    }
+
+    @Test
+    public void testVisitForEach_2()
+    {
+        IForLoopNode node = (IForLoopNode) getNode(
+                "for each(var i:int in obj.foo()) { break; }", IForLoopNode.class);
+        asBlockWalker.visitForLoop(node);
+        assertOut("var foreachiter0_target = obj.foo();\nfor (var foreachiter0 in foreachiter0_target)
\n{\nvar i = foreachiter0_target[foreachiter0];\n{\n  break;\n}}\n");
     }
 
     @Test
@@ -160,7 +169,7 @@ public class TestFlexJSStatements extends TestGoogStatements
         IForLoopNode node = (IForLoopNode) getNode(
                 "var i:int; for each(i in obj)  break; ", IForLoopNode.class);
         asBlockWalker.visitForLoop(node);
-        assertOut("for (var foreachiter0 in obj) \n{\ni = obj[foreachiter0];\n\n  break;}\n");
+        assertOut("var foreachiter0_target = obj;\nfor (var foreachiter0 in foreachiter0_target)
\n{\ni = foreachiter0_target[foreachiter0];\n\n  break;}\n");
     }
 
     //----------------------------------
@@ -406,7 +415,7 @@ public class TestFlexJSStatements extends TestGoogStatements
                 "foo: for each(var i:int in obj) { break foo; }",
                 LabeledStatementNode.class);
         asBlockWalker.visitLabeledStatement(node);
-        assertOut("foo : for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n{\n
 break foo;\n}}\n");
+        assertOut("foo : var foreachiter0_target = obj;\nfor (var foreachiter0 in foreachiter0_target)
\n{\nvar i = foreachiter0_target[foreachiter0];\n{\n  break foo;\n}}\n");
     }
 
     @Override
@@ -418,7 +427,7 @@ public class TestFlexJSStatements extends TestGoogStatements
                 "foo: for each(var i:int in obj) break foo;",
                 LabeledStatementNode.class);
         asBlockWalker.visitLabeledStatement(node);
-        assertOut("foo : for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n\n
 break foo;}\n");
+        assertOut("foo : var foreachiter0_target = obj;\nfor (var foreachiter0 in foreachiter0_target)
\n{\nvar i = foreachiter0_target[foreachiter0];\n\n  break foo;}\n");
     }
 
     //----------------------------------
@@ -528,9 +537,10 @@ public class TestFlexJSStatements extends TestGoogStatements
         		              "      eee.dd;\n" +
         		              "    }\n" +
         		              "  }\n" +
-        		              "  foo : for (var foreachiter0 in obj) \n" +
+        		              "  foo : var foreachiter0_target = obj;\n" +
+        		              "  for (var foreachiter0 in foreachiter0_target) \n" +
         		              "  {\n" +
-        		              "  var i = obj[foreachiter0];\n" +
+        		              "  var i = foreachiter0_target[foreachiter0];\n" +
         		              "  \n" +
         		              "    break foo;}\n" +
         		              "  ;\n};\n\n\n" +

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f00f8595/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
index cf151b5..7cc335b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
@@ -52,6 +52,18 @@ public class ForEachEmitter extends JSSubEmitter implements
 
         final String iterName = getModel().getCurrentForeachName();
         getModel().incForeachLoopCount();
+        final String targetName = iterName + "_target";
+        
+        write(ASEmitterTokens.VAR);
+        write(ASEmitterTokens.SPACE);
+        write(targetName);
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.EQUAL);
+        write(ASEmitterTokens.SPACE);
+        IASNode obj = bnode.getChild(1);
+        getWalker().walk(obj);
+        write(ASEmitterTokens.SEMICOLON);
+        writeNewline();
 
         write(ASEmitterTokens.FOR);
         write(ASEmitterTokens.SPACE);
@@ -62,8 +74,7 @@ public class ForEachEmitter extends JSSubEmitter implements
         write(ASEmitterTokens.SPACE);
         write(ASEmitterTokens.IN);
         write(ASEmitterTokens.SPACE);
-        IASNode obj = bnode.getChild(1);
-        getWalker().walk(obj);
+        write(targetName);
         boolean isXML = false;
         if (obj.getNodeID() == ASTNodeID.IdentifierID)
         {
@@ -96,7 +107,7 @@ public class ForEachEmitter extends JSSubEmitter implements
         write(ASEmitterTokens.SPACE);
         write(ASEmitterTokens.EQUAL);
         write(ASEmitterTokens.SPACE);
-        getWalker().walk(obj);
+        write(targetName);
         if (isXML)
         {
         	write(".child(");


Mime
View raw message