Skip to content

Commit 9f61479

Browse files
committed
[clang][Parser][NFC] Simplify ParseParenExprOrCondition
Differential Revision: https://reviews.llvm.org/D138194
1 parent 1614d63 commit 9f61479

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,8 +2109,8 @@ class Parser : public CodeCompletionHandler {
21092109
bool ParseParenExprOrCondition(StmtResult *InitStmt,
21102110
Sema::ConditionResult &CondResult,
21112111
SourceLocation Loc, Sema::ConditionKind CK,
2112-
bool MissingOK, SourceLocation *LParenLoc,
2113-
SourceLocation *RParenLoc);
2112+
SourceLocation &LParenLoc,
2113+
SourceLocation &RParenLoc);
21142114
StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
21152115
StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
21162116
StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);

clang/lib/Parse/ParseStmt.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,20 +1270,20 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
12701270
/// should try to recover harder. It returns false if the condition is
12711271
/// successfully parsed. Note that a successful parse can still have semantic
12721272
/// errors in the condition.
1273-
/// Additionally, if LParenLoc and RParenLoc are non-null, it will assign
1274-
/// the location of the outer-most '(' and ')', respectively, to them.
1273+
/// Additionally, it will assign the location of the outer-most '(' and ')',
1274+
/// to LParenLoc and RParenLoc, respectively.
12751275
bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
12761276
Sema::ConditionResult &Cond,
12771277
SourceLocation Loc,
1278-
Sema::ConditionKind CK, bool MissingOK,
1279-
SourceLocation *LParenLoc,
1280-
SourceLocation *RParenLoc) {
1278+
Sema::ConditionKind CK,
1279+
SourceLocation &LParenLoc,
1280+
SourceLocation &RParenLoc) {
12811281
BalancedDelimiterTracker T(*this, tok::l_paren);
12821282
T.consumeOpen();
12831283
SourceLocation Start = Tok.getLocation();
12841284

12851285
if (getLangOpts().CPlusPlus) {
1286-
Cond = ParseCXXCondition(InitStmt, Loc, CK, MissingOK);
1286+
Cond = ParseCXXCondition(InitStmt, Loc, CK, false);
12871287
} else {
12881288
ExprResult CondExpr = ParseExpression();
12891289

@@ -1292,7 +1292,7 @@ bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
12921292
Cond = Sema::ConditionError();
12931293
else
12941294
Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK,
1295-
MissingOK);
1295+
/*MissingOK=*/false);
12961296
}
12971297

12981298
// If the parser was confused by the condition and we don't have a ')', try to
@@ -1312,18 +1312,13 @@ bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
13121312
Actions.PreferredConditionType(CK));
13131313
if (!CondExpr.isInvalid())
13141314
Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK,
1315-
MissingOK);
1315+
/*MissingOK=*/false);
13161316
}
13171317

13181318
// Either the condition is valid or the rparen is present.
13191319
T.consumeClose();
1320-
1321-
if (LParenLoc != nullptr) {
1322-
*LParenLoc = T.getOpenLocation();
1323-
}
1324-
if (RParenLoc != nullptr) {
1325-
*RParenLoc = T.getCloseLocation();
1326-
}
1320+
LParenLoc = T.getOpenLocation();
1321+
RParenLoc = T.getCloseLocation();
13271322

13281323
// Check for extraneous ')'s to catch things like "if (foo())) {". We know
13291324
// that all callers are looking for a statement after the condition, so ")"
@@ -1499,7 +1494,7 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
14991494
if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
15001495
IsConstexpr ? Sema::ConditionKind::ConstexprIf
15011496
: Sema::ConditionKind::Boolean,
1502-
/*MissingOK=*/false, &LParen, &RParen))
1497+
LParen, RParen))
15031498
return StmtError();
15041499

15051500
if (IsConstexpr)
@@ -1694,8 +1689,7 @@ StmtResult Parser::ParseSwitchStatement(SourceLocation *TrailingElseLoc) {
16941689
SourceLocation LParen;
16951690
SourceLocation RParen;
16961691
if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1697-
Sema::ConditionKind::Switch,
1698-
/*MissingOK=*/false, &LParen, &RParen))
1692+
Sema::ConditionKind::Switch, LParen, RParen))
16991693
return StmtError();
17001694

17011695
StmtResult Switch = Actions.ActOnStartOfSwitchStmt(
@@ -1785,8 +1779,7 @@ StmtResult Parser::ParseWhileStatement(SourceLocation *TrailingElseLoc) {
17851779
SourceLocation LParen;
17861780
SourceLocation RParen;
17871781
if (ParseParenExprOrCondition(nullptr, Cond, WhileLoc,
1788-
Sema::ConditionKind::Boolean,
1789-
/*MissingOK=*/false, &LParen, &RParen))
1782+
Sema::ConditionKind::Boolean, LParen, RParen))
17901783
return StmtError();
17911784

17921785
// C99 6.8.5p5 - In C99, the body of the while statement is a scope, even if

0 commit comments

Comments
 (0)