LLVM 24.0.0git
llvm::SourceMgrDiagnosticVerifier Class Reference

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.

Detailed Description

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.

Member Enumeration Documentation

◆ MatchResult

The result of matching a single actual diagnostic against the expected diagnostics recorded for its location.

Enumerator
Matched 

The diagnostic matched an expected diagnostic (kind and text).

NearMiss 

The diagnostic's text matched an expected diagnostic, but its kind didn't; a message about this has already been printed.

Unexpected 

The diagnostic did not match any expected diagnostic.

The caller is responsible for reporting it, if desired.

Ignored 

The diagnostic did not match, but reportUnexpected was false, so nothing was printed and nothing needs to be done.

Definition at line 40 of file SourceMgrDiagnosticVerifier.h.

Constructor & Destructor Documentation

◆ SourceMgrDiagnosticVerifier()

llvm::SourceMgrDiagnosticVerifier::SourceMgrDiagnosticVerifier ( )
default

Member Function Documentation

◆ computeExpectedDiags()

◆ getExpectedDiags()

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().

◆ getExpectedUnknownLocDiags()

MutableArrayRef< ExpectedDiag > llvm::SourceMgrDiagnosticVerifier::getExpectedUnknownLocDiags ( )
inline

Returns the expected diagnostics with an '@unknown' location.

Definition at line 102 of file SourceMgrDiagnosticVerifier.h.

◆ process()

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.

◆ verify()

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().


The documentation for this class was generated from the following files: