diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-26 18:41:30 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-26 18:41:30 +0000 |
commit | 51cfee88b37794cb98ee948c142884044a74e1fb (patch) | |
tree | 3ad03203059aa21cc7eaedca304c01e8cf284b8d /lib/Parse/ParseStmt.cpp | |
parent | 172cbdc41f25ea610a15bb7f071a973751d57b6e (diff) | |
download | clang-51cfee88b37794cb98ee948c142884044a74e1fb.tar.gz |
Refactor checking of switch conditions and case values.
Check each case value in turn while parsing it, performing the
conversion to the switch type within the context of the expression
itself. This will become necessary in order to properly handle cleanups
for temporaries created as part of the case label (in an upcoming
patch). For now it's just good hygiene.
This necessitates moving the checking for the switch condition itself to
earlier, so that the destination type is available when checking the
case labels.
As a nice side-effect, we get slightly improved diagnostic quality and
error recovery by separating the case expression checking from the case
statement checking and from tracking whether there are discarded case
labels.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338056 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index b16ce4fde3..deb10af4b1 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -685,20 +685,12 @@ StmtResult Parser::ParseCaseStatement(bool MissingCase, ExprResult Expr) { ExprResult LHS; if (!MissingCase) { - LHS = ParseConstantExpression(); - if (!getLangOpts().CPlusPlus11) { - LHS = Actions.CorrectDelayedTyposInExpr(LHS, [this](class Expr *E) { - return Actions.VerifyIntegerConstantExpression(E); - }); - } + LHS = ParseCaseExpression(CaseLoc); if (LHS.isInvalid()) { // If constant-expression is parsed unsuccessfully, recover by skipping // current case statement (moving to the colon that ends it). - if (SkipUntil(tok::colon, tok::r_brace, StopAtSemi | StopBeforeMatch)) { - TryConsumeToken(tok::colon, ColonLoc); - continue; - } - return StmtError(); + if (!SkipUntil(tok::colon, tok::r_brace, StopAtSemi | StopBeforeMatch)) + return StmtError(); } } else { LHS = Expr; @@ -710,13 +702,10 @@ StmtResult Parser::ParseCaseStatement(bool MissingCase, ExprResult Expr) { ExprResult RHS; if (TryConsumeToken(tok::ellipsis, DotDotDotLoc)) { Diag(DotDotDotLoc, diag::ext_gnu_case_range); - RHS = ParseConstantExpression(); + RHS = ParseCaseExpression(CaseLoc); if (RHS.isInvalid()) { - if (SkipUntil(tok::colon, tok::r_brace, StopAtSemi | StopBeforeMatch)) { - TryConsumeToken(tok::colon, ColonLoc); - continue; - } - return StmtError(); + if (!SkipUntil(tok::colon, tok::r_brace, StopAtSemi | StopBeforeMatch)) + return StmtError(); } } @@ -738,8 +727,7 @@ StmtResult Parser::ParseCaseStatement(bool MissingCase, ExprResult Expr) { } StmtResult Case = - Actions.ActOnCaseStmt(CaseLoc, LHS.get(), DotDotDotLoc, - RHS.get(), ColonLoc); + Actions.ActOnCaseStmt(CaseLoc, LHS, DotDotDotLoc, RHS, ColonLoc); // If we had a sema error parsing this case, then just ignore it and // continue parsing the sub-stmt. |