|
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 ()=default | |
| 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, StringRef message, bool reportUnexpected=true) |
Matches a single actual diagnostic against the expected diagnostics recorded for buf / lineNo, 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. | |
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.
|
default |
References computeExpectedDiags(), and getExpectedDiags().
| 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 84 of file SourceMgrDiagnosticVerifier.cpp.
References assert(), 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::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(), and SourceMgrDiagnosticVerifier().
| 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 175 of file SourceMgrDiagnosticVerifier.cpp.
References llvm::MutableArrayRef().
Referenced by process(), and SourceMgrDiagnosticVerifier().
|
inline |
Returns the expected diagnostics with an '@unknown' location.
Definition at line 102 of file SourceMgrDiagnosticVerifier.h.
| SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process | ( | raw_ostream & | os, |
| SourceMgr & | mgr, | ||
| SourceMgr::DiagKind | kind, | ||
| bool | hasLoc, | ||
| const MemoryBuffer * | buf, | ||
| unsigned | lineNo, | ||
| StringRef | message, | ||
| bool | reportUnexpected = true ) |
Matches a single actual diagnostic against the expected diagnostics recorded for buf / lineNo, 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 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 183 of file SourceMgrDiagnosticVerifier.cpp.
References computeExpectedDiags(), llvm::SourceMgr::DK_Error, llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::fileLoc, llvm::MemoryBuffer::getBufferIdentifier(), getDiagKindStr(), getExpectedDiags(), hasLoc(), Ignored, llvm::SourceMgrDiagnosticVerifier::ExpectedDiag::kind, Matched, NearMiss, llvm::SourceMgr::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 238 of file SourceMgrDiagnosticVerifier.cpp.
References getDiagKindStr().