|
LLVM 24.0.0git
|
Scans SourceMgr source buffers for 'expected-<kind>' comments (e.g. More...
#include "llvm/Support/SourceMgrDiagnosticVerifier.h"
Classes | |
| struct | ExpectedDiag |
| A single diagnostic expected via an 'expected-<kind>' comment. More... | |
Public Types | |
| enum class | MatchResult { Matched , NearMiss , Unexpected , Ignored } |
| The result of matching a single actual diagnostic against the expected diagnostics recorded for its location. More... | |
Public Member Functions | |
| SourceMgrDiagnosticVerifier (ArrayRef< StringRef > prefixes={ "expected"}) | |
Recognizes directives starting with any of prefixes (e.g. | |
| SourceMgrDiagnosticVerifier (const SourceMgrDiagnosticVerifier &)=delete | |
| SourceMgrDiagnosticVerifier & | operator= (const SourceMgrDiagnosticVerifier &)=delete |
| MutableArrayRef< ExpectedDiag > | computeExpectedDiags (raw_ostream &os, SourceMgr &mgr, const MemoryBuffer *buf) |
Computes and caches the list of expected diagnostics for buf, if not already cached. | |
| std::optional< MutableArrayRef< ExpectedDiag > > | getExpectedDiags (StringRef bufName) |
Returns the cached expected diagnostics for the buffer named bufName, or std::nullopt if computeExpectedDiags hasn't been called for it. | |
| MutableArrayRef< ExpectedDiag > | getExpectedUnknownLocDiags () |
| Returns the expected diagnostics with an '@unknown' location. | |
| MatchResult | process (raw_ostream &os, SourceMgr &mgr, SourceMgr::DiagKind kind, bool hasLoc, const MemoryBuffer *buf, unsigned lineNo, unsigned colNo, StringRef message, bool reportUnexpected=true) |
Matches a single actual diagnostic against the expected diagnostics recorded for buf / lineNo / colNo (1-based), computing them first via computeExpectedDiags if they haven't been already. | |
| bool | verify (raw_ostream &os, SourceMgr &mgr) |
Reports (through mgr) any expected diagnostic that was never matched by a call to process. | |
Static Public Member Functions | |
| static StringRef | getDiagKindStr (SourceMgr::DiagKind kind) |
| Given a diagnostic kind, return a human readable string for it. | |
| static void | printMessage (raw_ostream &os, const SourceMgr &mgr, SMLoc loc, const Twine &msg, ArrayRef< SMRange > ranges={}) |
Prints an error to os without going through mgr's diagnostic handler, which may be the one feeding the verifier. | |
Scans SourceMgr source buffers for 'expected-<kind>' comments (e.g.
'expected-error {{message}}') and verifies that the diagnostics reported to it via process match them, and that every expected diagnostic is matched at least once.
Definition at line 36 of file SourceMgrDiagnosticVerifier.h.
|
strong |
The result of matching a single actual diagnostic against the expected diagnostics recorded for its location.
Definition at line 40 of file SourceMgrDiagnosticVerifier.h.
|
explicit |
Recognizes directives starting with any of prefixes (e.g.
'expected-error').
Definition at line 108 of file SourceMgrDiagnosticVerifier.cpp.
References buildExpectedRegex().
Referenced by operator=(), and SourceMgrDiagnosticVerifier().
|
delete |
References SourceMgrDiagnosticVerifier().
| MutableArrayRef< SourceMgrDiagnosticVerifier::ExpectedDiag > SourceMgrDiagnosticVerifier::computeExpectedDiags | ( | raw_ostream & | os, |
| SourceMgr & | mgr, | ||
| const MemoryBuffer * | buf ) |
Computes and caches the list of expected diagnostics for buf, if not already cached.
Returns the (mutable) cached list.
Definition at line 113 of file SourceMgrDiagnosticVerifier.cpp.
References assert(), llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::colNo, llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::computeRegex(), llvm::StringRef::consume_front(), data, llvm::SourceMgr::DK_Error, llvm::SourceMgr::DK_Note, llvm::SourceMgr::DK_Remark, llvm::SourceMgr::DK_Warning, llvm::StringRef::drop_front(), llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::emitError(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::StringRef::empty(), llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::fileLoc, llvm::StringRef::front(), llvm::StringRef::getAsInteger(), llvm::MemoryBuffer::getBuffer(), llvm::MemoryBuffer::getBufferIdentifier(), llvm::SMLoc::getFromPointer(), llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::lineNo, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), and llvm::StringRef::split().
Referenced by process().
|
static |
Given a diagnostic kind, return a human readable string for it.
Definition at line 25 of file SourceMgrDiagnosticVerifier.cpp.
References llvm::SourceMgr::DK_Error, llvm::SourceMgr::DK_Note, llvm::SourceMgr::DK_Remark, llvm::SourceMgr::DK_Warning, and llvm_unreachable.
Referenced by operator=(), process(), and verify().
| std::optional< MutableArrayRef< SourceMgrDiagnosticVerifier::ExpectedDiag > > SourceMgrDiagnosticVerifier::getExpectedDiags | ( | StringRef | bufName | ) |
Returns the cached expected diagnostics for the buffer named bufName, or std::nullopt if computeExpectedDiags hasn't been called for it.
Definition at line 214 of file SourceMgrDiagnosticVerifier.cpp.
References llvm::MutableArrayRef().
Referenced by process().
|
inline |
Returns the expected diagnostics with an '@unknown' location.
Definition at line 120 of file SourceMgrDiagnosticVerifier.h.
|
delete |
References getDiagKindStr(), printMessage(), and SourceMgrDiagnosticVerifier().
|
static |
Prints an error to os without going through mgr's diagnostic handler, which may be the one feeding the verifier.
Definition at line 16 of file SourceMgrDiagnosticVerifier.cpp.
References llvm::SourceMgr::DK_Error, llvm::SourceMgr::GetMessage(), llvm::SMDiagnostic::print(), and llvm::SourceMgr::printIncludeStackForDiagnostic().
Referenced by llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::emitError(), operator=(), and process().
| SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process | ( | raw_ostream & | os, |
| SourceMgr & | mgr, | ||
| SourceMgr::DiagKind | kind, | ||
| bool | hasLoc, | ||
| const MemoryBuffer * | buf, | ||
| unsigned | lineNo, | ||
| unsigned | colNo, | ||
| StringRef | message, | ||
| bool | reportUnexpected = true ) |
Matches a single actual diagnostic against the expected diagnostics recorded for buf / lineNo / colNo (1-based), computing them first via computeExpectedDiags if they haven't been already.
If hasLoc is false, the diagnostic has no location and is matched against the '@unknown' list instead (buf / lineNo / colNo are ignored). If hasLoc is true but buf is null (e.g. the diagnostic's file isn't a known buffer), the diagnostic is matched against an empty list, i.e. it can never match and is always unexpected. On a near miss, prints a message through mgr. reportUnexpected controls whether near misses / unexpected diagnostics are reported at all.
Definition at line 221 of file SourceMgrDiagnosticVerifier.cpp.
References computeExpectedDiags(), llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::fileLoc, llvm::MemoryBuffer::getBufferIdentifier(), getDiagKindStr(), getExpectedDiags(), hasLoc(), Ignored, llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::kind, Matched, NearMiss, printMessage(), and Unexpected.
| bool SourceMgrDiagnosticVerifier::verify | ( | raw_ostream & | os, |
| SourceMgr & | mgr ) |
Reports (through mgr) any expected diagnostic that was never matched by a call to process.
Returns whether verification succeeded overall, i.e. no diagnostic mismatches were recorded either here or by process.
Definition at line 278 of file SourceMgrDiagnosticVerifier.cpp.
References getDiagKindStr().