flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ftho...@apache.org
Subject [30/35] git commit: [flex-falcon] [refs/heads/IDEA-FLEX_JS_COMPILER] - - Refactored literal to emitter. - Refactored self ref to emitter.
Date Tue, 02 Jun 2015 12:42:37 GMT
- Refactored literal to emitter.
- Refactored self ref to 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/f2b74b68
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/f2b74b68
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/f2b74b68

Branch: refs/heads/IDEA-FLEX_JS_COMPILER
Commit: f2b74b68cbdcbbe1822c5771ae5f8caade04e37e
Parents: 0ca46d2
Author: Michael Schmalle <mschmalle@apache.org>
Authored: Sun May 31 15:40:01 2015 -0400
Committer: Frédéric THOMAS <webdoublefx@gmail.com>
Committed: Tue Jun 2 13:41:31 2015 +0100

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 56 +++------------
 .../internal/codegen/js/jx/LiteralEmitter.java  | 74 ++++++++++++++++++++
 .../codegen/js/jx/SelfReferenceEmitter.java     | 52 ++++++++++++++
 3 files changed, 135 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f2b74b68/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 78f1f0b..e1df65a 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
@@ -38,14 +38,15 @@ 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.InterfaceEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.LiteralEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.MemberAccessEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.MethodEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.ObjectDefinePropertyEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.PackageFooterEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.PackageHeaderEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.SelfReferenceEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.SuperCallEmitter;
 import org.apache.flex.compiler.internal.codegen.js.jx.VarDeclarationEmitter;
-import org.apache.flex.compiler.internal.tree.as.RegExpLiteralNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
@@ -60,7 +61,6 @@ import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode;
-import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
@@ -96,8 +96,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     private MemberAccessEmitter memberAccessEmitter;
     private BinaryOperatorEmitter binaryOperatorEmitter;
     private IdentifierEmitter identifierEmitter;
+    private LiteralEmitter literalEmitter;
 
     private AsIsEmitter asIsEmitter;
+    private SelfReferenceEmitter selfReferenceEmitter;
     private ObjectDefinePropertyEmitter objectDefinePropertyEmitter;
     private DefinePropertyFunctionEmitter definePropertyFunctionEmitter;
 
@@ -146,10 +148,12 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         superCallEmitter = new SuperCallEmitter(this);
         forEachEmitter = new ForEachEmitter(this);
         memberAccessEmitter = new MemberAccessEmitter(this);
-        asIsEmitter = new AsIsEmitter(this);
         binaryOperatorEmitter = new BinaryOperatorEmitter(this);
         identifierEmitter = new IdentifierEmitter(this);
+        literalEmitter = new LiteralEmitter(this);
 
+        asIsEmitter = new AsIsEmitter(this);
+        selfReferenceEmitter = new SelfReferenceEmitter(this);
         objectDefinePropertyEmitter = new ObjectDefinePropertyEmitter(this);
         definePropertyFunctionEmitter = new DefinePropertyFunctionEmitter(this);
     }
@@ -320,40 +324,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
     public void emitLiteral(ILiteralNode node)
     {
-        boolean isWritten = false;
-
-        String s = node.getValue(true);
-        if (!(node instanceof RegExpLiteralNode))
-        {
-            if (node.getLiteralType() == LiteralType.XML)
-            {
-                // ToDo (erikdebruin): VF2JS -> handle XML output properly...
-
-                write("'" + s + "'");
-
-                isWritten = true;
-            }
-            s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
-            s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
-            s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
-            s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
-            s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
-            s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
-            s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
-            //s = "\'" + s.replaceAll("\'", "\\\\\'") + "\'";
-            s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
-            s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
-            s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
-            s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
-            s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
-            s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
-            s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
-        }
-
-        if (!isWritten)
-        {
-            write(s);
-        }
+        literalEmitter.emit(node);
     }
 
     //--------------------------------------------------------------------------
@@ -369,16 +340,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
     protected void emitSelfReference(IFunctionNode node)
     {
-        // we don't want 'var self = this;' in FlexJS
-        // unless there are anonymous functions
-        if (node.containsAnonymousFunctions())
-        {
-            writeToken(ASEmitterTokens.VAR);
-            writeToken(JSGoogEmitterTokens.SELF);
-            writeToken(ASEmitterTokens.EQUAL);
-            write(ASEmitterTokens.THIS);
-            writeNewline(ASEmitterTokens.SEMICOLON);
-        }
+        selfReferenceEmitter.emit(node);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f2b74b68/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
new file mode 100644
index 0000000..8f26374
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -0,0 +1,74 @@
+/*
+ *
+ *  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.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.tree.as.RegExpLiteralNode;
+import org.apache.flex.compiler.tree.as.ILiteralNode;
+import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType;
+
+public class LiteralEmitter extends JSSubEmitter implements
+        ISubEmitter<ILiteralNode>
+{
+
+    public LiteralEmitter(IJSEmitter emitter)
+    {
+        super(emitter);
+    }
+
+    @Override
+    public void emit(ILiteralNode node)
+    {
+        boolean isWritten = false;
+
+        String s = node.getValue(true);
+        if (!(node instanceof RegExpLiteralNode))
+        {
+            if (node.getLiteralType() == LiteralType.XML)
+            {
+                write("'" + s + "'");
+
+                isWritten = true;
+            }
+            s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
+            s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
+            s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
+            s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
+            s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
+            s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
+            s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
+            //s = "\'" + s.replaceAll("\'", "\\\\\'") + "\'";
+            s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
+            s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
+            s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
+            s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
+            s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
+            s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
+            s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+        }
+
+        if (!isWritten)
+        {
+            write(s);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f2b74b68/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SelfReferenceEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SelfReferenceEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SelfReferenceEmitter.java
new file mode 100644
index 0000000..0d7849c
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SelfReferenceEmitter.java
@@ -0,0 +1,52 @@
+/*
+ *
+ *  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.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+
+public class SelfReferenceEmitter extends JSSubEmitter implements
+        ISubEmitter<IFunctionNode>
+{
+
+    public SelfReferenceEmitter(IJSEmitter emitter)
+    {
+        super(emitter);
+    }
+
+    @Override
+    public void emit(IFunctionNode node)
+    {
+        // we don't want 'var self = this;' in FlexJS
+        // unless there are anonymous functions
+        if (node.containsAnonymousFunctions())
+        {
+            writeToken(ASEmitterTokens.VAR);
+            writeToken(JSGoogEmitterTokens.SELF);
+            writeToken(ASEmitterTokens.EQUAL);
+            write(ASEmitterTokens.THIS);
+            writeNewline(ASEmitterTokens.SEMICOLON);
+        }
+    }
+}


Mime
View raw message