You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2015/05/31 18:01:17 UTC

[2/2] git commit: [flex-falcon] [refs/heads/develop] - - Moved emitBindableVarDefineProperty() to Bindable emitter. - Refactored foreach into emitter.

- Moved emitBindableVarDefineProperty() to Bindable emitter.
- Refactored foreach into emitter.


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

Branch: refs/heads/develop
Commit: ec0a792366d61ef6be6967745e96c13b662cd421
Parents: f51e234
Author: Michael Schmalle <ms...@apache.org>
Authored: Sun May 31 12:00:44 2015 -0400
Committer: Michael Schmalle <ms...@apache.org>
Committed: Sun May 31 12:00:44 2015 -0400

----------------------------------------------------------------------
 .../internal/codegen/js/JSSessionModel.java     |  12 +++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 105 +------------------
 .../internal/codegen/js/jx/BindableEmitter.java |  58 +++++++++-
 .../internal/codegen/js/jx/ForEachEmitter.java  |  88 ++++++++++++++++
 4 files changed, 162 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ec0a7923/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
index ba8df11..48079fa 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
@@ -50,6 +50,8 @@ public class JSSessionModel
 
     private ArrayList<String> bindableVars = new ArrayList<String>();
 
+    private int foreachLoopCount = 0;
+
     public IClassDefinition getCurrentClass()
     {
         return currentClass;
@@ -80,4 +82,14 @@ public class JSSessionModel
         return bindableVars;
     }
 
+    public final void incForeachLoopCount()
+    {
+        foreachLoopCount++;
+    }
+
+    public String getCurrentForeachName()
+    {
+        return "foreachiter" + Integer.toString(foreachLoopCount);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ec0a7923/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 5562e31..f86ca5a 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
@@ -26,7 +26,6 @@ import org.apache.flex.compiler.codegen.IDocEmitter;
 import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSEmitter;
 import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.common.IMetaInfo;
-import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
@@ -38,6 +37,7 @@ import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.jx.BinaryOperatorEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.ClassEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.FieldEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.ForEachEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.FunctionCallEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.IdentifierEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.MemberAccessEmitter;
@@ -65,11 +65,10 @@ import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
-import org.apache.flex.compiler.tree.as.IVariableExpressionNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 
 /**
- * Concrete implementation of the 'goog' JavaScript production.
+ * Concrete implementation of the 'FlexJS' JavaScript production.
  * 
  * @author Michael Schmalle
  * @author Erik de Bruin
@@ -77,8 +76,6 @@ import org.apache.flex.compiler.tree.as.IVariableNode;
 public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
 {
 
-    private int foreachLoopCounter = 0;
-
     private JSFlexJSDocEmitter docEmitter = null;
 
     private PackageHeaderEmitter packageHeaderEmitter;
@@ -88,6 +85,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     private FieldEmitter fieldEmitter;
     private FunctionCallEmitter functionCallEmitter;
     private SuperCallEmitter superCallEmitter;
+    private ForEachEmitter forEachEmitter;
     private MemberAccessEmitter memberAccessEmitter;
     private BinaryOperatorEmitter binaryOperatorEmitter;
     private IdentifierEmitter identifierEmitter;
@@ -116,6 +114,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         fieldEmitter = new FieldEmitter(this);
         functionCallEmitter = new FunctionCallEmitter(this);
         superCallEmitter = new SuperCallEmitter(this);
+        forEachEmitter = new ForEachEmitter(this);
         memberAccessEmitter = new MemberAccessEmitter(this);
         binaryOperatorEmitter = new BinaryOperatorEmitter(this);
         identifierEmitter = new IdentifierEmitter(this);
@@ -154,58 +153,6 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         fieldEmitter.emit(node);
     }
 
-    public void emitBindableVarDefineProperty(String name, IClassDefinition cdef)
-    {
-        // 'PropName': {
-        writeNewline("/** @expose */");
-        writeNewline(name + ASEmitterTokens.COLON.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.BLOCK_OPEN.getToken());
-        indentPush();
-        writeNewline("/** @this {"
-                + formatQualifiedName(cdef.getQualifiedName()) + "} */");
-        writeNewline(ASEmitterTokens.GET.getToken()
-                + ASEmitterTokens.COLON.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.FUNCTION.getToken()
-                + ASEmitterTokens.PAREN_OPEN.getToken()
-                + ASEmitterTokens.PAREN_CLOSE.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.BLOCK_OPEN.getToken());
-        writeNewline(ASEmitterTokens.RETURN.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.THIS.getToken()
-                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
-                + ASEmitterTokens.SEMICOLON.getToken());
-        indentPop();
-        writeNewline(ASEmitterTokens.BLOCK_CLOSE.getToken()
-                + ASEmitterTokens.COMMA.getToken());
-        writeNewline();
-        writeNewline("/** @this {"
-                + formatQualifiedName(cdef.getQualifiedName()) + "} */");
-        writeNewline(ASEmitterTokens.SET.getToken()
-                + ASEmitterTokens.COLON.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.FUNCTION.getToken()
-                + ASEmitterTokens.PAREN_OPEN.getToken() + "value"
-                + ASEmitterTokens.PAREN_CLOSE.getToken()
-                + ASEmitterTokens.SPACE.getToken()
-                + ASEmitterTokens.BLOCK_OPEN.getToken());
-        writeNewline("if (value != " + ASEmitterTokens.THIS.getToken()
-                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_) {");
-        writeNewline("    var oldValue = " + ASEmitterTokens.THIS.getToken()
-                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
-                + ASEmitterTokens.SEMICOLON.getToken());
-        writeNewline("    " + ASEmitterTokens.THIS.getToken()
-                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name
-                + "_ = value;");
-        writeNewline("    this.dispatchEvent(org_apache_flex_events_ValueChangeEvent.createUpdateEvent(");
-        writeNewline("         this, \"" + name + "\", oldValue, value));");
-        writeNewline("}");
-        write(ASEmitterTokens.BLOCK_CLOSE.getToken());
-        write(ASEmitterTokens.BLOCK_CLOSE.getToken());
-    }
-
     @Override
     public void emitAccessors(IAccessorNode node)
     {
@@ -500,49 +447,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
     public void emitForEachLoop(IForLoopNode node)
     {
-        IBinaryOperatorNode bnode = (IBinaryOperatorNode) node
-                .getConditionalsContainerNode().getChild(0);
-        IASNode childNode = bnode.getChild(0);
-
-        String iterName = "foreachiter"
-                + new Integer(foreachLoopCounter).toString();
-        foreachLoopCounter++;
-
-        write(ASEmitterTokens.FOR);
-        write(ASEmitterTokens.SPACE);
-        write(ASEmitterTokens.PAREN_OPEN);
-        write(ASEmitterTokens.VAR);
-        write(ASEmitterTokens.SPACE);
-        write(iterName);
-        write(ASEmitterTokens.SPACE);
-        write(ASEmitterTokens.IN);
-        write(ASEmitterTokens.SPACE);
-        getWalker().walk(bnode.getChild(1));
-        writeToken(ASEmitterTokens.PAREN_CLOSE);
-        writeNewline();
-        write(ASEmitterTokens.BLOCK_OPEN);
-        writeNewline();
-        if (childNode instanceof IVariableExpressionNode)
-        {
-            write(ASEmitterTokens.VAR);
-            write(ASEmitterTokens.SPACE);
-            write(((IVariableNode) childNode.getChild(0)).getName());
-        }
-        else
-            write(((IIdentifierNode) childNode).getName());
-        write(ASEmitterTokens.SPACE);
-        write(ASEmitterTokens.EQUAL);
-        write(ASEmitterTokens.SPACE);
-        getWalker().walk(bnode.getChild(1));
-        write(ASEmitterTokens.SQUARE_OPEN);
-        write(iterName);
-        write(ASEmitterTokens.SQUARE_CLOSE);
-        write(ASEmitterTokens.SEMICOLON);
-        writeNewline();
-        getWalker().walk(node.getStatementContentsNode());
-        write(ASEmitterTokens.BLOCK_CLOSE);
-        writeNewline();
-
+        forEachEmitter.emit(node);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ec0a7923/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
index 310bf6b..0ec3fd2 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
@@ -66,11 +66,67 @@ public class BindableEmitter extends JSSubEmitter implements
                 else
                     write(ASEmitterTokens.COMMA);
 
-                fjs.emitBindableVarDefineProperty(varName, definition);
+                emitBindableVarDefineProperty(varName, definition);
             }
             writeNewline(ASEmitterTokens.BLOCK_CLOSE);
             write(ASEmitterTokens.PAREN_CLOSE);
             write(ASEmitterTokens.SEMICOLON);
         }
     }
+
+    private void emitBindableVarDefineProperty(String name,
+            IClassDefinition cdef)
+    {
+        // TODO (mschmalle) will remove this cast as more things get abstracted
+        JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+        // 'PropName': {
+        writeNewline("/** @expose */");
+        writeNewline(name + ASEmitterTokens.COLON.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.BLOCK_OPEN.getToken());
+        indentPush();
+        writeNewline("/** @this {"
+                + fjs.formatQualifiedName(cdef.getQualifiedName()) + "} */");
+        writeNewline(ASEmitterTokens.GET.getToken()
+                + ASEmitterTokens.COLON.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.FUNCTION.getToken()
+                + ASEmitterTokens.PAREN_OPEN.getToken()
+                + ASEmitterTokens.PAREN_CLOSE.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.BLOCK_OPEN.getToken());
+        writeNewline(ASEmitterTokens.RETURN.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.THIS.getToken()
+                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+                + ASEmitterTokens.SEMICOLON.getToken());
+        indentPop();
+        writeNewline(ASEmitterTokens.BLOCK_CLOSE.getToken()
+                + ASEmitterTokens.COMMA.getToken());
+        writeNewline();
+        writeNewline("/** @this {"
+                + fjs.formatQualifiedName(cdef.getQualifiedName()) + "} */");
+        writeNewline(ASEmitterTokens.SET.getToken()
+                + ASEmitterTokens.COLON.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.FUNCTION.getToken()
+                + ASEmitterTokens.PAREN_OPEN.getToken() + "value"
+                + ASEmitterTokens.PAREN_CLOSE.getToken()
+                + ASEmitterTokens.SPACE.getToken()
+                + ASEmitterTokens.BLOCK_OPEN.getToken());
+        writeNewline("if (value != " + ASEmitterTokens.THIS.getToken()
+                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_) {");
+        writeNewline("    var oldValue = " + ASEmitterTokens.THIS.getToken()
+                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+                + ASEmitterTokens.SEMICOLON.getToken());
+        writeNewline("    " + ASEmitterTokens.THIS.getToken()
+                + ASEmitterTokens.MEMBER_ACCESS.getToken() + name
+                + "_ = value;");
+        writeNewline("    this.dispatchEvent(org_apache_flex_events_ValueChangeEvent.createUpdateEvent(");
+        writeNewline("         this, \"" + name + "\", oldValue, value));");
+        writeNewline("}");
+        write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+        write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ec0a7923/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
new file mode 100644
index 0000000..1b33061
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
@@ -0,0 +1,88 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IVariableExpressionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+
+public class ForEachEmitter extends JSSubEmitter implements
+        ISubEmitter<IForLoopNode>
+{
+
+    public ForEachEmitter(IJSEmitter emitter)
+    {
+        super(emitter);
+    }
+
+    @Override
+    public void emit(IForLoopNode node)
+    {
+        IBinaryOperatorNode bnode = (IBinaryOperatorNode) node
+                .getConditionalsContainerNode().getChild(0);
+        IASNode childNode = bnode.getChild(0);
+
+        final String iterName = getModel().getCurrentForeachName();
+        getModel().incForeachLoopCount();
+
+        write(ASEmitterTokens.FOR);
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.PAREN_OPEN);
+        write(ASEmitterTokens.VAR);
+        write(ASEmitterTokens.SPACE);
+        write(iterName);
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.IN);
+        write(ASEmitterTokens.SPACE);
+        getWalker().walk(bnode.getChild(1));
+        writeToken(ASEmitterTokens.PAREN_CLOSE);
+        writeNewline();
+        write(ASEmitterTokens.BLOCK_OPEN);
+        writeNewline();
+        if (childNode instanceof IVariableExpressionNode)
+        {
+            write(ASEmitterTokens.VAR);
+            write(ASEmitterTokens.SPACE);
+            write(((IVariableNode) childNode.getChild(0)).getName());
+        }
+        else
+            write(((IIdentifierNode) childNode).getName());
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.EQUAL);
+        write(ASEmitterTokens.SPACE);
+        getWalker().walk(bnode.getChild(1));
+        write(ASEmitterTokens.SQUARE_OPEN);
+        write(iterName);
+        write(ASEmitterTokens.SQUARE_CLOSE);
+        write(ASEmitterTokens.SEMICOLON);
+        writeNewline();
+        getWalker().walk(node.getStatementContentsNode());
+        write(ASEmitterTokens.BLOCK_CLOSE);
+        writeNewline();
+    }
+
+}