]> granicus.if.org Git - clang/commitdiff
Add support for expected-note to Clang's -verify option
authorDouglas Gregor <dgregor@apple.com>
Thu, 11 Sep 2008 02:46:36 +0000 (02:46 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 11 Sep 2008 02:46:36 +0000 (02:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56089 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/DiagChecker.cpp
include/clang/Driver/TextDiagnosticBuffer.h
lib/Driver/TextDiagnosticBuffer.cpp

index 660d17add27abfddb4c95b80a37aa539124320bf..6f7ea0b739b31624251a3b5557af1ebef733da5a 100644 (file)
@@ -40,6 +40,7 @@ typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
 
 static const char * const ExpectedErrStr = "expected-error";
 static const char * const ExpectedWarnStr = "expected-warning";
+static const char * const ExpectedNoteStr = "expected-note";
 
 /// FindDiagnostics - Go through the comment and see if it indicates expected
 /// diagnostics. If so, then put them in a diagnostic list.
@@ -86,7 +87,8 @@ static void FindDiagnostics(const std::string &Comment,
 //   expected errors and warnings.
 static void FindExpectedDiags(Preprocessor &PP,
                               DiagList &ExpectedErrors,
-                              DiagList &ExpectedWarnings) {
+                              DiagList &ExpectedWarnings,
+                              DiagList &ExpectedNotes) {
   // Return comments as tokens, this is how we find expected diagnostics.
   PP.SetCommentRetentionState(true, true);
 
@@ -114,6 +116,10 @@ static void FindExpectedDiags(Preprocessor &PP,
       // Find all expected warnings
       FindDiagnostics(Comment, ExpectedWarnings, PP.getSourceManager(),
                       Tok.getLocation(), ExpectedWarnStr);
+
+      // Find all expected notes
+      FindDiagnostics(Comment, ExpectedNotes, PP.getSourceManager(),
+                      Tok.getLocation(), ExpectedNoteStr);
     }
   } while (Tok.isNot(tok::eof));
 
@@ -182,7 +188,8 @@ static bool CompareDiagLists(SourceManager &SourceMgr,
 /// 
 static bool CheckResults(Preprocessor &PP,
                          const DiagList &ExpectedErrors,
-                         const DiagList &ExpectedWarnings) {
+                         const DiagList &ExpectedWarnings,
+                         const DiagList &ExpectedNotes) {
   const DiagnosticClient *DiagClient = PP.getDiagnostics().getClient();
   assert(DiagClient != 0 &&
       "DiagChecker requires a valid TextDiagnosticBuffer");
@@ -223,6 +230,20 @@ static bool CheckResults(Preprocessor &PP,
                                  ExpectedWarnings.end(),
                                  "Warnings seen but not expected:");
 
+  // See if there were notes that were expected but not seen.
+  HadProblem |= CompareDiagLists(SourceMgr,
+                                 ExpectedNotes.begin(),
+                                 ExpectedNotes.end(),
+                                 Diags.note_begin(), Diags.note_end(),
+                                 "Notes expected but not seen:");
+
+  // See if there were notes that were seen but not expected.
+  HadProblem |= CompareDiagLists(SourceMgr,
+                                 Diags.note_begin(), Diags.note_end(),
+                                 ExpectedNotes.begin(),
+                                 ExpectedNotes.end(),
+                                 "Notes seen but not expected:");
+
   return HadProblem;
 }
 
@@ -238,9 +259,9 @@ bool clang::CheckASTConsumer(Preprocessor &PP, ASTConsumer* C) {
 /// CheckDiagnostics - Gather the expected diagnostics and check them.
 bool clang::CheckDiagnostics(Preprocessor &PP) {
   // Gather the set of expected diagnostics.
-  DiagList ExpectedErrors, ExpectedWarnings;
-  FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings);
+  DiagList ExpectedErrors, ExpectedWarnings, ExpectedNotes;
+  FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes);
 
   // Check that the expected diagnostics occurred.
-  return CheckResults(PP, ExpectedErrors, ExpectedWarnings);
+  return CheckResults(PP, ExpectedErrors, ExpectedWarnings, ExpectedNotes);
 }
index 76dfeaf3057a9f00595b2989427eefc6e1213de1..28f2287c675afaa67a5fb56dc38b5a5446298379 100644 (file)
@@ -28,7 +28,7 @@ public:
   typedef DiagList::iterator iterator;
   typedef DiagList::const_iterator const_iterator;
 private:
-  DiagList Errors, Warnings;
+  DiagList Errors, Warnings, Notes;
 public:
   const_iterator err_begin() const  { return Errors.begin(); }
   const_iterator err_end() const    { return Errors.end(); }
@@ -36,6 +36,9 @@ public:
   const_iterator warn_begin() const { return Warnings.begin(); }
   const_iterator warn_end() const   { return Warnings.end(); }
 
+  const_iterator note_begin() const { return Notes.begin(); }
+  const_iterator note_end() const   { return Notes.end(); }
+
   virtual void HandleDiagnostic(Diagnostic &Diags,
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
index b3e21e1b153f9fdb21881295189946c807325f24..1df93750f0dc20d5fab905f30dd342e371271ee9 100644 (file)
@@ -26,6 +26,11 @@ void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags,
                                             unsigned) {
   switch (Level) {
   default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
+  case Diagnostic::Note:
+    Notes.push_back(std::make_pair(Pos.getLocation(),
+                                   FormatDiagnostic(Diags, Level, ID, 
+                                                    Strs, NumStrs)));
+    break;
   case Diagnostic::Warning:
     Warnings.push_back(std::make_pair(Pos.getLocation(),
                                       FormatDiagnostic(Diags, Level, ID,