Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modify rhino so that infix expressions use a starte position and line…

… number that point to the start of the expression rather than the position of the operator.

Modify IRFactory to maintain this new position logic when it does its translation pass.
Adjusted the test file expectations accordingly.

Committed by Mike Taylor
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=26391660
  • Loading branch information...
commit 85bbbb6f7d4a57e2318cdca5a06c18c92f0a9c46 1 parent d75957d
Nick Santos authored hns committed
View
15 src/org/mozilla/javascript/Parser.java
@@ -2063,7 +2063,6 @@ private AstNode expr()
if (peekToken() == Token.YIELD)
reportError("msg.yield.parenthesized");
pn = new InfixExpression(Token.COMMA, pn, assignExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2089,7 +2088,6 @@ private AstNode assignExpr()
pn = new Assignment(tt, pn, assignExpr(), opPos);
- pn.setLineno(opLineno);
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
@@ -2135,7 +2133,6 @@ private AstNode orExpr()
int opPos = ts.tokenBeg;
int lineno = ts.lineno;
pn = new InfixExpression(Token.OR, pn, orExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2148,7 +2145,6 @@ private AstNode andExpr()
int opPos = ts.tokenBeg;
int lineno = ts.lineno;
pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2161,7 +2157,6 @@ private AstNode bitOrExpr()
int opPos = ts.tokenBeg;
int lineno = ts.lineno;
pn = new InfixExpression(Token.BITOR, pn, bitXorExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2174,7 +2169,6 @@ private AstNode bitXorExpr()
int opPos = ts.tokenBeg;
int lineno = ts.lineno;
pn = new InfixExpression(Token.BITXOR, pn, bitAndExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2187,7 +2181,6 @@ private AstNode bitAndExpr()
int opPos = ts.tokenBeg;
int lineno = ts.lineno;
pn = new InfixExpression(Token.BITAND, pn, eqExpr(), opPos);
- pn.setLineno(lineno);
}
return pn;
}
@@ -2214,7 +2207,6 @@ else if (tt == Token.NE)
parseToken = Token.SHNE;
}
pn = new InfixExpression(parseToken, pn, relExpr(), opPos);
- pn.setLineno(lineno);
continue;
}
break;
@@ -2241,7 +2233,6 @@ private AstNode relExpr()
case Token.GT:
consumeToken();
pn = new InfixExpression(tt, pn, shiftExpr(), opPos);
- pn.setLineno(line);
continue;
}
break;
@@ -2262,7 +2253,6 @@ private AstNode shiftExpr()
case Token.RSH:
consumeToken();
pn = new InfixExpression(tt, pn, addExpr(), opPos);
- pn.setLineno(lineno);
continue;
}
break;
@@ -2280,7 +2270,6 @@ private AstNode addExpr()
consumeToken();
int lineno = ts.lineno;
pn = new InfixExpression(tt, pn, mulExpr(), opPos);
- pn.setLineno(lineno);
continue;
}
break;
@@ -2301,7 +2290,6 @@ private AstNode mulExpr()
consumeToken();
int line = ts.lineno;
pn = new InfixExpression(tt, pn, unaryExpr(), opPos);
- pn.setLineno(line);
continue;
}
break;
@@ -2323,7 +2311,6 @@ private AstNode unaryExpr()
case Token.TYPEOF:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
- node.setLineno(line);
return node;
case Token.ADD:
@@ -2677,7 +2664,7 @@ private AstNode propertyAccess(int tt, AstNode pn)
result.setPosition(pos);
result.setLength(getNodeEnd(ref) - pos);
result.setOperatorPosition(dotPos - pos);
- result.setLineno(lineno);
+ result.setLineno(pn.getLineno());
result.setLeft(pn); // do this after setting position
result.setRight(ref);
return result;
View
4 src/org/mozilla/javascript/ast/InfixExpression.java
@@ -95,6 +95,10 @@ public void setLeftAndRight(AstNode left, AstNode right) {
int beg = left.getPosition();
int end = right.getPosition() + right.getLength();
setBounds(beg, end);
+
+ // line number should agree with source position
+ setLineno(left.getLineno());
+
// this updates their positions to be parent-relative
setLeft(left);
setRight(right);
View
35 testsrc/org/mozilla/javascript/tests/ParserTest.java
@@ -359,7 +359,7 @@ public void testLinenoInfix() {
assertEquals(1, var1.getLineno());
assertEquals(1, firstVarName.getLineno());
- assertEquals(2, var1Add.getLineno());
+ assertEquals(1, var1Add.getLineno());
assertEquals(1, var1Add.getLeft().getLineno());
assertEquals(3, var1Add.getRight().getLineno());
@@ -373,7 +373,7 @@ public void testLinenoInfix() {
assertEquals(8, var3.getLineno());
assertEquals(8, thirdVarName.getLineno());
- assertEquals(9, thirdVarDiv.getLineno());
+ assertEquals(8, thirdVarDiv.getLineno());
assertEquals(8, thirdVarDiv.getLeft().getLineno());
assertEquals(9, thirdVarDiv.getRight().getLineno());
}
@@ -496,7 +496,7 @@ public void testLinenoCompare() {
AstNode rhs = compare.getRight();
assertEquals(1, lhs.getLineno());
- assertEquals(2, compare.getLineno());
+ assertEquals(1, compare.getLineno());
assertEquals(3, rhs.getLineno());
}
@@ -511,7 +511,7 @@ public void testLinenoEq() {
AstNode rhs = compare.getRight();
assertEquals(1, lhs.getLineno());
- assertEquals(2, compare.getLineno());
+ assertEquals(1, compare.getLineno());
assertEquals(3, rhs.getLineno());
}
@@ -526,7 +526,7 @@ public void testLinenoPlusEq() {
AstNode rhs = assign.getRight();
assertEquals(1, lhs.getLineno());
- assertEquals(2, assign.getLineno());
+ assertEquals(1, assign.getLineno());
assertEquals(3, rhs.getLineno());
}
@@ -543,7 +543,7 @@ public void testLinenoComma() {
AstNode aRef = comma2.getLeft();
AstNode bRef = comma2.getRight();
- assertEquals(2, comma1.getLineno());
+ assertEquals(1, comma1.getLineno());
assertEquals(1, comma2.getLineno());
assertEquals(1, aRef.getLineno());
assertEquals(2, bRef.getLineno());
@@ -591,7 +591,7 @@ public void testNestedOr() {
AstNode cName = orClause.getRight();
assertEquals(1, ifStmt.getLineno());
- assertEquals(2, orClause.getLineno());
+ assertEquals(1, orClause.getLineno());
assertEquals(1, andClause.getLineno());
assertEquals(4, cName.getLineno());
@@ -628,7 +628,8 @@ public void testObjectLitLocation() {
AstNode thirdValue = thirdObjectLit.getRight();
assertEquals(1, firstVarName.getLineno());
- assertEquals(2, firstObjectLit.getLineno());
+ assertEquals(2, objectLiteral.getLineno());
+ assertEquals(3, firstObjectLit.getLineno());
assertEquals(3, firstKey.getLineno());
assertEquals(3, firstValue.getLineno());
@@ -703,8 +704,8 @@ public void testLinenoMultilineEq() {
AstNode bTest = andTest.getRight();
assertEquals(1, ifStmt.getLineno());
- assertEquals(4, orTest.getLineno());
- assertEquals(3, andTest.getLineno());
+ assertEquals(2, orTest.getLineno());
+ assertEquals(2, andTest.getLineno());
assertEquals(2, aTest.getLineno());
assertEquals(4, bTest.getLineno());
assertEquals(5, cTest.getLineno());
@@ -756,18 +757,18 @@ public void testLinenoMultilineBitTest() {
assertEquals(2, bigLHSExpr.getLineno());
assertEquals(7, bigRHSExpr.getLineno());
- assertEquals(4, eqTest.getLineno());
- assertEquals(9, notEqTest.getLineno());
+ assertEquals(2, eqTest.getLineno());
+ assertEquals(7, notEqTest.getLineno());
assertEquals(2, test1Expr.getLineno());
assertEquals(5, test2Expr.getLineno());
assertEquals(7, test3Expr.getLineno());
assertEquals(10, test4Expr.getLineno());
- assertEquals(3, bitOrTest.getLineno());
- assertEquals(6, bitAndTest.getLineno());
- assertEquals(8, bitXorTest.getLineno());
- assertEquals(11, bitShiftTest.getLineno());
+ assertEquals(2, bitOrTest.getLineno());
+ assertEquals(5, bitAndTest.getLineno());
+ assertEquals(7, bitXorTest.getLineno());
+ assertEquals(10, bitShiftTest.getLineno());
}
public void testLinenoFunctionCall() {
@@ -810,7 +811,7 @@ public void testLinenoDeclaration() {
AstNode bName = aDotbName.getRight();
FunctionNode fnNode = (FunctionNode) fnAssignment.getRight();
- assertEquals(2, fnAssignment.getLineno());
+ assertEquals(1, fnAssignment.getLineno());
assertEquals(1, aDotbName.getLineno());
assertEquals(1, aName.getLineno());
assertEquals(2, bName.getLineno());
Please sign in to comment.
Something went wrong with that request. Please try again.