You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/04/11 15:59:52 UTC
[25/50] git commit: [flex-falcon]
[refs/heads/feature/maven-migration] - IJSEmitter: replaced startMapping()
that takes a column offset with one that takes prev/next nodes so that the
entire space can be filled (even across multiple lines)
IJSEmitter: replaced startMapping() that takes a column offset with one that takes prev/next nodes so that the entire space can be filled (even across multiple lines)
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/739bef79
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/739bef79
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/739bef79
Branch: refs/heads/feature/maven-migration
Commit: 739bef79dd9c2de5e2820c7ec191e27fe7263588
Parents: 799f906
Author: Josh Tynjala <jo...@apache.org>
Authored: Fri Apr 1 17:01:47 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Fri Apr 1 17:01:47 2016 -0700
----------------------------------------------------------------------
.../flex/compiler/codegen/js/IJSEmitter.java | 23 +++++++--
.../compiler/internal/codegen/js/JSEmitter.java | 52 ++++++++++----------
.../internal/codegen/js/jx/AsIsEmitter.java | 6 +--
.../codegen/js/jx/BinaryOperatorEmitter.java | 6 +--
.../codegen/js/jx/MemberAccessEmitter.java | 2 +-
.../codegen/js/jx/VarDeclarationEmitter.java | 25 +++++++---
6 files changed, 71 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
index 56a0c05..d42abe1 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
@@ -43,13 +43,30 @@ public interface IJSEmitter extends IASEmitter
List<SourceMapMapping> getSourceMapMappings();
String formatQualifiedName(String name);
-
+
+ /**
+ * Adds a node to the source map.
+ */
void startMapping(ISourceLocation node);
- void startMapping(ISourceLocation node, int startOffset);
+
+ /**
+ * Adds a node to the source map using custom line and column values,
+ * instead of the node's own line and column. Useful for starting a mapping
+ * in the middle of the node.
+ */
void startMapping(ISourceLocation node, int line, int column);
+
+ /**
+ * Adds a node to the source map using the space between two nodes instead
+ * of the node's own line and column.
+ */
void startMapping(ISourceLocation node, ISourceLocation previousNode, ISourceLocation nextNode);
-
+
+ /**
+ * Commits a mapping to the source map.
+ */
void endMapping(ISourceLocation node);
+
void pushSourceMapName(ISourceLocation node);
void popSourceMapName();
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/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 71c7d6e..ba7cbdf 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
@@ -183,7 +183,7 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
}
}
- startMapping(node, node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
+ startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
write(ASEmitterTokens.PAREN_CLOSE);
endMapping(node);
}
@@ -220,7 +220,7 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
}
}
- startMapping(node, node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
+ startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
write(ASEmitterTokens.PAREN_CLOSE);
endMapping(node);
}
@@ -286,7 +286,7 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
if (postFix != null)
{
- startMapping(node, node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
+ startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
write(postFix);
endMapping(node);
}
@@ -308,11 +308,12 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
endMapping(nameNode);
}
- startMapping(sourceLocationNode, nameNode.getAbsoluteEnd() - sourceLocationNode.getAbsoluteStart());
+ IExpressionNode valueNode = node.getValueNode();
+ startMapping(sourceLocationNode, nameNode, valueNode);
write(ASEmitterTokens.COLON);
endMapping(sourceLocationNode);
- getWalker().walk(node.getValueNode());
+ getWalker().walk(valueNode);
}
@Override
@@ -406,10 +407,10 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
IASNode conditionalExpression = node.getChild(0);
getWalker().walk(conditionalExpression);
-
- startMapping(node, conditionalExpression.getAbsoluteEnd() - node.getAbsoluteStart());
- write(ASEmitterTokens.PAREN_CLOSE);
+
IContainerNode xnode = (IContainerNode) node.getStatementContentsNode();
+ startMapping(node, conditionalExpression, xnode);
+ write(ASEmitterTokens.PAREN_CLOSE);
if (!isImplicit(xnode))
write(ASEmitterTokens.SPACE);
endMapping(node);
@@ -446,21 +447,22 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
IExpressionNode conditionalNode = node.getConditionalNode();
getWalker().walk(conditionalNode);
-
- startMapping(node, conditionalNode.getAbsoluteEnd() - node.getAbsoluteStart());
+
+ IExpressionNode leftOperandNode = node.getLeftOperandNode();
+ startMapping(node, conditionalNode, leftOperandNode);
write(ASEmitterTokens.SPACE);
writeToken(ASEmitterTokens.TERNARY);
endMapping(node);
- IExpressionNode leftOperandNode = node.getLeftOperandNode();
getWalker().walk(leftOperandNode);
- startMapping(node, leftOperandNode.getAbsoluteEnd() - node.getAbsoluteStart());
+ IExpressionNode rightOperandNode = node.getRightOperandNode();
+ startMapping(node, leftOperandNode, rightOperandNode);
write(ASEmitterTokens.SPACE);
writeToken(ASEmitterTokens.COLON);
endMapping(node);
- getWalker().walk(node.getRightOperandNode());
+ getWalker().walk(rightOperandNode);
if (ASNodeUtils.hasParenClose((IOperatorNode) node))
write(ASEmitterTokens.PAREN_CLOSE);
@@ -478,14 +480,15 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
IASNode conditionalExpression = node.getConditionalExpressionNode();
getWalker().walk(conditionalExpression);
-
- startMapping(node, conditionalExpression.getAbsoluteEnd() - node.getAbsoluteStart());
+
+ IASNode statementContentsNode = node.getStatementContentsNode();
+ startMapping(node, conditionalExpression, statementContentsNode);
write(ASEmitterTokens.PAREN_CLOSE);
if (!isImplicit(cnode))
write(ASEmitterTokens.SPACE);
endMapping(node);
- getWalker().walk(node.getStatementContentsNode());
+ getWalker().walk(statementContentsNode);
}
@Override
@@ -501,8 +504,9 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
IASNode statementContents = node.getStatementContentsNode();
getWalker().walk(statementContents);
-
- startMapping(node, statementContents.getAbsoluteEnd() - statementContents.getAbsoluteStart());
+
+ IASNode conditionalExpressionNode = node.getConditionalExpressionNode();
+ startMapping(node, statementContents, conditionalExpressionNode);
if (!isImplicit(cnode))
write(ASEmitterTokens.SPACE);
else
@@ -512,10 +516,9 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
write(ASEmitterTokens.PAREN_OPEN);
endMapping(node);
- IASNode conditionalExpression = node.getConditionalExpressionNode();
- getWalker().walk(conditionalExpression);
+ getWalker().walk(conditionalExpressionNode);
- startMapping(node, conditionalExpression.getAbsoluteEnd() - node.getAbsoluteStart());
+ startMapping(node, conditionalExpressionNode, conditionalExpressionNode.getSucceedingNode(1));
write(ASEmitterTokens.PAREN_CLOSE);
write(ASEmitterTokens.SEMICOLON);
endMapping(node);
@@ -536,7 +539,7 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
{
IExpressionNode operandNode = node.getOperandNode();
getWalker().walk(operandNode);
- startMapping(node, operandNode.getAbsoluteEnd() - operandNode.getAbsoluteStart());
+ startMapping(node, operandNode.getLine(), operandNode.getColumn() + operandNode.getAbsoluteEnd() - operandNode.getAbsoluteStart());
write(node.getOperator().getOperatorText());
endMapping(node);
}
@@ -635,11 +638,6 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
startMapping(node, node.getLine(), node.getColumn());
}
- public void startMapping(ISourceLocation node, int startOffset)
- {
- startMapping(node, node.getLine(), node.getColumn() + startOffset);
- }
-
public void startMapping(ISourceLocation node, ISourceLocation previousNode, ISourceLocation nextNode)
{
if(previousNode.getLine() == nextNode.getLine())
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java
index 1557b7e..18c2e05 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java
@@ -136,7 +136,7 @@ public class AsIsEmitter extends JSSubEmitter
if (node instanceof IBinaryOperatorNode)
{
IBinaryOperatorNode binaryOperatorNode = (IBinaryOperatorNode) node;
- getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode().getEnd() - binaryOperatorNode.getLeftOperandNode().getStart());
+ getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode(), binaryOperatorNode.getRightOperandNode());
}
else
{
@@ -157,7 +157,7 @@ public class AsIsEmitter extends JSSubEmitter
if (node instanceof IBinaryOperatorNode)
{
IBinaryOperatorNode binaryOperatorNode = (IBinaryOperatorNode) node;
- getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode().getEnd() - binaryOperatorNode.getLeftOperandNode().getStart());
+ getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode(), binaryOperatorNode.getRightOperandNode());
}
else
{
@@ -180,7 +180,7 @@ public class AsIsEmitter extends JSSubEmitter
if (node instanceof IBinaryOperatorNode)
{
IBinaryOperatorNode binaryOperatorNode = (IBinaryOperatorNode) node;
- getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode().getEnd() - binaryOperatorNode.getLeftOperandNode().getStart());
+ getEmitter().startMapping(node, binaryOperatorNode.getLeftOperandNode(), binaryOperatorNode.getRightOperandNode());
}
else
{
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 704c06b..b056177 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -71,7 +71,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
{
getWalker().walk(node.getLeftOperandNode());
- getEmitter().startMapping(node, node.getLeftOperandNode().getAbsoluteEnd() - node.getAbsoluteStart());
+ getEmitter().startMapping(node, node.getLeftOperandNode(), node.getRightOperandNode());
write(ASEmitterTokens.SPACE);
writeToken(ASEmitterTokens.INSTANCEOF);
getEmitter().endMapping(node);
@@ -330,7 +330,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
{
getWalker().walk(node.getLeftOperandNode());
- getEmitter().startMapping(node, node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ getEmitter().startMapping(node, node.getLeftOperandNode(), node.getRightOperandNode());
if (id != ASTNodeID.Op_CommaID)
write(ASEmitterTokens.SPACE);
@@ -346,7 +346,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
getEmitter().endMapping(node);
write(lnode.getName());
- getEmitter().startMapping(node, node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ getEmitter().startMapping(node, node.getLeftOperandNode(), node.getRightOperandNode());
write(ASEmitterTokens.SPACE);
write((id == ASTNodeID.Op_LogicalAndAssignID) ? ASEmitterTokens.LOGICAL_AND
: ASEmitterTokens.LOGICAL_OR);
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
index 245ae98..e5f9a58 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
@@ -246,7 +246,7 @@ public class MemberAccessEmitter extends JSSubEmitter implements
continueWalk = writeLeftSide(node, leftNode, rightNode);
if (continueWalk)
{
- getEmitter().startMapping(node, node.getLeftOperandNode().getAbsoluteEnd() - node.getAbsoluteStart());
+ getEmitter().startMapping(node, node.getLeftOperandNode(), node.getRightOperandNode());
write(node.getOperator().getOperatorText());
getEmitter().endMapping(node);
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/739bef79/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
index 0cbb60a..aed9671 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
@@ -53,10 +53,23 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
fjs.emitMemberKeyword(node);
}
- //we could use getVariableTypeNode(), but it might not have a line
- //and column. this can happen when the type is omitted in the code
- //and the compiler generates a node for type *
- getEmitter().startMapping(node, node.getNameExpressionNode().getAbsoluteEnd() - node.getAbsoluteStart());
+ IExpressionNode variableTypeNode = node.getVariableTypeNode();
+ if(variableTypeNode.getLine() >= 0)
+ {
+ getEmitter().startMapping(variableTypeNode,
+ variableTypeNode.getLine(),
+ variableTypeNode.getColumn() - 1); //include the :
+ }
+ else
+ {
+ //the result of getVariableTypeNode() may not have a line and
+ //column. this can happen when the type is omitted in the code, and
+ //the compiler generates a node for type *.
+ //in this case, put it at the end of the name expression.
+ IExpressionNode nameExpressionNode = node.getNameExpressionNode();
+ getEmitter().startMapping(variableTypeNode, nameExpressionNode.getLine(),
+ nameExpressionNode.getColumn() + nameExpressionNode.getAbsoluteEnd() - nameExpressionNode.getAbsoluteStart());
+ }
IExpressionNode avnode = node.getAssignedValueNode();
if (avnode != null)
{
@@ -72,7 +85,7 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
{
fjs.getDocEmitter().emitVarDoc(node, null, getWalker().getProject());
}
- getEmitter().endMapping(node);
+ getEmitter().endMapping(variableTypeNode);
if (!(node instanceof ChainedVariableNode) && node.isConst())
{
@@ -82,7 +95,7 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
fjs.emitDeclarationName(node);
if (avnode != null && !(avnode instanceof IEmbedNode))
{
- getEmitter().startMapping(node, node.getVariableTypeNode().getEnd() - node.getStart());
+ getEmitter().startMapping(node, node.getVariableTypeNode(), avnode);
write(ASEmitterTokens.SPACE);
writeToken(ASEmitterTokens.EQUAL);
getEmitter().endMapping(node);