Permalink
Browse files

Clean up infix line number commit

 - Remove local variables no longer used
 - Restore setting line number for unary expression
 - Make sure infix expression always uses line number of left child
  • Loading branch information...
1 parent 85bbbb6 commit 10bd92a5ec3e3ca0dec87e073587619abe1f5558 @hns hns committed May 9, 2012
Showing with 3 additions and 15 deletions.
  1. +1 −12 src/org/mozilla/javascript/Parser.java
  2. +2 −3 src/org/mozilla/javascript/ast/InfixExpression.java
View
13 src/org/mozilla/javascript/Parser.java
@@ -2055,7 +2055,6 @@ private AstNode expr()
AstNode pn = assignExpr();
int pos = pn.getPosition();
while (matchToken(Token.COMMA)) {
- int lineno = ts.lineno;
int opPos = ts.tokenBeg;
if (compilerEnv.isStrictMode() && !pn.hasSideEffects())
addStrictWarning("msg.no.side.effects", "",
@@ -2084,7 +2083,6 @@ private AstNode assignExpr()
markDestructuring(pn);
int opPos = ts.tokenBeg;
- int opLineno = ts.getLineno();
pn = new Assignment(tt, pn, assignExpr(), opPos);
@@ -2131,7 +2129,6 @@ private AstNode orExpr()
AstNode pn = andExpr();
if (matchToken(Token.OR)) {
int opPos = ts.tokenBeg;
- int lineno = ts.lineno;
pn = new InfixExpression(Token.OR, pn, orExpr(), opPos);
}
return pn;
@@ -2143,7 +2140,6 @@ private AstNode andExpr()
AstNode pn = bitOrExpr();
if (matchToken(Token.AND)) {
int opPos = ts.tokenBeg;
- int lineno = ts.lineno;
pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
}
return pn;
@@ -2155,7 +2151,6 @@ private AstNode bitOrExpr()
AstNode pn = bitXorExpr();
while (matchToken(Token.BITOR)) {
int opPos = ts.tokenBeg;
- int lineno = ts.lineno;
pn = new InfixExpression(Token.BITOR, pn, bitXorExpr(), opPos);
}
return pn;
@@ -2167,7 +2162,6 @@ private AstNode bitXorExpr()
AstNode pn = bitAndExpr();
while (matchToken(Token.BITXOR)) {
int opPos = ts.tokenBeg;
- int lineno = ts.lineno;
pn = new InfixExpression(Token.BITXOR, pn, bitAndExpr(), opPos);
}
return pn;
@@ -2179,7 +2173,6 @@ private AstNode bitAndExpr()
AstNode pn = eqExpr();
while (matchToken(Token.BITAND)) {
int opPos = ts.tokenBeg;
- int lineno = ts.lineno;
pn = new InfixExpression(Token.BITAND, pn, eqExpr(), opPos);
}
return pn;
@@ -2191,7 +2184,6 @@ private AstNode eqExpr()
AstNode pn = relExpr();
for (;;) {
int tt = peekToken(), opPos = ts.tokenBeg;
- int lineno = ts.lineno;
switch (tt) {
case Token.EQ:
case Token.NE:
@@ -2220,7 +2212,6 @@ private AstNode relExpr()
AstNode pn = shiftExpr();
for (;;) {
int tt = peekToken(), opPos = ts.tokenBeg;
- int line = ts.lineno;
switch (tt) {
case Token.IN:
if (inForInit)
@@ -2246,7 +2237,6 @@ private AstNode shiftExpr()
AstNode pn = addExpr();
for (;;) {
int tt = peekToken(), opPos = ts.tokenBeg;
- int lineno = ts.lineno;
switch (tt) {
case Token.LSH:
case Token.URSH:
@@ -2268,7 +2258,6 @@ private AstNode addExpr()
int tt = peekToken(), opPos = ts.tokenBeg;
if (tt == Token.ADD || tt == Token.SUB) {
consumeToken();
- int lineno = ts.lineno;
pn = new InfixExpression(tt, pn, mulExpr(), opPos);
continue;
}
@@ -2288,7 +2277,6 @@ private AstNode mulExpr()
case Token.DIV:
case Token.MOD:
consumeToken();
- int line = ts.lineno;
pn = new InfixExpression(tt, pn, unaryExpr(), opPos);
continue;
}
@@ -2311,6 +2299,7 @@ private AstNode unaryExpr()
case Token.TYPEOF:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
+ node.setLineno(line);
return node;
case Token.ADD:
View
5 src/org/mozilla/javascript/ast/InfixExpression.java
@@ -96,9 +96,6 @@ public void setLeftAndRight(AstNode left, AstNode right) {
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);
@@ -139,6 +136,8 @@ public AstNode getLeft() {
public void setLeft(AstNode left) {
assertNotNull(left);
this.left = left;
+ // line number should agree with source position
+ setLineno(left.getLineno());
left.setParent(this);
}

0 comments on commit 10bd92a

Please sign in to comment.