r198252 - Switch over more of the parser to err_expected
Alp Toker
alp at nuanti.com
Mon Dec 30 15:29:50 PST 2013
Author: alp
Date: Mon Dec 30 17:29:50 2013
New Revision: 198252
URL: http://llvm.org/viewvc/llvm-project?rev=198252&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Lex/PPExpressions.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=198252&r1=198251&r2=198252&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Mon Dec 30 17:29:50 2013
@@ -681,8 +681,8 @@ static bool EvaluateDirectiveSubExpr(PPV
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;
}
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=198252&r1=198251&r2=198252&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Dec 30 17:29:50 2013
@@ -2085,9 +2085,7 @@ void Parser::ParseCXXClassMemberDeclarat
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::ParseCXXClassMemberDeclarat
SkipUntil(tok::r_brace);
// Consume the optional ';'
- if (Tok.is(tok::semi))
- ConsumeToken();
+ TryConsumeToken(tok::semi);
+
return;
}
@@ -2401,7 +2399,7 @@ void Parser::ParseCXXClassMemberDeclarat
// 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
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::ParseMicrosoftIfExistsClass
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;
}
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=198252&r1=198251&r2=198252&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Dec 30 17:29:50 2013
@@ -291,9 +291,9 @@ Parser::ParseRHSOfBinaryExpression(ExprR
}
}
}
-
- 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();
}
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=198252&r1=198251&r2=198252&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Dec 30 17:29:50 2013
@@ -1058,7 +1058,7 @@ Decl *Parser::ParseObjCMethodDecl(Source
// 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(S
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(S
}
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::ParseObjCSelectorExpr
++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 '::'.
More information about the cfe-commits
mailing list