clang API Documentation

Public Member Functions | Public Attributes
clang::VerifyDiagnosticConsumer Class Reference

#include <VerifyDiagnosticConsumer.h>

Inheritance diagram for clang::VerifyDiagnosticConsumer:
Inheritance graph
[legend]
Collaboration diagram for clang::VerifyDiagnosticConsumer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 VerifyDiagnosticConsumer (DiagnosticsEngine &Diags)
 ~VerifyDiagnosticConsumer ()
virtual void BeginSourceFile (const LangOptions &LangOpts, const Preprocessor *PP)
virtual void EndSourceFile ()
virtual void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
virtual DiagnosticConsumerclone (DiagnosticsEngine &Diags) const
 Clone the diagnostic consumer, producing an equivalent consumer that can be used in a different context.

Public Attributes

DiagnosticsEngineDiags
DiagnosticConsumerPrimaryClient
bool OwnsPrimaryClient
OwningPtr< TextDiagnosticBufferBuffer
PreprocessorCurrentPreprocessor

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.

USING THE DIAGNOSTIC CHECKER:

Indicating that a line expects an error or a warning is simple. Put a comment on the line that has the diagnostic, use:

expected-{error,warning,note}

to tag if it's an expected error or warning, and place the expected text between {{ and }} markers. The full text doesn't have to be included, only enough to ensure that the correct diagnostic was emitted.

Here's an example:

int A = B; // expected-error {{use of undeclared identifier 'B'}}

You can place as many diagnostics on one line as you wish. To make the code more readable, you can use slash-newline to separate out the diagnostics.

The simple syntax above allows each specification to match exactly one error. You can use the extended syntax to customize this. The extended syntax is "expected-<type> <n> {{diag text}}", where <type> is one of "error", "warning" or "note", and <n> is a positive integer. This allows the diagnostic to appear as many times as specified. Example:

void f(); // expected-note 2 {{previous declaration is here}}

Regex matching mode may be selected by appending '-re' to type. Example:

expected-error-re

Examples matching error: "variable has incomplete type 'struct s'"

expected-error {{variable has incomplete type 'struct s'}} expected-error {{variable has incomplete type}}

expected-error-re {{variable has has type 'struct .'}} expected-error-re {{variable has has type 'struct .*'}} expected-error-re {{variable has has type 'struct (.*)'}} expected-error-re {{variable has has type 'struct[[:space:]](.*)'}}

Definition at line 65 of file VerifyDiagnosticConsumer.h.


Constructor & Destructor Documentation

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 25 of file VerifyDiagnosticConsumer.cpp.

References Diags, and clang::DiagnosticsEngine::takeClient().

Referenced by clone().

VerifyDiagnosticConsumer::~VerifyDiagnosticConsumer ( )

Member Function Documentation

void VerifyDiagnosticConsumer::BeginSourceFile ( const LangOptions LangOpts,
const Preprocessor PP 
) [virtual]

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

  • LO - The language options for the source file being processed.
  • PP - The preprocessor object being used for the source; this optional and may not be present, for example when processing AST source files.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 42 of file VerifyDiagnosticConsumer.cpp.

References clang::DiagnosticConsumer::BeginSourceFile(), CurrentPreprocessor, and PrimaryClient.

DiagnosticConsumer * VerifyDiagnosticConsumer::clone ( DiagnosticsEngine Diags) const [virtual]

Clone the diagnostic consumer, producing an equivalent consumer that can be used in a different context.

Implements clang::DiagnosticConsumer.

Definition at line 545 of file VerifyDiagnosticConsumer.cpp.

References clang::DiagnosticConsumer::clone(), clang::DiagnosticsEngine::getClient(), PrimaryClient, clang::DiagnosticsEngine::setClient(), and VerifyDiagnosticConsumer().

void VerifyDiagnosticConsumer::EndSourceFile ( ) [virtual]

EndSourceFile - 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

See also:
BeginSourceFile() are inaccessible.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 52 of file VerifyDiagnosticConsumer.cpp.

References CurrentPreprocessor, clang::DiagnosticConsumer::EndSourceFile(), and PrimaryClient.

void VerifyDiagnosticConsumer::HandleDiagnostic ( DiagnosticsEngine::Level  DiagLevel,
const Diagnostic Info 
) [virtual]

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

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

Reimplemented from clang::DiagnosticConsumer.

Definition at line 60 of file VerifyDiagnosticConsumer.cpp.

References Buffer, clang::SourceManager::getFileID(), clang::Diagnostic::getLocation(), clang::Diagnostic::getSourceManager(), clang::Diagnostic::hasSourceManager(), and clang::FileID::isInvalid().


Member Data Documentation

Definition at line 70 of file VerifyDiagnosticConsumer.h.

Referenced by HandleDiagnostic().

Definition at line 71 of file VerifyDiagnosticConsumer.h.

Referenced by BeginSourceFile(), and EndSourceFile().

Definition at line 69 of file VerifyDiagnosticConsumer.h.

Referenced by ~VerifyDiagnosticConsumer().


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