Switch over more of the parser to err_expected
authorAlp Toker <alp@nuanti.com>
Mon, 30 Dec 2013 23:29:50 +0000 (23:29 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 30 Dec 2013 23:29:50 +0000 (23:29 +0000)
Includes a fix for a missing highlight range caused by a ',' typo in the PP
diagnostics.

llvm-svn: 198252

clang/lib/Lex/PPExpressions.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseObjc.cpp

index 09d87de..f7c3be9 100644 (file)
@@ -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;
       }
index cf86b43..6098c0c 100644 (file)
@@ -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;
     }
index 9abc5a3..96f8f55 100644 (file)
@@ -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();
       }
index 6f83707..a36d2ea 100644 (file)
@@ -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 '::'.