You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2016/04/29 01:58:44 UTC
[2/5] git commit: [flex-falcon] [refs/heads/develop] - source maps
for try/catch
source maps for try/catch
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/91288abb
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/91288abb
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/91288abb
Branch: refs/heads/develop
Commit: 91288abb223101216f1ab0b79e1362d0b5834710
Parents: bf86283
Author: Josh Tynjala <jo...@gmail.com>
Authored: Thu Apr 28 16:13:46 2016 -0700
Committer: Josh Tynjala <jo...@gmail.com>
Committed: Thu Apr 28 16:13:46 2016 -0700
----------------------------------------------------------------------
.../compiler/internal/codegen/js/JSEmitter.java | 20 +++++
.../internal/codegen/js/jx/CatchEmitter.java | 52 ++++++++++++
.../internal/codegen/js/jx/TryEmitter.java | 58 +++++++++++++
.../js/sourcemaps/TestSourceMapStatements.java | 89 ++++++++++++++++++++
4 files changed, 219 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91288abb/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
index d7db258..6d4b15f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
@@ -32,6 +32,7 @@ import org.apache.flex.compiler.internal.codegen.as.ASEmitter;
import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
import org.apache.flex.compiler.internal.codegen.js.jx.BlockCloseEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.BlockOpenEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.CatchEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.DoWhileLoopEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.DynamicAccessEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.ForLoopEmitter;
@@ -50,11 +51,13 @@ import org.apache.flex.compiler.internal.codegen.js.jx.SourceMapDirectiveEmitter
import org.apache.flex.compiler.internal.codegen.js.jx.StatementEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.SwitchEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.TernaryOperatorEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.TryEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.UnaryOperatorEmitter;
import org.apache.flex.compiler.internal.codegen.js.jx.WhileLoopEmitter;
import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
import org.apache.flex.compiler.internal.tree.as.FunctionNode;
import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.ICatchNode;
import org.apache.flex.compiler.tree.as.IContainerNode;
import org.apache.flex.compiler.tree.as.IDefinitionNode;
import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
@@ -72,6 +75,7 @@ import org.apache.flex.compiler.tree.as.IParameterNode;
import org.apache.flex.compiler.tree.as.IReturnNode;
import org.apache.flex.compiler.tree.as.ISwitchNode;
import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
import org.apache.flex.compiler.tree.as.ITypeNode;
import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
@@ -105,6 +109,8 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
public DoWhileLoopEmitter doWhileLoopEmitter;
public ForLoopEmitter forLoopEmitter;
public IterationFlowEmitter interationFlowEmitter;
+ public TryEmitter tryEmitter;
+ public CatchEmitter catchEmitter;
public StatementEmitter statementEmitter;
public LanguageIdentifierEmitter languageIdentifierEmitter;
public SourceMapDirectiveEmitter sourceMapDirectiveEmitter;
@@ -152,6 +158,8 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
doWhileLoopEmitter = new DoWhileLoopEmitter(this);
forLoopEmitter = new ForLoopEmitter(this);
interationFlowEmitter = new IterationFlowEmitter(this);
+ tryEmitter = new TryEmitter(this);
+ catchEmitter = new CatchEmitter(this);
statementEmitter = new StatementEmitter(this);
languageIdentifierEmitter = new LanguageIdentifierEmitter(this);
sourceMapDirectiveEmitter = new SourceMapDirectiveEmitter(this);
@@ -238,6 +246,18 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
}
@Override
+ public void emitTry(ITryNode node)
+ {
+ tryEmitter.emit(node);
+ }
+
+ @Override
+ public void emitCatch(ICatchNode node)
+ {
+ catchEmitter.emit(node);
+ }
+
+ @Override
public void emitReturn(IReturnNode node)
{
returnEmitter.emit(node);
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91288abb/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/CatchEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/CatchEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/CatchEmitter.java
new file mode 100644
index 0000000..876593c
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/CatchEmitter.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.tree.as.ICatchNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
+
+public class CatchEmitter extends JSSubEmitter implements
+ ISubEmitter<ICatchNode>
+{
+ public CatchEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(ICatchNode node)
+ {
+ startMapping(node);
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.CATCH);
+ write(ASEmitterTokens.PAREN_OPEN);
+ endMapping(node);
+ IParameterNode paramNode = node.getCatchParameterNode();
+ getWalker().walk(paramNode);
+ startMapping(node, paramNode);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ endMapping(node);
+ getWalker().walk(node.getStatementContentsNode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91288abb/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/TryEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/TryEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/TryEmitter.java
new file mode 100644
index 0000000..268925b
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/TryEmitter.java
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.ITerminalNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
+
+public class TryEmitter extends JSSubEmitter implements
+ ISubEmitter<ITryNode>
+{
+ public TryEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(ITryNode node)
+ {
+ startMapping(node);
+ writeToken(ASEmitterTokens.TRY);
+ endMapping(node);
+ getWalker().walk(node.getStatementContentsNode());
+ for (int i = 0; i < node.getCatchNodeCount(); i++)
+ {
+ getWalker().walk(node.getCatchNode(i));
+ }
+ ITerminalNode fnode = node.getFinallyNode();
+ if (fnode != null)
+ {
+ startMapping(fnode);
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.FINALLY);
+ endMapping(fnode);
+ getWalker().walk(fnode);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91288abb/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
index 8eed245..a462d03 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
@@ -24,6 +24,7 @@ import org.apache.flex.compiler.internal.test.SourceMapTestBase;
import org.apache.flex.compiler.tree.as.IForLoopNode;
import org.apache.flex.compiler.tree.as.IIfNode;
import org.apache.flex.compiler.tree.as.ISwitchNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
import org.apache.flex.compiler.tree.as.IVariableNode;
import org.junit.Test;
@@ -205,6 +206,94 @@ public class TestSourceMapStatements extends SourceMapTestBase
}
//----------------------------------
+ // try {} catch () {} finally {}
+ //----------------------------------
+
+ @Test
+ public void testVisitTry_Catch()
+ {
+ ITryNode node = (ITryNode) getNode("try { a; } catch (e:Error) { b; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ //try {\n a;\n} catch (e) {\n b;\n}
+ assertMapping(node, 0, 0, 0, 0, 0, 4); // try
+ assertMapping(node, 0, 4, 0, 4, 0, 5); // {
+ assertMapping(node, 0, 9, 2, 0, 2, 1); // }
+ assertMapping(node, 0, 11, 2, 1, 2, 9); // catch(
+ assertMapping(node, 0, 18, 2, 9, 2, 10); // e
+ assertMapping(node, 0, 25, 2, 10, 2, 12); // )
+ assertMapping(node, 0, 27, 2, 12, 2, 13); // {
+ assertMapping(node, 0, 32, 4, 0, 4, 1); // }
+ }
+
+ @Test
+ public void testVisitTry_Catch_Finally()
+ {
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { b; } finally { c; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ //try {\n a;\n} catch (e) {\n b;\n} finally {\n c;\n}
+ assertMapping(node, 0, 0, 0, 0, 0, 4); // try
+ assertMapping(node, 0, 4, 0, 4, 0, 5); // {
+ assertMapping(node, 0, 9, 2, 0, 2, 1); // }
+ assertMapping(node, 0, 11, 2, 1, 2, 9); // catch(
+ assertMapping(node, 0, 18, 2, 9, 2, 10); // e
+ assertMapping(node, 0, 25, 2, 10, 2, 12); // )
+ assertMapping(node, 0, 27, 2, 12, 2, 13); // {
+ assertMapping(node, 0, 32, 4, 0, 4, 1); // }
+ assertMapping(node, 0, 34, 4, 1, 4, 10); // finally
+ assertMapping(node, 0, 42, 4, 10, 4, 11); // {
+ assertMapping(node, 0, 47, 6, 0, 6, 1); // }
+ }
+
+ @Test
+ public void testVisitTry_Catch_Catch_Finally()
+ {
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { b; } catch (f:Error) { c; } finally { d; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ //try {\n a;\n} catch (e) {\n b;\n} catch (f) {\n c;\n} finally {\n d;\n}
+ assertMapping(node, 0, 0, 0, 0, 0, 4); // try
+ assertMapping(node, 0, 4, 0, 4, 0, 5); // {
+ assertMapping(node, 0, 9, 2, 0, 2, 1); // }
+ assertMapping(node, 0, 11, 2, 1, 2, 9); // catch(
+ assertMapping(node, 0, 18, 2, 9, 2, 10); // e
+ assertMapping(node, 0, 25, 2, 10, 2, 12); // )
+ assertMapping(node, 0, 27, 2, 12, 2, 13); // {
+ assertMapping(node, 0, 32, 4, 0, 4, 1); // }
+ assertMapping(node, 0, 34, 4, 1, 4, 9); // catch(
+ assertMapping(node, 0, 41, 4, 9, 4, 10); // f
+ assertMapping(node, 0, 48, 4, 10, 4, 12); // )
+ assertMapping(node, 0, 50, 4, 12, 4, 13); // {
+ assertMapping(node, 0, 55, 6, 0, 6, 1); // }
+ assertMapping(node, 0, 57, 6, 1, 6, 10); // finally
+ assertMapping(node, 0, 65, 6, 10, 6, 11); // {
+ assertMapping(node, 0, 70, 8, 0, 8, 1); // }
+ }
+
+ @Test
+ public void testVisitTry_CatchEmpty_FinallyEmpty_()
+ {
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { } finally { }", ITryNode.class);
+ asBlockWalker.visitTry(node);
+ //try {\n a;\n} catch (e) {\n} finally {\n}
+ assertMapping(node, 0, 0, 0, 0, 0, 4); // try
+ assertMapping(node, 0, 4, 0, 4, 0, 5); // {
+ assertMapping(node, 0, 9, 2, 0, 2, 1); // }
+ assertMapping(node, 0, 11, 2, 1, 2, 9); // catch(
+ assertMapping(node, 0, 18, 2, 9, 2, 10); // e
+ assertMapping(node, 0, 25, 2, 10, 2, 12); // )
+ assertMapping(node, 0, 27, 2, 12, 2, 13); // {
+ assertMapping(node, 0, 30, 3, 0, 3, 1); // }
+ assertMapping(node, 0, 32, 3, 1, 3, 10); // finally
+ assertMapping(node, 0, 40, 3, 10, 3, 11); // {
+ assertMapping(node, 0, 43, 4, 0, 4, 1); // }
+ }
+
+ //----------------------------------
// switch {}
//----------------------------------