added source maps for for loop, and renamed emitters for while and do-while loops
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c759afdf Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c759afdf Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c759afdf Branch: refs/heads/develop Commit: c759afdfc4f3ac1128b7a0d7a08dbf40b2b0dfa3 Parents: d89a0b2 Author: Josh Tynjala <[email protected]> Authored: Fri Apr 8 13:55:45 2016 -0700 Committer: Josh Tynjala <[email protected]> Committed: Fri Apr 8 13:55:45 2016 -0700 ---------------------------------------------------------------------- .../js/sourcemaps/TestSourceMapStatements.java | 69 ++++++++++++++ .../compiler/internal/codegen/js/JSEmitter.java | 26 +++-- .../internal/codegen/js/jx/DoWhileEmitter.java | 71 -------------- .../codegen/js/jx/DoWhileLoopEmitter.java | 71 ++++++++++++++ .../internal/codegen/js/jx/ForLoopEmitter.java | 99 ++++++++++++++++++++ .../internal/codegen/js/jx/WhileEmitter.java | 61 ------------ .../codegen/js/jx/WhileLoopEmitter.java | 61 ++++++++++++ 7 files changed, 318 insertions(+), 140 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java index 713c3cf..3c25d07 100644 --- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java +++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java @@ -3,6 +3,7 @@ package org.apache.flex.compiler.internal.codegen.js.sourcemaps; import org.apache.flex.compiler.driver.IBackend; import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend; import org.apache.flex.compiler.internal.test.SourceMapTestBase; +import org.apache.flex.compiler.tree.as.IForLoopNode; import org.apache.flex.compiler.tree.as.IVariableNode; import org.junit.Test; @@ -95,6 +96,74 @@ public class TestSourceMapStatements extends SourceMapTestBase assertMapping(node, 0, 35, 0, 89, 0, 91); // 42 } + //---------------------------------- + // for () { } + //---------------------------------- + + @Test + public void testVisitFor_1a() + { + IForLoopNode node = (IForLoopNode) getNode( + "for (var i:int = 0; i < len; i++) { break; }", + IForLoopNode.class); + asBlockWalker.visitForLoop(node); + //for (var /** @type {number} */ i = 0; i < len; i++) {\n break;\n} + assertMapping(node, 0, 0, 0, 0, 0, 5); // for ( + assertMapping(node, 0, 18, 0, 36, 0, 38); // ; + assertMapping(node, 0, 27, 0, 45, 0, 47); // ; + assertMapping(node, 0, 32, 0, 50, 0, 52); // ) + } + + @Test + public void testVisitFor_1b() + { + IForLoopNode node = (IForLoopNode) getNode( + "for (var i:int = 0; i < len; i++) break;", IForLoopNode.class); + asBlockWalker.visitForLoop(node); + //for (var /** @type {number} */ i = 0; i < len; i++)\n break; + assertMapping(node, 0, 0, 0, 0, 0, 5); // for ( + assertMapping(node, 0, 18, 0, 36, 0, 38); // ; + assertMapping(node, 0, 27, 0, 45, 0, 47); // ; + assertMapping(node, 0, 32, 0, 50, 0, 51); // ) + } + + @Test + public void testVisitFor_2() + { + IForLoopNode node = (IForLoopNode) getNode("for (;;) { break; }", + IForLoopNode.class); + asBlockWalker.visitForLoop(node); + //for (;;) {\n break;\n} + assertMapping(node, 0, 0, 0, 0, 0, 5); // for ( + assertMapping(node, 0, 5, 0, 5, 0, 6); // ; + assertMapping(node, 0, 6, 0, 6, 0, 7); // ; + assertMapping(node, 0, 7, 0, 7, 0, 9); // ) + } + + @Test + public void testVisitForIn_1() + { + IForLoopNode node = (IForLoopNode) getNode( + "for (var i:int in obj) { break; }", IForLoopNode.class); + asBlockWalker.visitForLoop(node); + //for (var /** @type {number} */ i in obj) {\n break;\n} + assertMapping(node, 0, 0, 0, 0, 0, 5); // for ( + assertMapping(node, 0, 14, 0, 32, 0, 36); // in + assertMapping(node, 0, 21, 0, 39, 0, 41); // ) + } + + @Test + public void testVisitForIn_1a() + { + IForLoopNode node = (IForLoopNode) getNode( + "for (var i:int in obj) break; ", IForLoopNode.class); + asBlockWalker.visitForLoop(node); + //for (var /** @type {number} */ i in obj)\n break; + assertMapping(node, 0, 0, 0, 0, 0, 5); // for ( + assertMapping(node, 0, 14, 0, 32, 0, 36); // in + assertMapping(node, 0, 21, 0, 39, 0, 40); // ) + } + protected IBackend createBackend() { return new FlexJSBackend(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java index 589cbaf..65a8e63 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java @@ -30,8 +30,9 @@ import org.apache.flex.compiler.common.ISourceLocation; import org.apache.flex.compiler.definitions.ITypeDefinition; 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.DoWhileEmitter; +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; import org.apache.flex.compiler.internal.codegen.js.jx.FunctionCallArgumentsEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.IfEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.IterationFlowEmitter; @@ -45,13 +46,14 @@ import org.apache.flex.compiler.internal.codegen.js.jx.ReturnEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.SourceMapDirectiveEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.TernaryOperatorEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.UnaryOperatorEmitter; -import org.apache.flex.compiler.internal.codegen.js.jx.WhileEmitter; +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.IContainerNode; import org.apache.flex.compiler.tree.as.IDefinitionNode; import org.apache.flex.compiler.tree.as.IDynamicAccessNode; +import org.apache.flex.compiler.tree.as.IForLoopNode; import org.apache.flex.compiler.tree.as.IFunctionNode; import org.apache.flex.compiler.tree.as.IFunctionObjectNode; import org.apache.flex.compiler.tree.as.IIfNode; @@ -89,8 +91,9 @@ public class JSEmitter extends ASEmitter implements IJSEmitter public TernaryOperatorEmitter ternaryOperatorEmitter; public MemberKeywordEmitter memberKeywordEmitter; public IfEmitter ifEmitter; - public WhileEmitter whileEmitter; - public DoWhileEmitter doWhileEmitter; + public WhileLoopEmitter whileLoopEmitter; + public DoWhileLoopEmitter doWhileLoopEmitter; + public ForLoopEmitter forLoopEmitter; public IterationFlowEmitter interationFlowEmitter; public SourceMapDirectiveEmitter sourceMapDirectiveEmitter; @@ -130,8 +133,9 @@ public class JSEmitter extends ASEmitter implements IJSEmitter ternaryOperatorEmitter = new TernaryOperatorEmitter(this); memberKeywordEmitter = new MemberKeywordEmitter(this); ifEmitter = new IfEmitter(this); - whileEmitter = new WhileEmitter(this); - doWhileEmitter = new DoWhileEmitter(this); + whileLoopEmitter = new WhileLoopEmitter(this); + doWhileLoopEmitter = new DoWhileLoopEmitter(this); + forLoopEmitter = new ForLoopEmitter(this); interationFlowEmitter = new IterationFlowEmitter(this); sourceMapDirectiveEmitter = new SourceMapDirectiveEmitter(this); } @@ -261,13 +265,19 @@ public class JSEmitter extends ASEmitter implements IJSEmitter @Override public void emitWhileLoop(IWhileLoopNode node) { - whileEmitter.emit(node); + whileLoopEmitter.emit(node); } @Override public void emitDoLoop(IWhileLoopNode node) { - doWhileEmitter.emit(node); + doWhileLoopEmitter.emit(node); + } + + @Override + public void emitForLoop(IForLoopNode node) + { + forLoopEmitter.emit(node); } @Override http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileEmitter.java deleted file mode 100644 index 4dfafac..0000000 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileEmitter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * 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.utils.EmitterUtils; -import org.apache.flex.compiler.tree.as.IASNode; -import org.apache.flex.compiler.tree.as.IContainerNode; -import org.apache.flex.compiler.tree.as.IWhileLoopNode; - -public class DoWhileEmitter extends JSSubEmitter implements - ISubEmitter<IWhileLoopNode> -{ - public DoWhileEmitter(IJSEmitter emitter) - { - super(emitter); - } - - @Override - public void emit(IWhileLoopNode node) - { - IContainerNode cnode = (IContainerNode) node.getChild(0); - - startMapping(node); - write(ASEmitterTokens.DO); - if (!EmitterUtils.isImplicit(cnode)) - write(ASEmitterTokens.SPACE); - endMapping(node); - - IASNode statementContents = node.getStatementContentsNode(); - getWalker().walk(statementContents); - - IASNode conditionalExpressionNode = node.getConditionalExpressionNode(); - startMapping(node, statementContents); - if (!EmitterUtils.isImplicit(cnode)) - write(ASEmitterTokens.SPACE); - else - writeNewline(); // TODO (mschmalle) there is something wrong here, block should NL - write(ASEmitterTokens.WHILE); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - - getWalker().walk(conditionalExpressionNode); - - startMapping(node, conditionalExpressionNode); - write(ASEmitterTokens.PAREN_CLOSE); - write(ASEmitterTokens.SEMICOLON); - endMapping(node); - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java new file mode 100644 index 0000000..e087bcd --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java @@ -0,0 +1,71 @@ +/* + * + * 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.utils.EmitterUtils; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode; + +public class DoWhileLoopEmitter extends JSSubEmitter implements + ISubEmitter<IWhileLoopNode> +{ + public DoWhileLoopEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IWhileLoopNode node) + { + IContainerNode cnode = (IContainerNode) node.getChild(0); + + startMapping(node); + write(ASEmitterTokens.DO); + if (!EmitterUtils.isImplicit(cnode)) + write(ASEmitterTokens.SPACE); + endMapping(node); + + IASNode statementContents = node.getStatementContentsNode(); + getWalker().walk(statementContents); + + IASNode conditionalExpressionNode = node.getConditionalExpressionNode(); + startMapping(node, statementContents); + if (!EmitterUtils.isImplicit(cnode)) + write(ASEmitterTokens.SPACE); + else + writeNewline(); // TODO (mschmalle) there is something wrong here, block should NL + write(ASEmitterTokens.WHILE); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + getWalker().walk(conditionalExpressionNode); + + startMapping(node, conditionalExpressionNode); + write(ASEmitterTokens.PAREN_CLOSE); + write(ASEmitterTokens.SEMICOLON); + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java new file mode 100644 index 0000000..567b029 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java @@ -0,0 +1,99 @@ +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.utils.EmitterUtils; +import org.apache.flex.compiler.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IForLoopNode; + +public class ForLoopEmitter extends JSSubEmitter implements + ISubEmitter<IForLoopNode> +{ + public ForLoopEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IForLoopNode node) + { + IContainerNode xnode = (IContainerNode) node.getChild(1); + + startMapping(node); + writeToken(ASEmitterTokens.FOR); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + IContainerNode cnode = node.getConditionalsContainerNode(); + final IASNode node0 = cnode.getChild(0); + if (node0.getNodeID() == ASTNodeID.Op_InID) + { + //for(in) + getWalker().walk(cnode.getChild(0)); + } + else //for(;;) + { + emitForStatements(cnode); + } + + startMapping(node, cnode); + write(ASEmitterTokens.PAREN_CLOSE); + if (!EmitterUtils.isImplicit(xnode)) + write(ASEmitterTokens.SPACE); + endMapping(node); + + getWalker().walk(node.getStatementContentsNode()); + } + + protected void emitForStatements(IContainerNode node) + { + final IASNode node0 = node.getChild(0); + final IASNode node1 = node.getChild(1); + final IASNode node2 = node.getChild(2); + + int column = node.getColumn(); + // initializer + if (node0 != null) + { + getWalker().walk(node0); + + if (node1.getNodeID() != ASTNodeID.NilID) + { + column += node0.getAbsoluteEnd() - node0.getAbsoluteStart(); + } + startMapping(node, node.getLine(), column); + write(ASEmitterTokens.SEMICOLON); + column++; + if (node1.getNodeID() != ASTNodeID.NilID) + { + write(ASEmitterTokens.SPACE); + column++; + } + endMapping(node); + } + // condition or target + if (node1 != null) + { + getWalker().walk(node1); + + if (node1.getNodeID() != ASTNodeID.NilID) + { + column += node1.getAbsoluteEnd() - node1.getAbsoluteStart(); + } + startMapping(node, node.getLine(), column); + write(ASEmitterTokens.SEMICOLON); + if (node2.getNodeID() != ASTNodeID.NilID) + write(ASEmitterTokens.SPACE); + endMapping(node); + } + // iterator + if (node2 != null) + { + getWalker().walk(node2); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileEmitter.java deleted file mode 100644 index 8ff0e84..0000000 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileEmitter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * 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.utils.EmitterUtils; -import org.apache.flex.compiler.tree.as.IASNode; -import org.apache.flex.compiler.tree.as.IContainerNode; -import org.apache.flex.compiler.tree.as.IWhileLoopNode; - -public class WhileEmitter extends JSSubEmitter implements - ISubEmitter<IWhileLoopNode> -{ - public WhileEmitter(IJSEmitter emitter) - { - super(emitter); - } - - @Override - public void emit(IWhileLoopNode node) - { - IContainerNode cnode = (IContainerNode) node.getChild(1); - - startMapping(node); - writeToken(ASEmitterTokens.WHILE); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - - IASNode conditionalExpression = node.getConditionalExpressionNode(); - getWalker().walk(conditionalExpression); - - IASNode statementContentsNode = node.getStatementContentsNode(); - startMapping(node, conditionalExpression); - write(ASEmitterTokens.PAREN_CLOSE); - if (!EmitterUtils.isImplicit(cnode)) - write(ASEmitterTokens.SPACE); - endMapping(node); - - getWalker().walk(statementContentsNode); - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c759afdf/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileLoopEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileLoopEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileLoopEmitter.java new file mode 100644 index 0000000..54f663d --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileLoopEmitter.java @@ -0,0 +1,61 @@ +/* + * + * 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.utils.EmitterUtils; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode; + +public class WhileLoopEmitter extends JSSubEmitter implements + ISubEmitter<IWhileLoopNode> +{ + public WhileLoopEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IWhileLoopNode node) + { + IContainerNode cnode = (IContainerNode) node.getChild(1); + + startMapping(node); + writeToken(ASEmitterTokens.WHILE); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + IASNode conditionalExpression = node.getConditionalExpressionNode(); + getWalker().walk(conditionalExpression); + + IASNode statementContentsNode = node.getStatementContentsNode(); + startMapping(node, conditionalExpression); + write(ASEmitterTokens.PAREN_CLOSE); + if (!EmitterUtils.isImplicit(cnode)) + write(ASEmitterTokens.SPACE); + endMapping(node); + + getWalker().walk(statementContentsNode); + } +}
