parent
0d21046a7e
commit
318a9d7663
|
@ -19,6 +19,7 @@
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
typedef TextDiagnosticBuffer::DiagList DiagList;
|
typedef TextDiagnosticBuffer::DiagList DiagList;
|
||||||
|
typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
|
||||||
|
|
||||||
// USING THE DIAGNOSTIC CHECKER:
|
// USING THE DIAGNOSTIC CHECKER:
|
||||||
//
|
//
|
||||||
|
@ -79,16 +80,11 @@ static void FindDiagnostics(const std::string &Comment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ProcessFileDiagnosticChecking - This lexes the file and finds all of the
|
/// FindExpectedDiags - Lex the file to finds all of the expected errors and
|
||||||
/// expected errors and warnings. It then does the actual parsing of the
|
/// warnings.
|
||||||
/// program. The parsing will report its diagnostics, and a function can be
|
static void FindExpectedDiags(Preprocessor &PP, unsigned MainFileID,
|
||||||
/// called later to report any discrepencies between the diagnostics expected
|
DiagList &ExpectedErrors,
|
||||||
/// and those actually seen.
|
DiagList &ExpectedWarnings) {
|
||||||
///
|
|
||||||
static void ProcessFileDiagnosticChecking(Preprocessor &PP,
|
|
||||||
unsigned MainFileID,
|
|
||||||
DiagList &ExpectedErrors,
|
|
||||||
DiagList &ExpectedWarnings) {
|
|
||||||
// Return comments as tokens, this is how we find expected diagnostics.
|
// Return comments as tokens, this is how we find expected diagnostics.
|
||||||
PP.SetCommentRetentionState(true, true);
|
PP.SetCommentRetentionState(true, true);
|
||||||
|
|
||||||
|
@ -112,13 +108,9 @@ static void ProcessFileDiagnosticChecking(Preprocessor &PP,
|
||||||
}
|
}
|
||||||
} while (Tok.getKind() != tok::eof);
|
} while (Tok.getKind() != tok::eof);
|
||||||
|
|
||||||
// Parsing the specified input file.
|
|
||||||
PP.SetCommentRetentionState(false, false);
|
PP.SetCommentRetentionState(false, false);
|
||||||
BuildASTs(PP, MainFileID, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
|
|
||||||
|
|
||||||
/// PrintProblem - This takes a diagnostic map of the delta between expected and
|
/// PrintProblem - This takes a diagnostic map of the delta between expected and
|
||||||
/// seen diagnostics. If there's anything in it, then something unexpected
|
/// seen diagnostics. If there's anything in it, then something unexpected
|
||||||
/// happened. Print the map out in a nice format and return "true". If the map
|
/// happened. Print the map out in a nice format and return "true". If the map
|
||||||
|
@ -175,14 +167,17 @@ static bool CompareDiagLists(SourceManager &SourceMgr,
|
||||||
return PrintProblem(SourceMgr, DiffList.begin(), DiffList.end(), Msg);
|
return PrintProblem(SourceMgr, DiffList.begin(), DiffList.end(), Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ReportCheckingResults - This compares the expected results to those that
|
/// CheckResults - This compares the expected results to those that
|
||||||
/// were actually reported. It emits any discrepencies. Return "true" if there
|
/// were actually reported. It emits any discrepencies. Return "true" if there
|
||||||
/// were problems. Return "false" otherwise.
|
/// were problems. Return "false" otherwise.
|
||||||
///
|
///
|
||||||
static bool ReportCheckingResults(const TextDiagnosticBuffer &DiagClient,
|
static bool CheckResults(Preprocessor &PP,
|
||||||
const DiagList &ExpectedErrors,
|
const DiagList &ExpectedErrors,
|
||||||
const DiagList &ExpectedWarnings,
|
const DiagList &ExpectedWarnings) {
|
||||||
SourceManager &SourceMgr) {
|
const TextDiagnosticBuffer &Diags =
|
||||||
|
static_cast<const TextDiagnosticBuffer&>(PP.getDiagnostics().getClient());
|
||||||
|
SourceManager &SourceMgr = PP.getSourceManager();
|
||||||
|
|
||||||
// We want to capture the delta between what was expected and what was
|
// We want to capture the delta between what was expected and what was
|
||||||
// seen.
|
// seen.
|
||||||
//
|
//
|
||||||
|
@ -193,12 +188,12 @@ static bool ReportCheckingResults(const TextDiagnosticBuffer &DiagClient,
|
||||||
// See if there were errors that were expected but not seen.
|
// See if there were errors that were expected but not seen.
|
||||||
HadProblem |= CompareDiagLists(SourceMgr,
|
HadProblem |= CompareDiagLists(SourceMgr,
|
||||||
ExpectedErrors.begin(), ExpectedErrors.end(),
|
ExpectedErrors.begin(), ExpectedErrors.end(),
|
||||||
DiagClient.err_begin(), DiagClient.err_end(),
|
Diags.err_begin(), Diags.err_end(),
|
||||||
"Errors expected but not seen:");
|
"Errors expected but not seen:");
|
||||||
|
|
||||||
// See if there were errors that were seen but not expected.
|
// See if there were errors that were seen but not expected.
|
||||||
HadProblem |= CompareDiagLists(SourceMgr,
|
HadProblem |= CompareDiagLists(SourceMgr,
|
||||||
DiagClient.err_begin(), DiagClient.err_end(),
|
Diags.err_begin(), Diags.err_end(),
|
||||||
ExpectedErrors.begin(), ExpectedErrors.end(),
|
ExpectedErrors.begin(), ExpectedErrors.end(),
|
||||||
"Errors seen but not expected:");
|
"Errors seen but not expected:");
|
||||||
|
|
||||||
|
@ -206,12 +201,12 @@ static bool ReportCheckingResults(const TextDiagnosticBuffer &DiagClient,
|
||||||
HadProblem |= CompareDiagLists(SourceMgr,
|
HadProblem |= CompareDiagLists(SourceMgr,
|
||||||
ExpectedWarnings.begin(),
|
ExpectedWarnings.begin(),
|
||||||
ExpectedWarnings.end(),
|
ExpectedWarnings.end(),
|
||||||
DiagClient.warn_begin(), DiagClient.warn_end(),
|
Diags.warn_begin(), Diags.warn_end(),
|
||||||
"Warnings expected but not seen:");
|
"Warnings expected but not seen:");
|
||||||
|
|
||||||
// See if there were warnings that were seen but not expected.
|
// See if there were warnings that were seen but not expected.
|
||||||
HadProblem |= CompareDiagLists(SourceMgr,
|
HadProblem |= CompareDiagLists(SourceMgr,
|
||||||
DiagClient.warn_begin(), DiagClient.warn_end(),
|
Diags.warn_begin(), Diags.warn_end(),
|
||||||
ExpectedWarnings.begin(),
|
ExpectedWarnings.begin(),
|
||||||
ExpectedWarnings.end(),
|
ExpectedWarnings.end(),
|
||||||
"Warnings seen but not expected:");
|
"Warnings seen but not expected:");
|
||||||
|
@ -223,14 +218,13 @@ static bool ReportCheckingResults(const TextDiagnosticBuffer &DiagClient,
|
||||||
bool clang::CheckDiagnostics(Preprocessor &PP, unsigned MainFileID) {
|
bool clang::CheckDiagnostics(Preprocessor &PP, unsigned MainFileID) {
|
||||||
// Gather the set of expected diagnostics.
|
// Gather the set of expected diagnostics.
|
||||||
DiagList ExpectedErrors, ExpectedWarnings;
|
DiagList ExpectedErrors, ExpectedWarnings;
|
||||||
ProcessFileDiagnosticChecking(PP, MainFileID, ExpectedErrors,
|
FindExpectedDiags(PP, MainFileID, ExpectedErrors, ExpectedWarnings);
|
||||||
ExpectedWarnings);
|
|
||||||
|
|
||||||
const TextDiagnosticBuffer &Diags =
|
|
||||||
static_cast<const TextDiagnosticBuffer&>(PP.getDiagnostics().getClient());
|
|
||||||
|
|
||||||
return ReportCheckingResults(Diags, ExpectedErrors,
|
// Parse the specified input file.
|
||||||
ExpectedWarnings, PP.getSourceManager());
|
BuildASTs(PP, MainFileID, false);
|
||||||
|
|
||||||
|
// Check that the expected diagnostics occurred.
|
||||||
|
return CheckResults(PP, ExpectedErrors, ExpectedWarnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue