From 0e39d5d027f226967bfb09673485a35ba40ee724 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Mon, 30 Dec 2013 23:29:50 +0000 Subject: [PATCH] Switch over more of the parser to err_expected Includes a fix for a missing highlight range caused by a ',' typo in the PP diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198252 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPExpressions.cpp | 4 ++-- lib/Parse/ParseDeclCXX.cpp | 28 +++++++++++----------------- lib/Parse/ParseExpr.cpp | 6 +++--- lib/Parse/ParseObjc.cpp | 12 +++++------- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 09d87de86b..f7c3be9958 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -681,8 +681,8 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, case tok::question: { // Parse the : part of the expression. if (PeekTok.isNot(tok::colon)) { - PP.Diag(PeekTok.getLocation(), diag::err_expected_colon) - << LHS.getRange(), RHS.getRange(); + PP.Diag(PeekTok.getLocation(), diag::err_expected) + << tok::colon << LHS.getRange() << RHS.getRange(); PP.Diag(OpLoc, diag::note_matching) << tok::question; return true; } diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index cf86b43abb..6098c0c897 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2085,9 +2085,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); - if (Tok.is(tok::semi)) { - ConsumeToken(); - + if (TryConsumeToken(tok::semi)) { if (DS.isFriendSpecified()) ProhibitAttributes(FnAttrs); @@ -2175,8 +2173,8 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, SkipUntil(tok::r_brace); // Consume the optional ';' - if (Tok.is(tok::semi)) - ConsumeToken(); + TryConsumeToken(tok::semi); + return; } @@ -2401,7 +2399,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // Skip to end of block or statement. SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); // If we stopped at a ';', eat it. - if (Tok.is(tok::semi)) ConsumeToken(); + TryConsumeToken(tok::semi); return; } @@ -2645,18 +2643,14 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, MaybeParseGNUAttributes(AccessAttrs); SourceLocation EndLoc; - if (Tok.is(tok::colon)) { - EndLoc = Tok.getLocation(); - ConsumeToken(); - } else if (Tok.is(tok::semi)) { - EndLoc = Tok.getLocation(); - ConsumeToken(); - Diag(EndLoc, diag::err_expected_colon) - << FixItHint::CreateReplacement(EndLoc, ":"); + if (TryConsumeToken(tok::colon, EndLoc)) { + } else if (TryConsumeToken(tok::semi, EndLoc)) { + Diag(EndLoc, diag::err_expected) + << tok::colon << FixItHint::CreateReplacement(EndLoc, ":"); } else { EndLoc = ASLoc.getLocWithOffset(TokLength); - Diag(EndLoc, diag::err_expected_colon) - << FixItHint::CreateInsertion(EndLoc, ":"); + Diag(EndLoc, diag::err_expected) + << tok::colon << FixItHint::CreateInsertion(EndLoc, ":"); } // The Microsoft extension __interface does not permit non-public @@ -3440,7 +3434,7 @@ void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, if (Tok.is(tok::colon)) Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); else - Diag(Tok, diag::err_expected_colon); + Diag(Tok, diag::err_expected) << tok::colon; ConsumeToken(); continue; } diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 9abc5a3aef..96f8f55a73 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -291,9 +291,9 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { } } } - - Diag(Tok, diag::err_expected_colon) - << FixItHint::CreateInsertion(FILoc, FIText); + + Diag(Tok, diag::err_expected) + << tok::colon << FixItHint::CreateInsertion(FILoc, FIText); Diag(OpToken, diag::note_matching) << tok::question; ColonLoc = Tok.getLocation(); } diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 6f83707d05..a36d2ea1b4 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1058,7 +1058,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, // Each iteration parses a single keyword argument. if (Tok.isNot(tok::colon)) { - Diag(Tok, diag::err_expected_colon); + Diag(Tok, diag::err_expected) << tok::colon; break; } ConsumeToken(); // Eat the ':'. @@ -2486,7 +2486,7 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, KeyLocs.push_back(Loc); if (Tok.isNot(tok::colon)) { - Diag(Tok, diag::err_expected_colon); + Diag(Tok, diag::err_expected) << tok::colon; // We must manually skip to a ']', otherwise the expression skipper will // stop at the ']' when it skips to the ';'. We want it to skip beyond // the enclosing expression. @@ -2589,10 +2589,8 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, } if (Tok.isNot(tok::r_square)) { - if (Tok.is(tok::identifier)) - Diag(Tok, diag::err_expected_colon); - else - Diag(Tok, diag::err_expected_rsquare); + Diag(Tok, diag::err_expected) + << (Tok.is(tok::identifier) ? tok::colon : tok::r_square); // We must manually skip to a ']', otherwise the expression skipper will // stop at the ']' when it skips to the ';'. We want it to skip beyond // the enclosing expression. @@ -2886,7 +2884,7 @@ ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { ++nColons; KeyIdents.push_back(0); } else if (Tok.isNot(tok::colon)) - return ExprError(Diag(Tok, diag::err_expected_colon)); + return ExprError(Diag(Tok, diag::err_expected) << tok::colon); ++nColons; ConsumeToken(); // Eat the ':' or '::'. -- 2.50.0