[cfe-commits] r56089 - in /cfe/trunk: Driver/DiagChecker.cpp include/clang/Driver/TextDiagnosticBuffer.h lib/Driver/TextDiagnosticBuffer.cpp
Douglas Gregor
doug.gregor at gmail.com
Wed Sep 10 19:46:36 PDT 2008
Author: dgregor
Date: Wed Sep 10 21:46:36 2008
New Revision: 56089
URL: http://llvm.org/viewvc/llvm-project?rev=56089&view=rev
Log:
Add support for expected-note to Clang's -verify option
Modified:
cfe/trunk/Driver/DiagChecker.cpp
cfe/trunk/include/clang/Driver/TextDiagnosticBuffer.h
cfe/trunk/lib/Driver/TextDiagnosticBuffer.cpp
Modified: cfe/trunk/Driver/DiagChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/DiagChecker.cpp?rev=56089&r1=56088&r2=56089&view=diff
==============================================================================
--- cfe/trunk/Driver/DiagChecker.cpp (original)
+++ cfe/trunk/Driver/DiagChecker.cpp Wed Sep 10 21:46:36 2008
@@ -40,6 +40,7 @@
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 @@
// 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 @@
// 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 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 @@
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 @@
/// 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);
}
Modified: cfe/trunk/include/clang/Driver/TextDiagnosticBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/TextDiagnosticBuffer.h?rev=56089&r1=56088&r2=56089&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/TextDiagnosticBuffer.h (original)
+++ cfe/trunk/include/clang/Driver/TextDiagnosticBuffer.h Wed Sep 10 21:46:36 2008
@@ -28,7 +28,7 @@
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 @@
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,
Modified: cfe/trunk/lib/Driver/TextDiagnosticBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/TextDiagnosticBuffer.cpp?rev=56089&r1=56088&r2=56089&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/TextDiagnosticBuffer.cpp (original)
+++ cfe/trunk/lib/Driver/TextDiagnosticBuffer.cpp Wed Sep 10 21:46:36 2008
@@ -26,6 +26,11 @@
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,
More information about the cfe-commits
mailing list