diff options
Diffstat (limited to 'lib/Parse/ParseExec.cpp')
-rw-r--r-- | lib/Parse/ParseExec.cpp | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/lib/Parse/ParseExec.cpp b/lib/Parse/ParseExec.cpp index 7ac3e1afdf..9d070f2814 100644 --- a/lib/Parse/ParseExec.cpp +++ b/lib/Parse/ParseExec.cpp @@ -336,29 +336,44 @@ Parser::StmtResult Parser::ParseGotoStmt() { /// if-stmt := /// IF(scalar-logic-expr) action-stmt -ExprResult Parser::ParseExpectedConditionExpression(const char *DiagAfter) { - if (!ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, - DiagAfter)) - return ExprError(); - ExprResult Condition = ParseExpectedFollowupExpression("("); - if(Condition.isInvalid()) return Condition; - if (!ExpectAndConsume(tok::r_paren)) - return ExprError(); +ExprResult Parser::ParseExpectedConditionExpression(const char *DiagAfter, bool *Failed) { + ExprResult Condition; + if (IsPresent(tok::logical_literal_constant)) { + Condition = ParseExpectedFollowupExpression(DiagAfter); + } else { + if (!ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, + DiagAfter)) { + if (Failed) + *Failed = true; + return ExprError(); + } + + Condition = ParseExpectedFollowupExpression("("); + if(Condition.isInvalid() && !SkipUntil(tok::r_paren, true, true)) { + if (Failed) + *Failed = true; + return Condition; + } + + if (!ExpectAndConsume(tok::r_paren)) { + if (Failed) + *Failed = true; + return ExprError(); + } + } + + if (Failed) + *Failed = false; return Condition; } Parser::StmtResult Parser::ParseIfStmt() { auto Loc = ConsumeToken(); - ExprResult Condition; - if (!ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "IF")) + bool BadCondition = false; + ExprResult Condition = ParseExpectedConditionExpression("IF", &BadCondition); + if (BadCondition) goto error; - Condition = ParseExpectedFollowupExpression("("); - if(Condition.isInvalid()) { - if(!SkipUntil(tok::r_paren, true, true)) - goto error; - } - if (!ExpectAndConsume(tok::r_paren)) goto error; if(Features.FixedForm && !Tok.isAtStartOfStatement()) ReLexAmbiguousIdentifier(FixedFormAmbiguities.getMatcherForKeywordsAfterIF()); @@ -387,15 +402,12 @@ error: // FIXME: fixed-form THENconstructname Parser::StmtResult Parser::ParseElseIfStmt() { auto Loc = ConsumeToken(); - ExprResult Condition; - if (!ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "ELSE IF")) + + bool BadCondition = false; + ExprResult Condition = ParseExpectedConditionExpression("ELSE IF", &BadCondition); + if (BadCondition) goto error; - Condition = ParseExpectedFollowupExpression("("); - if(Condition.isInvalid()) { - if(!SkipUntil(tok::r_paren, true, true)) - goto error; - } - if (!ExpectAndConsume(tok::r_paren)) goto error; + if (!ExpectAndConsumeFixedFormAmbiguous(tok::kw_THEN, diag::err_expected_kw, "THEN")) goto error; ParseTrailingConstructName(); |