Skip to content

Commit

Permalink
eliminate private AstNode expr() in favor of private AstNode
Browse files Browse the repository at this point in the history
expr(boolean)
  • Loading branch information
p-bakker committed Nov 6, 2023
1 parent a3f43df commit c17868e
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/org/mozilla/javascript/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ private ConditionData condition() throws IOException {

if (mustMatchToken(Token.LP, "msg.no.paren.cond", true)) data.lp = ts.tokenBeg;

data.condition = expr();
data.condition = expr(false);

if (mustMatchToken(Token.RP, "msg.no.paren.after.cond", true)) data.rp = ts.tokenBeg;

Expand Down Expand Up @@ -1245,7 +1245,7 @@ private AstNode statementHelper() throws IOException {
return pn;
default:
lineno = ts.lineno;
pn = new ExpressionStatement(expr(), !insideFunction());
pn = new ExpressionStatement(expr(false), !insideFunction());
pn.setLineno(lineno);
break;
}
Expand Down Expand Up @@ -1319,7 +1319,7 @@ private SwitchStatement switchStatement() throws IOException {
if (mustMatchToken(Token.LP, "msg.no.paren.switch", true)) pn.setLp(ts.tokenBeg - pos);
pn.setLineno(ts.lineno);

AstNode discriminant = expr();
AstNode discriminant = expr(false);
pn.setExpression(discriminant);
enterSwitch(pn);

Expand All @@ -1343,7 +1343,7 @@ private SwitchStatement switchStatement() throws IOException {
break switchLoop;

case Token.CASE:
caseExpression = expr();
caseExpression = expr(false);
mustMatchToken(Token.COLON, "msg.no.colon.case", true);
break;

Expand Down Expand Up @@ -1499,22 +1499,22 @@ private Loop forLoop() throws IOException {
isForIn = true;
inPos = ts.tokenBeg - forPos;
markDestructuring(init);
cond = expr(); // object over which we're iterating
cond = expr(false); // object over which we're iterating
} else if (compilerEnv.getLanguageVersion() >= Context.VERSION_ES6
&& matchToken(Token.NAME, true)
&& "of".equals(ts.getString())) {
isForOf = true;
inPos = ts.tokenBeg - forPos;
markDestructuring(init);
cond = expr(); // object over which we're iterating
cond = expr(false); // object over which we're iterating
} else { // ordinary for-loop
mustMatchToken(Token.SEMI, "msg.no.semi.for", true);
if (peekToken() == Token.SEMI) {
// no loop condition
cond = new EmptyExpression(ts.tokenBeg, 1);
cond.setLineno(ts.lineno);
} else {
cond = expr();
cond = expr(false);
}

mustMatchToken(Token.SEMI, "msg.no.semi.for.cond", true);
Expand All @@ -1523,7 +1523,7 @@ && matchToken(Token.NAME, true)
incr = new EmptyExpression(tmpPos, 1);
incr.setLineno(ts.lineno);
} else {
incr = expr();
incr = expr(false);
}
}

Expand Down Expand Up @@ -1593,7 +1593,7 @@ private AstNode forLoopInit(int tt) throws IOException {
consumeToken();
init = variables(tt, ts.tokenBeg, false);
} else {
init = expr();
init = expr(false);
}
return init;
} finally {
Expand Down Expand Up @@ -1667,7 +1667,7 @@ private TryStatement tryStatement() throws IOException {

if (matchToken(Token.IF, true)) {
guardPos = ts.tokenBeg;
catchCond = expr();
catchCond = expr(false);
} else {
sawDefaultCatch = true;
}
Expand Down Expand Up @@ -1751,7 +1751,7 @@ private ThrowStatement throwStatement() throws IOException {
// see bug 256617
reportError("msg.bad.throw.eol");
}
AstNode expr = expr();
AstNode expr = expr(false);
ThrowStatement pn = new ThrowStatement(pos, expr);
pn.setLineno(lineno);
return pn;
Expand Down Expand Up @@ -1853,7 +1853,7 @@ private WithStatement withStatement() throws IOException {
int lineno = ts.lineno, pos = ts.tokenBeg, lp = -1, rp = -1;
if (mustMatchToken(Token.LP, "msg.no.paren.with", true)) lp = ts.tokenBeg;

AstNode obj = expr();
AstNode obj = expr(false);

if (mustMatchToken(Token.RP, "msg.no.paren.after.with", true)) rp = ts.tokenBeg;

Expand Down Expand Up @@ -1927,7 +1927,7 @@ private AstNode returnOrYield(int tt, boolean exprContext) throws IOException {
}
// fallthrough
default:
e = expr();
e = expr(false);
end = getNodeEnd(e);
}

Expand Down Expand Up @@ -2004,7 +2004,7 @@ private AstNode defaultXmlNamespace() throws IOException {
reportError("msg.bad.namespace");
}

AstNode e = expr();
AstNode e = expr(false);
UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
dxmln.setOperator(Token.DEFAULTNAMESPACE);
dxmln.setOperand(e);
Expand Down Expand Up @@ -2046,7 +2046,7 @@ private AstNode nameOrLabel() throws IOException {

// set check for label and call down to primaryExpr
currentFlaggedToken |= TI_CHECK_LABEL;
AstNode expr = expr();
AstNode expr = expr(false);

if (expr.getType() != Token.LABEL) {
AstNode n = new ExpressionStatement(expr, !insideFunction());
Expand All @@ -2061,7 +2061,7 @@ private AstNode nameOrLabel() throws IOException {
AstNode stmt = null;
while (peekToken() == Token.NAME) {
currentFlaggedToken |= TI_CHECK_LABEL;
expr = expr();
expr = expr(false);
if (expr.getType() != Token.LABEL) {
stmt = new ExpressionStatement(expr, !insideFunction());
autoInsertSemicolon(stmt);
Expand Down Expand Up @@ -2203,7 +2203,7 @@ private AstNode let(boolean isStatement, int pos) throws IOException {
pn.setType(Token.LET);
} else {
// let expression
AstNode expr = expr();
AstNode expr = expr(false);
pn.setLength(getNodeEnd(expr) - pos);
pn.setBody(expr);
if (isStatement) {
Expand Down Expand Up @@ -2287,10 +2287,6 @@ else if (symDeclType == Token.LP) {
}
}

private AstNode expr() throws IOException {
return expr(false);
}

private AstNode expr(boolean allowTrailingComma) throws IOException {
AstNode pn = assignExpr();
int pos = pn.getPosition();
Expand Down Expand Up @@ -2641,7 +2637,7 @@ private AstNode xmlInitializer() throws IOException {
AstNode expr =
(peekToken() == Token.RC)
? new EmptyExpression(beg, ts.tokenEnd - beg)
: expr();
: expr(false);
mustMatchToken(Token.RC, "msg.syntax", true);
XmlExpression xexpr = new XmlExpression(beg, expr);
xexpr.setIsXmlAttribute(ts.isXMLAttribute());
Expand Down Expand Up @@ -2773,7 +2769,7 @@ private AstNode memberExprTail(boolean allowCallSyntax, AstNode pn) throws IOExc
lineno = ts.lineno;
mustHaveXML();
setRequiresActivation();
AstNode filter = expr();
AstNode filter = expr(false);
int end = getNodeEnd(filter);
if (mustMatchToken(Token.RP, "msg.no.paren", true)) {
rp = ts.tokenBeg;
Expand All @@ -2792,7 +2788,7 @@ private AstNode memberExprTail(boolean allowCallSyntax, AstNode pn) throws IOExc
consumeToken();
int lb = ts.tokenBeg, rb = -1;
lineno = ts.lineno;
AstNode expr = expr();
AstNode expr = expr(false);
end = getNodeEnd(expr);
if (mustMatchToken(Token.RB, "msg.no.bracket.index", true)) {
rb = ts.tokenBeg;
Expand Down Expand Up @@ -3043,7 +3039,7 @@ private AstNode propertyName(int atPos, int memberTypeFlags) throws IOException
*/
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos) throws IOException {
int lb = ts.tokenBeg, rb = -1, pos = atPos != -1 ? atPos : lb;
AstNode expr = expr();
AstNode expr = expr(false);
int end = getNodeEnd(expr);
if (mustMatchToken(Token.RB, "msg.no.bracket.index", true)) {
rb = ts.tokenBeg;
Expand Down Expand Up @@ -3366,7 +3362,7 @@ private ArrayComprehensionLoop arrayComprehensionLoop() throws IOException {
default:
reportError("msg.in.after.for.name");
}
AstNode obj = expr();
AstNode obj = expr(false);
if (mustMatchToken(Token.RP, "msg.no.paren.for.ctrl", true)) rp = ts.tokenBeg - pos;

pn.setLength(ts.tokenEnd - pos);
Expand Down Expand Up @@ -3451,7 +3447,7 @@ private GeneratorExpressionLoop generatorExpressionLoop() throws IOException {
}

if (mustMatchToken(Token.IN, "msg.in.after.for.name", true)) inPos = ts.tokenBeg - pos;
AstNode obj = expr();
AstNode obj = expr(false);
if (mustMatchToken(Token.RP, "msg.no.paren.for.ctrl", true)) rp = ts.tokenBeg - pos;

pn.setLength(ts.tokenEnd - pos);
Expand Down Expand Up @@ -3733,7 +3729,7 @@ private AstNode templateLiteral(boolean isTaggedLiteral) throws IOException {
int tt = ts.readTemplateLiteral(isTaggedLiteral);
while (tt == Token.TEMPLATE_LITERAL_SUBST) {
elements.add(createTemplateLiteralCharacters(posChars));
elements.add(expr());
elements.add(expr(false));
mustMatchToken(Token.RC, "msg.syntax", true);
posChars = ts.tokenBeg + 1;
tt = ts.readTemplateLiteral(isTaggedLiteral);
Expand Down

0 comments on commit c17868e

Please sign in to comment.