moved overrides in JSEmitter into JSSubEmitter implementations
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c3b8a2b8 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c3b8a2b8 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c3b8a2b8 Branch: refs/heads/develop Commit: c3b8a2b8ccfbee3d97913a590a735091875549b0 Parents: 4256628 Author: Josh Tynjala <[email protected]> Authored: Tue Apr 5 16:35:59 2016 -0700 Committer: Josh Tynjala <[email protected]> Committed: Tue Apr 5 16:35:59 2016 -0700 ---------------------------------------------------------------------- .../compiler/internal/codegen/as/ASEmitter.java | 59 +-- .../compiler/internal/codegen/js/JSEmitter.java | 454 +++---------------- .../internal/codegen/js/JSSubEmitter.java | 21 + .../internal/codegen/js/jx/DoWhileEmitter.java | 71 +++ .../codegen/js/jx/DynamicAccessEmitter.java | 54 +++ .../js/jx/FunctionCallArgumentsEmitter.java | 64 +++ .../internal/codegen/js/jx/IfEmitter.java | 117 +++++ .../codegen/js/jx/IterationFlowEmitter.java | 54 +++ .../codegen/js/jx/LiteralContainerEmitter.java | 96 ++++ .../codegen/js/jx/MemberKeywordEmitter.java | 70 +++ .../codegen/js/jx/NumericLiteralEmitter.java | 43 ++ .../js/jx/ObjectLiteralValuePairEmitter.java | 62 +++ .../codegen/js/jx/ParameterEmitter.java | 62 +++ .../codegen/js/jx/ParametersEmitter.java | 64 +++ .../internal/codegen/js/jx/ReturnEmitter.java | 57 +++ .../js/jx/SourceMapDirectiveEmitter.java | 60 +++ .../codegen/js/jx/TernaryOperatorEmitter.java | 67 +++ .../codegen/js/jx/UnaryOperatorEmitter.java | 122 +++++ .../internal/codegen/js/jx/WhileEmitter.java | 61 +++ .../internal/codegen/js/utils/EmitterUtils.java | 6 + 20 files changed, 1236 insertions(+), 428 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java index 309d156..1c4036e 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java @@ -1256,8 +1256,7 @@ public class ASEmitter implements IASEmitter, IEmitter protected static final boolean isImplicit(IContainerNode node) { - return node.getContainerType() == ContainerType.IMPLICIT - || node.getContainerType() == ContainerType.SYNTHESIZED; + return EmitterUtils.isImplicit(node); } protected void visitForBody(IContainerNode node) @@ -1452,63 +1451,35 @@ public class ASEmitter implements IASEmitter, IEmitter || node.getNodeID() == ASTNodeID.Op_SubtractID || node.getNodeID() == ASTNodeID.Op_AddID) { - emitPreUnaryOperator(node); + write(node.getOperator().getOperatorText()); + IExpressionNode opNode = node.getOperandNode(); + getWalker().walk(opNode); } + else if (node.getNodeID() == ASTNodeID.Op_PostIncrID || node.getNodeID() == ASTNodeID.Op_PostDecrID) { - emitPostUnaryOperator(node); - } - else if (node.getNodeID() == ASTNodeID.Op_DeleteID) - { - emitDeleteOperator(node); + getWalker().walk(node.getOperandNode()); + write(node.getOperator().getOperatorText()); } - else if (node.getNodeID() == ASTNodeID.Op_VoidID) + else if (node.getNodeID() == ASTNodeID.Op_DeleteID + || node.getNodeID() == ASTNodeID.Op_VoidID) { - emitVoidOperator(node); + writeToken(node.getOperator().getOperatorText()); + getWalker().walk(node.getOperandNode()); } else if (node.getNodeID() == ASTNodeID.Op_TypeOfID) { - emitTypeOfOperator(node); + write(node.getOperator().getOperatorText()); + write(ASEmitterTokens.PAREN_OPEN); + getWalker().walk(node.getOperandNode()); + write(ASEmitterTokens.PAREN_CLOSE); } if (ASNodeUtils.hasParenClose(node)) write(ASEmitterTokens.PAREN_CLOSE); } - public void emitPreUnaryOperator(IUnaryOperatorNode node) - { - write(node.getOperator().getOperatorText()); - IExpressionNode opNode = node.getOperandNode(); - getWalker().walk(opNode); - } - - public void emitPostUnaryOperator(IUnaryOperatorNode node) - { - getWalker().walk(node.getOperandNode()); - write(node.getOperator().getOperatorText()); - } - - public void emitDeleteOperator(IUnaryOperatorNode node) - { - writeToken(node.getOperator().getOperatorText()); - getWalker().walk(node.getOperandNode()); - } - - public void emitVoidOperator(IUnaryOperatorNode node) - { - writeToken(node.getOperator().getOperatorText()); - getWalker().walk(node.getOperandNode()); - } - - public void emitTypeOfOperator(IUnaryOperatorNode node) - { - write(node.getOperator().getOperatorText()); - write(ASEmitterTokens.PAREN_OPEN); - getWalker().walk(node.getOperandNode()); - write(ASEmitterTokens.PAREN_CLOSE); - } - @Override public void emitLanguageIdentifier(ILanguageIdentifierNode node) { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/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 6839f9e..589cbaf 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 @@ -24,45 +24,49 @@ import java.util.ArrayList; import java.util.List; import java.util.Stack; -import org.apache.flex.compiler.clients.JSConfiguration; import org.apache.flex.compiler.codegen.js.IJSEmitter; import org.apache.flex.compiler.common.ASModifier; 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.DynamicAccessEmitter; +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; +import org.apache.flex.compiler.internal.codegen.js.jx.LiteralContainerEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.MemberKeywordEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.NumericLiteralEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.ObjectLiteralValuePairEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.ParameterEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.ParametersEmitter; +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.utils.EmitterUtils; -import org.apache.flex.compiler.internal.projects.FlexJSProject; import org.apache.flex.compiler.internal.tree.as.FunctionNode; -import org.apache.flex.compiler.tree.ASTNodeID; import org.apache.flex.compiler.tree.as.IASNode; -import org.apache.flex.compiler.tree.as.IConditionalNode; 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.IExpressionNode; import org.apache.flex.compiler.tree.as.IFunctionNode; import org.apache.flex.compiler.tree.as.IFunctionObjectNode; -import org.apache.flex.compiler.tree.as.IIdentifierNode; +import org.apache.flex.compiler.tree.as.IIfNode; import org.apache.flex.compiler.tree.as.IIterationFlowNode; -import org.apache.flex.compiler.tree.as.IKeywordNode; import org.apache.flex.compiler.tree.as.ILiteralContainerNode; -import org.apache.flex.compiler.tree.as.ILiteralNode; import org.apache.flex.compiler.tree.as.INumericLiteralNode; import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode; -import org.apache.flex.compiler.tree.as.IOperatorNode; import org.apache.flex.compiler.tree.as.IPackageNode; import org.apache.flex.compiler.tree.as.IParameterNode; import org.apache.flex.compiler.tree.as.IReturnNode; -import org.apache.flex.compiler.tree.as.ITerminalNode; import org.apache.flex.compiler.tree.as.ITernaryOperatorNode; import org.apache.flex.compiler.tree.as.ITypeNode; import org.apache.flex.compiler.tree.as.ITypedExpressionNode; import org.apache.flex.compiler.tree.as.IUnaryOperatorNode; -import org.apache.flex.compiler.tree.as.IVariableNode; import org.apache.flex.compiler.tree.as.IWhileLoopNode; -import org.apache.flex.compiler.utils.ASNodeUtils; -import org.apache.flex.compiler.visitor.IBlockWalker; import com.google.debugging.sourcemap.FilePosition; @@ -73,6 +77,23 @@ public class JSEmitter extends ASEmitter implements IJSEmitter { private JSSessionModel model; + public NumericLiteralEmitter numericLiteralEmitter; + public ParametersEmitter parametersEmitter; + public ParameterEmitter parameterEmitter; + public FunctionCallArgumentsEmitter functionCallArgumentsEmitter; + public LiteralContainerEmitter literalContainerEmitter; + public ObjectLiteralValuePairEmitter objectLiteralValuePairEmitter; + public ReturnEmitter returnEmitter; + public DynamicAccessEmitter dynamicAccessEmitter; + public UnaryOperatorEmitter unaryOperatorEmitter; + public TernaryOperatorEmitter ternaryOperatorEmitter; + public MemberKeywordEmitter memberKeywordEmitter; + public IfEmitter ifEmitter; + public WhileEmitter whileEmitter; + public DoWhileEmitter doWhileEmitter; + public IterationFlowEmitter interationFlowEmitter; + public SourceMapDirectiveEmitter sourceMapDirectiveEmitter; + @Override public JSSessionModel getModel() { @@ -96,6 +117,23 @@ public class JSEmitter extends ASEmitter implements IJSEmitter model = new JSSessionModel(); sourceMapMappings = new ArrayList<SourceMapMapping>(); + + numericLiteralEmitter = new NumericLiteralEmitter(this); + parametersEmitter = new ParametersEmitter(this); + parameterEmitter = new ParameterEmitter(this); + functionCallArgumentsEmitter = new FunctionCallArgumentsEmitter(this); + literalContainerEmitter = new LiteralContainerEmitter(this); + objectLiteralValuePairEmitter = new ObjectLiteralValuePairEmitter(this); + returnEmitter = new ReturnEmitter(this); + dynamicAccessEmitter = new DynamicAccessEmitter(this); + unaryOperatorEmitter = new UnaryOperatorEmitter(this); + ternaryOperatorEmitter = new TernaryOperatorEmitter(this); + memberKeywordEmitter = new MemberKeywordEmitter(this); + ifEmitter = new IfEmitter(this); + whileEmitter = new WhileEmitter(this); + doWhileEmitter = new DoWhileEmitter(this); + interationFlowEmitter = new IterationFlowEmitter(this); + sourceMapDirectiveEmitter = new SourceMapDirectiveEmitter(this); } @Override @@ -140,198 +178,48 @@ public class JSEmitter extends ASEmitter implements IJSEmitter public void emitSourceMapDirective(ITypeNode node) { - boolean sourceMap = false; - - IBlockWalker walker = getWalker(); - FlexJSProject project = (FlexJSProject) walker.getProject(); - if (project != null) - { - JSConfiguration config = project.config; - if (config != null) - { - sourceMap = config.getSourceMap(); - } - } - - if (sourceMap) - { - writeNewline(); - write("//# sourceMappingURL=./" + node.getName() + ".js.map"); - } + sourceMapDirectiveEmitter.emit(node); } public void emitParameters(IContainerNode node) { - startMapping(node); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - - int len = node.getChildCount(); - for (int i = 0; i < len; i++) - { - IParameterNode parameterNode = (IParameterNode) node.getChild(i); - getWalker().walk(parameterNode); //emitParameter - if (i < len - 1) - { - //we're mapping the comma to the container, but we use the - //parameter line/column in case the comma is not on the same - //line as the opening ( - startMapping(node, parameterNode); - writeToken(ASEmitterTokens.COMMA); - endMapping(node); - } - } - - startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); - write(ASEmitterTokens.PAREN_CLOSE); - endMapping(node); + parametersEmitter.emit(node); } @Override public void emitParameter(IParameterNode node) { - startMapping(node); - super.emitParameter(node); - endMapping(node); + parameterEmitter.emit(node); } @Override public void emitArguments(IContainerNode node) { - startMapping(node); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - - int len = node.getChildCount(); - for (int i = 0; i < len; i++) - { - IExpressionNode argumentNode = (IExpressionNode) node.getChild(i); - getWalker().walk(argumentNode); - if (i < len - 1) - { - //we're mapping the comma to the container, but we use the - //parameter line/column in case the comma is not on the same - //line as the opening ( - startMapping(node, argumentNode); - writeToken(ASEmitterTokens.COMMA); - endMapping(node); - } - } - - startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); - write(ASEmitterTokens.PAREN_CLOSE); - endMapping(node); + functionCallArgumentsEmitter.emit(node); } @Override public void emitNumericLiteral(INumericLiteralNode node) { - startMapping((ISourceLocation) node); - super.emitNumericLiteral(node); - endMapping((ISourceLocation) node); + numericLiteralEmitter.emit(node); } @Override public void emitLiteralContainer(ILiteralContainerNode node) { - final IContainerNode cnode = node.getContentsNode(); - final IContainerNode.ContainerType type = cnode.getContainerType(); - String preFix = null; - String postFix = null; - - if (type == IContainerNode.ContainerType.BRACES) - { - preFix = ASEmitterTokens.BLOCK_OPEN.getToken(); - postFix = ASEmitterTokens.BLOCK_CLOSE.getToken(); - } - else if (type == IContainerNode.ContainerType.BRACKETS) - { - preFix = ASEmitterTokens.SQUARE_OPEN.getToken(); - postFix = ASEmitterTokens.SQUARE_CLOSE.getToken(); - } - else if (type == IContainerNode.ContainerType.IMPLICIT) - { - // nothing to write, move along - } - else if (type == IContainerNode.ContainerType.PARENTHESIS) - { - preFix = ASEmitterTokens.PAREN_OPEN.getToken(); - postFix = ASEmitterTokens.PAREN_CLOSE.getToken(); - } - - if (preFix != null) - { - startMapping(node); - write(preFix); - endMapping(node); - } - - final int len = cnode.getChildCount(); - for (int i = 0; i < len; i++) - { - IASNode child = cnode.getChild(i); - getWalker().walk(child); - if (i < len - 1) - { - //we're mapping the comma to the literal container, but we fill - //the space between the current child and the next because we - //don't know exactly where the comma appears in ActionScript - startMapping(node, child); - writeToken(ASEmitterTokens.COMMA); - endMapping(node); - } - } - - if (postFix != null) - { - startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); - write(postFix); - endMapping(node); - } + literalContainerEmitter.emit(node); } @Override public void emitObjectLiteralValuePair(IObjectLiteralValuePairNode node) { - ISourceLocation sourceLocationNode = (ISourceLocation) node; - - IExpressionNode nameNode = node.getNameNode(); - if (!(nameNode instanceof ILiteralNode)) - { - startMapping(nameNode); - } - getWalker().walk(node.getNameNode()); - if (!(nameNode instanceof ILiteralNode)) - { - endMapping(nameNode); - } - - startMapping(sourceLocationNode, nameNode); - write(ASEmitterTokens.COLON); - endMapping(sourceLocationNode); - - IExpressionNode valueNode = node.getValueNode(); - getWalker().walk(valueNode); + objectLiteralValuePairEmitter.emit(node); } @Override public void emitReturn(IReturnNode node) { - IExpressionNode rnode = node.getReturnValueNode(); - boolean hasReturnValue = rnode != null && rnode.getNodeID() != ASTNodeID.NilID; - - startMapping(node); - write(ASEmitterTokens.RETURN); - if (hasReturnValue) - { - write(ASEmitterTokens.SPACE); - } - endMapping(node); - - if (hasReturnValue) - { - getWalker().walk(rnode); - } + returnEmitter.emit(node); } @Override @@ -343,251 +231,49 @@ public class JSEmitter extends ASEmitter implements IJSEmitter @Override public void emitDynamicAccess(IDynamicAccessNode node) { - IExpressionNode leftOperandNode = node.getLeftOperandNode(); - getWalker().walk(leftOperandNode); - - startMapping(node, leftOperandNode); - write(ASEmitterTokens.SQUARE_OPEN); - endMapping(node); - - IExpressionNode rightOperandNode = node.getRightOperandNode(); - getWalker().walk(rightOperandNode); - - startMapping(node, rightOperandNode); - write(ASEmitterTokens.SQUARE_CLOSE); - endMapping(node); + dynamicAccessEmitter.emit(node); } @Override public void emitMemberKeyword(IDefinitionNode node) { - IKeywordNode keywordNode = null; - for(int i = 0; i < node.getChildCount(); i++) - { - IASNode childNode = node.getChild(i); - if (childNode instanceof IKeywordNode) - { - keywordNode = (IKeywordNode) childNode; - break; - } - } - if (keywordNode != null) - { - startMapping(keywordNode); - } - if (node instanceof IFunctionNode) - { - writeToken(ASEmitterTokens.FUNCTION); - } - else if (node instanceof IVariableNode) - { - writeToken(ASEmitterTokens.VAR); - } - if (keywordNode != null) - { - endMapping(keywordNode); - } + memberKeywordEmitter.emit(node); } @Override - public void emitConditional(IConditionalNode node, boolean isElseIf) + public void emitUnaryOperator(IUnaryOperatorNode node) { - startMapping(node); - if (isElseIf) - { - writeToken(ASEmitterTokens.ELSE); - } - writeToken(ASEmitterTokens.IF); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - - IASNode conditionalExpression = node.getChild(0); - getWalker().walk(conditionalExpression); - - startMapping(node, conditionalExpression); - write(ASEmitterTokens.PAREN_CLOSE); - IContainerNode xnode = (IContainerNode) node.getStatementContentsNode(); - if (!isImplicit(xnode)) - write(ASEmitterTokens.SPACE); - endMapping(node); - - getWalker().walk(node.getChild(1)); // BlockNode + unaryOperatorEmitter.emit(node); } @Override - public void emitElse(ITerminalNode node) + public void emitTernaryOperator(ITernaryOperatorNode node) { - IContainerNode cnode = (IContainerNode) node.getChild(0); - - // if an implicit if, add a newline with no space - final boolean isImplicit = isImplicit(cnode); - if (isImplicit) - writeNewline(); - else - write(ASEmitterTokens.SPACE); - - startMapping(node); - write(ASEmitterTokens.ELSE); - if (!isImplicit) - write(ASEmitterTokens.SPACE); - endMapping(node); - - getWalker().walk(node); // TerminalNode + ternaryOperatorEmitter.emit(node); } @Override - public void emitTernaryOperator(ITernaryOperatorNode node) + public void emitIf(IIfNode node) { - if (ASNodeUtils.hasParenOpen((IOperatorNode) node)) - write(ASEmitterTokens.PAREN_OPEN); - - IExpressionNode conditionalNode = node.getConditionalNode(); - getWalker().walk(conditionalNode); - - IExpressionNode leftOperandNode = node.getLeftOperandNode(); - startMapping(node, conditionalNode); - write(ASEmitterTokens.SPACE); - writeToken(ASEmitterTokens.TERNARY); - endMapping(node); - - getWalker().walk(leftOperandNode); - - IExpressionNode rightOperandNode = node.getRightOperandNode(); - startMapping(node, leftOperandNode); - write(ASEmitterTokens.SPACE); - writeToken(ASEmitterTokens.COLON); - endMapping(node); - - getWalker().walk(rightOperandNode); - - if (ASNodeUtils.hasParenClose((IOperatorNode) node)) - write(ASEmitterTokens.PAREN_CLOSE); + ifEmitter.emit(node); } @Override public void emitWhileLoop(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 (!isImplicit(cnode)) - write(ASEmitterTokens.SPACE); - endMapping(node); - - getWalker().walk(statementContentsNode); + whileEmitter.emit(node); } @Override public void emitDoLoop(IWhileLoopNode node) { - IContainerNode cnode = (IContainerNode) node.getChild(0); - - startMapping(node); - write(ASEmitterTokens.DO); - if (!isImplicit(cnode)) - write(ASEmitterTokens.SPACE); - endMapping(node); - - IASNode statementContents = node.getStatementContentsNode(); - getWalker().walk(statementContents); - - IASNode conditionalExpressionNode = node.getConditionalExpressionNode(); - startMapping(node, statementContents); - if (!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); - } - - @Override - public void emitPreUnaryOperator(IUnaryOperatorNode node) - { - startMapping(node); - write(node.getOperator().getOperatorText()); - IExpressionNode opNode = node.getOperandNode(); - endMapping(node); - getWalker().walk(opNode); - } - - @Override - public void emitPostUnaryOperator(IUnaryOperatorNode node) - { - IExpressionNode operandNode = node.getOperandNode(); - getWalker().walk(operandNode); - startMapping(node, operandNode); - write(node.getOperator().getOperatorText()); - endMapping(node); - } - - @Override - public void emitDeleteOperator(IUnaryOperatorNode node) - { - startMapping(node); - writeToken(node.getOperator().getOperatorText()); - endMapping(node); - getWalker().walk(node.getOperandNode()); - } - - @Override - public void emitVoidOperator(IUnaryOperatorNode node) - { - startMapping(node); - writeToken(node.getOperator().getOperatorText()); - endMapping(node); - getWalker().walk(node.getOperandNode()); - } - - @Override - public void emitTypeOfOperator(IUnaryOperatorNode node) - { - startMapping(node); - write(node.getOperator().getOperatorText()); - write(ASEmitterTokens.PAREN_OPEN); - endMapping(node); - IExpressionNode operandNode = node.getOperandNode(); - getWalker().walk(operandNode); - startMapping(node); - write(ASEmitterTokens.PAREN_CLOSE); - endMapping(node); + doWhileEmitter.emit(node); } @Override public void emitIterationFlow(IIterationFlowNode node) { - startMapping(node); - write(node.getKind().toString().toLowerCase()); - IIdentifierNode lnode = node.getLabelNode(); - if (lnode != null) - { - write(ASEmitterTokens.SPACE); - endMapping(node); - getWalker().walk(lnode); - } - else - { - endMapping(node); - } + interationFlowEmitter.emit(node); } public void pushSourceMapName(ISourceLocation node) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java index e4a413f..be0b9d1 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java @@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.codegen.js; import org.apache.flex.compiler.codegen.IEmitterTokens; import org.apache.flex.compiler.codegen.js.IJSEmitter; +import org.apache.flex.compiler.common.ISourceLocation; import org.apache.flex.compiler.projects.ICompilerProject; import org.apache.flex.compiler.visitor.IBlockWalker; @@ -102,4 +103,24 @@ public class JSSubEmitter { emitter.indentPop(); } + + protected void startMapping(ISourceLocation node) + { + emitter.startMapping(node); + } + + protected void startMapping(ISourceLocation node, int line, int column) + { + emitter.startMapping(node, line, column); + } + + protected void startMapping(ISourceLocation node, ISourceLocation nodeBeforeMapping) + { + emitter.startMapping(node, nodeBeforeMapping); + } + + protected void endMapping(ISourceLocation node) + { + emitter.endMapping(node); + } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/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 new file mode 100644 index 0000000..4dfafac --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileEmitter.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 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/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java new file mode 100644 index 0000000..f02d298 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java @@ -0,0 +1,54 @@ +/* + * + * 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.IDynamicAccessNode; +import org.apache.flex.compiler.tree.as.IExpressionNode; + +public class DynamicAccessEmitter extends JSSubEmitter implements + ISubEmitter<IDynamicAccessNode> +{ + public DynamicAccessEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IDynamicAccessNode node) + { + IExpressionNode leftOperandNode = node.getLeftOperandNode(); + getWalker().walk(leftOperandNode); + + startMapping(node, leftOperandNode); + write(ASEmitterTokens.SQUARE_OPEN); + endMapping(node); + + IExpressionNode rightOperandNode = node.getRightOperandNode(); + getWalker().walk(rightOperandNode); + + startMapping(node, rightOperandNode); + write(ASEmitterTokens.SQUARE_CLOSE); + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java new file mode 100644 index 0000000..f875e92 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java @@ -0,0 +1,64 @@ +/* + * + * 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.IContainerNode; +import org.apache.flex.compiler.tree.as.IExpressionNode; + +public class FunctionCallArgumentsEmitter extends JSSubEmitter implements + ISubEmitter<IContainerNode> +{ + public FunctionCallArgumentsEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IContainerNode node) + { + startMapping(node); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + int len = node.getChildCount(); + for (int i = 0; i < len; i++) + { + IExpressionNode argumentNode = (IExpressionNode) node.getChild(i); + getWalker().walk(argumentNode); + if (i < len - 1) + { + //we're mapping the comma to the container, but we use the + //parameter line/column in case the comma is not on the same + //line as the opening ( + startMapping(node, argumentNode); + writeToken(ASEmitterTokens.COMMA); + endMapping(node); + } + } + + startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); + write(ASEmitterTokens.PAREN_CLOSE); + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java new file mode 100644 index 0000000..5370a95 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java @@ -0,0 +1,117 @@ +/* + * + * 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.IConditionalNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IIfNode; +import org.apache.flex.compiler.tree.as.ITerminalNode; + +public class IfEmitter extends JSSubEmitter implements + ISubEmitter<IIfNode> +{ + public IfEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IIfNode node) + { + IConditionalNode conditional = (IConditionalNode) node.getChild(0); + emitConditional(conditional, false); + + IConditionalNode[] nodes = node.getElseIfNodes(); + if (nodes.length > 0) + { + for (int i = 0; i < nodes.length; i++) + { + IConditionalNode enode = nodes[i]; + IContainerNode snode = (IContainerNode) enode + .getStatementContentsNode(); + + final boolean isImplicit = EmitterUtils.isImplicit(snode); + if (isImplicit) + writeNewline(); + else + write(ASEmitterTokens.SPACE); + + emitConditional(enode, true); + } + } + + ITerminalNode elseNode = node.getElseNode(); + if (elseNode != null) + { + emitElse(elseNode); + } + + } + + protected void emitConditional(IConditionalNode node, boolean isElseIf) + { + startMapping(node); + if (isElseIf) + { + writeToken(ASEmitterTokens.ELSE); + } + writeToken(ASEmitterTokens.IF); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + IASNode conditionalExpression = node.getChild(0); + getWalker().walk(conditionalExpression); + + startMapping(node, conditionalExpression); + write(ASEmitterTokens.PAREN_CLOSE); + IContainerNode xnode = (IContainerNode) node.getStatementContentsNode(); + if (!EmitterUtils.isImplicit(xnode)) + write(ASEmitterTokens.SPACE); + endMapping(node); + + getWalker().walk(node.getChild(1)); // BlockNode + } + + protected void emitElse(ITerminalNode node) + { + IContainerNode cnode = (IContainerNode) node.getChild(0); + + // if an implicit if, add a newline with no space + final boolean isImplicit = EmitterUtils.isImplicit(cnode); + if (isImplicit) + writeNewline(); + else + write(ASEmitterTokens.SPACE); + + startMapping(node); + write(ASEmitterTokens.ELSE); + if (!isImplicit) + write(ASEmitterTokens.SPACE); + endMapping(node); + + getWalker().walk(node); // TerminalNode + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java new file mode 100644 index 0000000..25c2d10 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java @@ -0,0 +1,54 @@ +/* + * + * 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.IIdentifierNode; +import org.apache.flex.compiler.tree.as.IIterationFlowNode; + +public class IterationFlowEmitter extends JSSubEmitter implements + ISubEmitter<IIterationFlowNode> +{ + public IterationFlowEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IIterationFlowNode node) + { + startMapping(node); + write(node.getKind().toString().toLowerCase()); + IIdentifierNode lnode = node.getLabelNode(); + if (lnode != null) + { + write(ASEmitterTokens.SPACE); + endMapping(node); + getWalker().walk(lnode); + } + else + { + endMapping(node); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java new file mode 100644 index 0000000..d1d24fd --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java @@ -0,0 +1,96 @@ +/* + * + * 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.IContainerNode; +import org.apache.flex.compiler.tree.as.ILiteralContainerNode; + +public class LiteralContainerEmitter extends JSSubEmitter implements + ISubEmitter<ILiteralContainerNode> +{ + public LiteralContainerEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(ILiteralContainerNode node) + { + final IContainerNode cnode = node.getContentsNode(); + final IContainerNode.ContainerType type = cnode.getContainerType(); + String preFix = null; + String postFix = null; + + if (type == IContainerNode.ContainerType.BRACES) + { + preFix = ASEmitterTokens.BLOCK_OPEN.getToken(); + postFix = ASEmitterTokens.BLOCK_CLOSE.getToken(); + } + else if (type == IContainerNode.ContainerType.BRACKETS) + { + preFix = ASEmitterTokens.SQUARE_OPEN.getToken(); + postFix = ASEmitterTokens.SQUARE_CLOSE.getToken(); + } + else if (type == IContainerNode.ContainerType.IMPLICIT) + { + // nothing to write, move along + } + else if (type == IContainerNode.ContainerType.PARENTHESIS) + { + preFix = ASEmitterTokens.PAREN_OPEN.getToken(); + postFix = ASEmitterTokens.PAREN_CLOSE.getToken(); + } + + if (preFix != null) + { + startMapping(node); + write(preFix); + endMapping(node); + } + + final int len = cnode.getChildCount(); + for (int i = 0; i < len; i++) + { + IASNode child = cnode.getChild(i); + getWalker().walk(child); + if (i < len - 1) + { + //we're mapping the comma to the literal container, but we fill + //the space between the current child and the next because we + //don't know exactly where the comma appears in ActionScript + startMapping(node, child); + writeToken(ASEmitterTokens.COMMA); + endMapping(node); + } + } + + if (postFix != null) + { + startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); + write(postFix); + endMapping(node); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java new file mode 100644 index 0000000..3f71c78 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java @@ -0,0 +1,70 @@ +/* + * + * 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.IDefinitionNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; +import org.apache.flex.compiler.tree.as.IKeywordNode; +import org.apache.flex.compiler.tree.as.IVariableNode; + +public class MemberKeywordEmitter extends JSSubEmitter implements + ISubEmitter<IDefinitionNode> +{ + public MemberKeywordEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IDefinitionNode node) + { + IKeywordNode keywordNode = null; + for(int i = 0; i < node.getChildCount(); i++) + { + IASNode childNode = node.getChild(i); + if (childNode instanceof IKeywordNode) + { + keywordNode = (IKeywordNode) childNode; + break; + } + } + if (keywordNode != null) + { + startMapping(keywordNode); + } + if (node instanceof IFunctionNode) + { + writeToken(ASEmitterTokens.FUNCTION); + } + else if (node instanceof IVariableNode) + { + writeToken(ASEmitterTokens.VAR); + } + if (keywordNode != null) + { + endMapping(keywordNode); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java new file mode 100644 index 0000000..604d1d6 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java @@ -0,0 +1,43 @@ +/* + * + * 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.common.ISourceLocation; +import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter; +import org.apache.flex.compiler.tree.as.INumericLiteralNode; + +public class NumericLiteralEmitter extends JSSubEmitter implements + ISubEmitter<INumericLiteralNode> +{ + public NumericLiteralEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(INumericLiteralNode node) + { + startMapping((ISourceLocation) node); + write(node.getNumericValue().toString()); + endMapping((ISourceLocation) node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java new file mode 100644 index 0000000..0c36871 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java @@ -0,0 +1,62 @@ +/* + * + * 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.common.ISourceLocation; +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.IExpressionNode; +import org.apache.flex.compiler.tree.as.ILiteralNode; +import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode; + +public class ObjectLiteralValuePairEmitter extends JSSubEmitter implements + ISubEmitter<IObjectLiteralValuePairNode> +{ + public ObjectLiteralValuePairEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IObjectLiteralValuePairNode node) + { + ISourceLocation sourceLocationNode = (ISourceLocation) node; + + IExpressionNode nameNode = node.getNameNode(); + if (!(nameNode instanceof ILiteralNode)) + { + startMapping(nameNode); + } + getWalker().walk(node.getNameNode()); + if (!(nameNode instanceof ILiteralNode)) + { + endMapping(nameNode); + } + + startMapping(sourceLocationNode, nameNode); + write(ASEmitterTokens.COLON); + endMapping(sourceLocationNode); + + IExpressionNode valueNode = node.getValueNode(); + getWalker().walk(valueNode); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParameterEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParameterEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParameterEmitter.java new file mode 100644 index 0000000..ef5c5a5 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParameterEmitter.java @@ -0,0 +1,62 @@ +/* + * + * 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.IExpressionNode; +import org.apache.flex.compiler.tree.as.IParameterNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode; + +public class ParameterEmitter extends JSSubEmitter implements + ISubEmitter<IParameterNode> +{ + public ParameterEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IParameterNode node) + { + startMapping(node); + if (node.isRest()) + { + write(ASEmitterTokens.ELLIPSIS); + write(node.getName()); + } + else + { + getWalker().walk(node.getNameExpressionNode()); + write(ASEmitterTokens.COLON); + getWalker().walk(node.getVariableTypeNode()); + IExpressionNode anode = node.getAssignedValueNode(); + if (anode != null) + { + write(ASEmitterTokens.SPACE); + writeToken(ASEmitterTokens.EQUAL); + getWalker().walk(anode); + } + } + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParametersEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParametersEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParametersEmitter.java new file mode 100644 index 0000000..01e1f25 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ParametersEmitter.java @@ -0,0 +1,64 @@ +/* + * + * 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.IContainerNode; +import org.apache.flex.compiler.tree.as.IParameterNode; + +public class ParametersEmitter extends JSSubEmitter implements + ISubEmitter<IContainerNode> +{ + public ParametersEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IContainerNode node) + { + startMapping(node); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + + int len = node.getChildCount(); + for (int i = 0; i < len; i++) + { + IParameterNode parameterNode = (IParameterNode) node.getChild(i); + getWalker().walk(parameterNode); //emitParameter + if (i < len - 1) + { + //we're mapping the comma to the container, but we use the + //parameter line/column in case the comma is not on the same + //line as the opening ( + startMapping(node, parameterNode); + writeToken(ASEmitterTokens.COMMA); + endMapping(node); + } + } + + startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1); + write(ASEmitterTokens.PAREN_CLOSE); + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ReturnEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ReturnEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ReturnEmitter.java new file mode 100644 index 0000000..407b80c --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ReturnEmitter.java @@ -0,0 +1,57 @@ +/* + * + * 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.ASTNodeID; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IReturnNode; + +public class ReturnEmitter extends JSSubEmitter implements + ISubEmitter<IReturnNode> +{ + public ReturnEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IReturnNode node) + { + IExpressionNode rnode = node.getReturnValueNode(); + boolean hasReturnValue = rnode != null && rnode.getNodeID() != ASTNodeID.NilID; + + startMapping(node); + write(ASEmitterTokens.RETURN); + if (hasReturnValue) + { + write(ASEmitterTokens.SPACE); + } + endMapping(node); + + if (hasReturnValue) + { + getWalker().walk(rnode); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SourceMapDirectiveEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SourceMapDirectiveEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SourceMapDirectiveEmitter.java new file mode 100644 index 0000000..14674de --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/SourceMapDirectiveEmitter.java @@ -0,0 +1,60 @@ +/* + * + * 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.clients.JSConfiguration; +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.projects.FlexJSProject; +import org.apache.flex.compiler.tree.as.ITypeNode; +import org.apache.flex.compiler.visitor.IBlockWalker; + +public class SourceMapDirectiveEmitter extends JSSubEmitter implements + ISubEmitter<ITypeNode> +{ + public SourceMapDirectiveEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(ITypeNode node) + { + boolean sourceMap = false; + + IBlockWalker walker = getWalker(); + FlexJSProject project = (FlexJSProject) walker.getProject(); + if (project != null) + { + JSConfiguration config = project.config; + if (config != null) + { + sourceMap = config.getSourceMap(); + } + } + + if (sourceMap) + { + writeNewline(); + write("//# sourceMappingURL=./" + node.getName() + ".js.map"); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/TernaryOperatorEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/TernaryOperatorEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/TernaryOperatorEmitter.java new file mode 100644 index 0000000..8273e1b --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/TernaryOperatorEmitter.java @@ -0,0 +1,67 @@ +/* + * + * 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.IExpressionNode; +import org.apache.flex.compiler.tree.as.IOperatorNode; +import org.apache.flex.compiler.tree.as.ITernaryOperatorNode; +import org.apache.flex.compiler.utils.ASNodeUtils; + +public class TernaryOperatorEmitter extends JSSubEmitter implements + ISubEmitter<ITernaryOperatorNode> +{ + public TernaryOperatorEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(ITernaryOperatorNode node) + { + if (ASNodeUtils.hasParenOpen((IOperatorNode) node)) + write(ASEmitterTokens.PAREN_OPEN); + + IExpressionNode conditionalNode = node.getConditionalNode(); + getWalker().walk(conditionalNode); + + IExpressionNode leftOperandNode = node.getLeftOperandNode(); + startMapping(node, conditionalNode); + write(ASEmitterTokens.SPACE); + writeToken(ASEmitterTokens.TERNARY); + endMapping(node); + + getWalker().walk(leftOperandNode); + + IExpressionNode rightOperandNode = node.getRightOperandNode(); + startMapping(node, leftOperandNode); + write(ASEmitterTokens.SPACE); + writeToken(ASEmitterTokens.COLON); + endMapping(node); + + getWalker().walk(rightOperandNode); + + if (ASNodeUtils.hasParenClose((IOperatorNode) node)) + write(ASEmitterTokens.PAREN_CLOSE); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/UnaryOperatorEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/UnaryOperatorEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/UnaryOperatorEmitter.java new file mode 100644 index 0000000..88bb154 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/UnaryOperatorEmitter.java @@ -0,0 +1,122 @@ +/* + * + * 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.ASTNodeID; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IUnaryOperatorNode; +import org.apache.flex.compiler.utils.ASNodeUtils; + +public class UnaryOperatorEmitter extends JSSubEmitter implements + ISubEmitter<IUnaryOperatorNode> +{ + public UnaryOperatorEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IUnaryOperatorNode node) + { + if (ASNodeUtils.hasParenOpen(node)) + write(ASEmitterTokens.PAREN_OPEN); + + if (node.getNodeID() == ASTNodeID.Op_PreIncrID + || node.getNodeID() == ASTNodeID.Op_PreDecrID + || node.getNodeID() == ASTNodeID.Op_BitwiseNotID + || node.getNodeID() == ASTNodeID.Op_LogicalNotID + || node.getNodeID() == ASTNodeID.Op_SubtractID + || node.getNodeID() == ASTNodeID.Op_AddID) + { + emitPreUnaryOperator(node); + } + else if (node.getNodeID() == ASTNodeID.Op_PostIncrID + || node.getNodeID() == ASTNodeID.Op_PostDecrID) + { + emitPostUnaryOperator(node); + } + else if (node.getNodeID() == ASTNodeID.Op_DeleteID) + { + emitDeleteOperator(node); + } + else if (node.getNodeID() == ASTNodeID.Op_VoidID) + { + emitVoidOperator(node); + } + else if (node.getNodeID() == ASTNodeID.Op_TypeOfID) + { + emitTypeOfOperator(node); + } + + if (ASNodeUtils.hasParenClose(node)) + write(ASEmitterTokens.PAREN_CLOSE); + } + + public void emitPreUnaryOperator(IUnaryOperatorNode node) + { + startMapping(node); + write(node.getOperator().getOperatorText()); + IExpressionNode opNode = node.getOperandNode(); + endMapping(node); + getWalker().walk(opNode); + } + + protected void emitPostUnaryOperator(IUnaryOperatorNode node) + { + IExpressionNode operandNode = node.getOperandNode(); + getWalker().walk(operandNode); + startMapping(node, operandNode); + write(node.getOperator().getOperatorText()); + endMapping(node); + } + + protected void emitDeleteOperator(IUnaryOperatorNode node) + { + startMapping(node); + writeToken(node.getOperator().getOperatorText()); + endMapping(node); + getWalker().walk(node.getOperandNode()); + } + + protected void emitVoidOperator(IUnaryOperatorNode node) + { + startMapping(node); + writeToken(node.getOperator().getOperatorText()); + endMapping(node); + getWalker().walk(node.getOperandNode()); + } + + protected void emitTypeOfOperator(IUnaryOperatorNode node) + { + startMapping(node); + write(node.getOperator().getOperatorText()); + write(ASEmitterTokens.PAREN_OPEN); + endMapping(node); + IExpressionNode operandNode = node.getOperandNode(); + getWalker().walk(operandNode); + startMapping(node); + write(ASEmitterTokens.PAREN_CLOSE); + endMapping(node); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3b8a2b8/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 new file mode 100644 index 0000000..8ff0e84 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/WhileEmitter.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 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/c3b8a2b8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java index 3e59a8d..ecfdde7 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java @@ -505,4 +505,10 @@ public class EmitterUtils return result; } + public static boolean isImplicit(IContainerNode node) + { + return node.getContainerType() == IContainerNode.ContainerType.IMPLICIT + || node.getContainerType() == IContainerNode.ContainerType.SYNTHESIZED; + } + }
