clang 22.0.0git
clang::VerifyDiagnosticConsumer Class Reference

VerifyDiagnosticConsumer - Create a diagnostic client which will use markers in the input source to check that all the emitted diagnostics match those expected. More...

#include "clang/Frontend/VerifyDiagnosticConsumer.h"

Inheritance diagram for clang::VerifyDiagnosticConsumer:
[legend]

Classes

class  Directive
 Directive - Abstract class representing a parsed verify directive. More...
struct  ExpectedData
 ExpectedData - owns directive objects and deletes on destructor. More...
class  MarkerTracker
struct  ParsingState

Public Types

enum  DirectiveStatus { HasNoDirectives , HasNoDirectivesReported , HasExpectedNoDiagnostics , HasOtherExpectedDirectives }
enum  ParsedStatus { IsParsed , IsUnparsed , IsUnparsedNoDirectives }
using DirectiveList = std::vector<std::unique_ptr<Directive>>

Public Member Functions

 VerifyDiagnosticConsumer (DiagnosticsEngine &Diags)
 Create a new verifying diagnostic client, which will issue errors to the currently-attached diagnostic client when a diagnostic does not match what is expected (as indicated in the source file).
 ~VerifyDiagnosticConsumer () override
void BeginSourceFile (const LangOptions &LangOpts, const Preprocessor *PP) override
 Callback to inform the diagnostic client that processing of a source file is beginning.
void EndSourceFile () override
 Callback to inform the diagnostic client that processing of a source file has ended.
void UpdateParsedFileStatus (SourceManager &SM, FileID FID, ParsedStatus PS)
 Update lists of parsed and unparsed files.
bool HandleComment (Preprocessor &PP, SourceRange Comment) override
 HandleComment - Hook into the preprocessor and extract comments containing expected errors and warnings.
void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
 Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Public Member Functions inherited from clang::DiagnosticConsumer
 DiagnosticConsumer ()=default
virtual ~DiagnosticConsumer ()
unsigned getNumErrors () const
unsigned getNumWarnings () const
virtual void clear ()
virtual void finish ()
 Callback to inform the diagnostic client that processing of all source files has ended.
virtual bool IncludeInDiagnosticCounts () const
 Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number of diagnostics reported by DiagnosticsEngine.
Public Member Functions inherited from clang::CommentHandler
virtual ~CommentHandler ()

Additional Inherited Members

Protected Attributes inherited from clang::DiagnosticConsumer
unsigned NumWarnings = 0
 Number of warnings reported.
unsigned NumErrors = 0
 Number of errors reported.

Detailed Description

VerifyDiagnosticConsumer - Create a diagnostic client which will use markers in the input source to check that all the emitted diagnostics match those expected.

See clang/docs/InternalsManual.rst for details about how to write tests to verify diagnostics.

Definition at line 38 of file VerifyDiagnosticConsumer.h.

Member Typedef Documentation

◆ DirectiveList

using clang::VerifyDiagnosticConsumer::DirectiveList = std::vector<std::unique_ptr<Directive>>

Definition at line 88 of file VerifyDiagnosticConsumer.h.

Member Enumeration Documentation

◆ DirectiveStatus

Enumerator
HasNoDirectives 
HasNoDirectivesReported 
HasExpectedNoDiagnostics 
HasOtherExpectedDirectives 

Definition at line 105 of file VerifyDiagnosticConsumer.h.

◆ ParsedStatus

Enumerator
IsParsed 

File has been processed via HandleComment.

IsUnparsed 

File has diagnostics and may have directives.

IsUnparsedNoDirectives 

File has diagnostics but guaranteed no directives.

Definition at line 170 of file VerifyDiagnosticConsumer.h.

Constructor & Destructor Documentation

◆ VerifyDiagnosticConsumer()

VerifyDiagnosticConsumer::VerifyDiagnosticConsumer ( DiagnosticsEngine & Diags)

Create a new verifying diagnostic client, which will issue errors to the currently-attached diagnostic client when a diagnostic does not match what is expected (as indicated in the source file).

Definition at line 677 of file VerifyDiagnosticConsumer.cpp.

References HasNoDirectives.

◆ ~VerifyDiagnosticConsumer()

VerifyDiagnosticConsumer::~VerifyDiagnosticConsumer ( )
override

Definition at line 686 of file VerifyDiagnosticConsumer.cpp.

Member Function Documentation

◆ BeginSourceFile()

void VerifyDiagnosticConsumer::BeginSourceFile ( const LangOptions & LangOpts,
const Preprocessor * PP )
overridevirtual

Callback to inform the diagnostic client that processing of a source file is beginning.

Note that diagnostics may be emitted outside the processing of a source file, for example during the parsing of command line options. However, diagnostics with source range information are required to only be emitted in between BeginSourceFile() and EndSourceFile().

Parameters
LangOptsThe language options for the source file being processed.
PPThe preprocessor object being used for the source; this is optional, e.g., it may not be present when processing AST source files.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 697 of file VerifyDiagnosticConsumer.cpp.

References clang::Preprocessor::getSourceManager().

◆ EndSourceFile()

void VerifyDiagnosticConsumer::EndSourceFile ( )
overridevirtual

Callback to inform the diagnostic client that processing of a source file has ended.

The diagnostic client should assume that any objects made available via BeginSourceFile() are inaccessible.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 718 of file VerifyDiagnosticConsumer.cpp.

◆ HandleComment()

bool VerifyDiagnosticConsumer::HandleComment ( Preprocessor & PP,
SourceRange Comment )
overridevirtual

HandleComment - Hook into the preprocessor and extract comments containing expected errors and warnings.

Implements clang::CommentHandler.

Definition at line 780 of file VerifyDiagnosticConsumer.cpp.

References clang::C, clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::Preprocessor::getSourceManager(), ParseDirective(), and SM.

◆ HandleDiagnostic()

void VerifyDiagnosticConsumer::HandleDiagnostic ( DiagnosticsEngine::Level DiagLevel,
const Diagnostic & Info )
overridevirtual

Handle this diagnostic, reporting it to the user or capturing it to a log as needed.

The default implementation just keeps track of the total number of warnings and errors.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 738 of file VerifyDiagnosticConsumer.cpp.

References clang::HeaderSearch::findModuleForHeader(), clang::Diagnostic::getLocation(), clang::Diagnostic::getSourceManager(), clang::Diagnostic::hasSourceManager(), IsUnparsed, IsUnparsedNoDirectives, clang::SourceLocation::isValid(), and UpdateParsedFileStatus().

◆ UpdateParsedFileStatus()

void VerifyDiagnosticConsumer::UpdateParsedFileStatus ( SourceManager & SM,
FileID FID,
ParsedStatus PS )

Update lists of parsed and unparsed files.

Definition at line 1047 of file VerifyDiagnosticConsumer.cpp.

References findDirectives(), clang::FileEntryRef::getFileEntry(), clang::FileID::isInvalid(), IsParsed, IsUnparsedNoDirectives, and SM.

Referenced by HandleDiagnostic().


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