clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Friends | List of all members
clang::tidy::ClangTidyContext Class Reference

Every `ClangTidyCheck` reports errors through a `DiagnosticsEngine` provided by this context. More...

`#include <ClangTidyDiagnosticConsumer.h>`

## Public Member Functions
| ClangTidyContext (std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider)
| Initializes `ClangTidyContext` instance. More...
DiagnosticBuilder | diag (StringRef CheckName, SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
| Report any errors detected using this method. More...
void | setSourceManager (SourceManager *SourceMgr)
| Sets the `SourceManager` of the used `DiagnosticsEngine`. More...
void | setCurrentFile (StringRef File)
| Should be called when starting to process new translation unit. More...
StringRef | getCurrentFile () const
| Returns the main file name of the current translation unit. More...
void | setASTContext (ASTContext *Context)
| Sets ASTContext for the current translation unit. More...
LangOptions | getLangOpts () const
| Gets the language options from the AST context. More...
StringRef | getCheckName (unsigned DiagnosticID) const
| Returns the name of the clang-tidy check which produced this diagnostic ID. More...
GlobList & | getChecksFilter ()
| Returns check filter for the `CurrentFile`. More...
bool | isCheckEnabled (StringRef CheckName) const
| Returns true if the check name is enabled for the `CurrentFile`. More...
const ClangTidyGlobalOptions & | getGlobalOptions () const
| Returns global options. More...
const ClangTidyOptions & | getOptions () const
| Returns options for `CurrentFile`. More...
ClangTidyOptions | getOptionsForFile (StringRef File) const
| Returns options for `File`. More...
const ClangTidyStats & | getStats () const
| Returns `ClangTidyStats` containing issued and ignored diagnostic counters. More...
const std::vector < ClangTidyError > & | getErrors () const
| Returns all collected errors. More...
void | clearErrors ()
| Clears collected errors. More...
void | setCheckProfileData (ProfileData *Profile)
| Set the output struct for profile data. More...
ProfileData * | getCheckProfileData () const

## Friends
class | ClangTidyDiagnosticConsumer

## Detailed Description

Every `ClangTidyCheck` reports errors through a `DiagnosticsEngine` provided by this context.

A `ClangTidyCheck` always has access to the active context to report warnings like:

Context->Diag(Loc, "Single-argument constructors must be explicit")
<< FixItHint::CreateInsertion(Loc, "explicit ");

Definition at line 124 of file ClangTidyDiagnosticConsumer.h.

## Constructor & Destructor Documentation

ClangTidyContext::ClangTidyContext | ( | std::unique_ptr< ClangTidyOptionsProvider > | OptionsProvider | ) |

Initializes `ClangTidyContext` instance.

Definition at line 161 of file ClangTidyDiagnosticConsumer.cpp.

References setCurrentFile().

## Member Function Documentation

void clang::tidy::ClangTidyContext::clearErrors | ( |  | ) |
| inline

Clears collected errors.

Definition at line 187 of file ClangTidyDiagnosticConsumer.h.

DiagnosticBuilder ClangTidyContext::diag | ( | StringRef | CheckName,
|  | SourceLocation | Loc,
|  | StringRef | Message,
|  | DiagnosticIDs::Level | Level = `DiagnosticIDs::Warning`
| ) |  |

Report any errors detected using this method.

This is still under heavy development and will likely change towards using tablegen'd diagnostic IDs. FIXME: Figure out a way to manage ID spaces.

Definition at line 170 of file ClangTidyDiagnosticConsumer.cpp.

References clang::tidy::ClangTidyStats::ErrorsIgnoredNOLINT.

Referenced by clang::tidy::ClangTidyCheck::diag().

StringRef ClangTidyContext::getCheckName | ( | unsigned | DiagnosticID | ) | const

Returns the name of the clang-tidy check which produced this diagnostic ID.

Definition at line 245 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::ClangTidyDiagnosticConsumer::HandleDiagnostic().

ProfileData* clang::tidy::ClangTidyContext::getCheckProfileData | ( |  | ) | const
| inline

Definition at line 194 of file ClangTidyDiagnosticConsumer.h.

Referenced by clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer().

GlobList & ClangTidyContext::getChecksFilter | ( |  | ) |

Returns check filter for the `CurrentFile`.

The `CurrentFile` can be changed using `setCurrentFile`.

Definition at line 231 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer(), clang::tidy::ClangTidyCheckFactories::createChecks(), and clang::tidy::ClangTidyASTConsumerFactory::getCheckNames().

StringRef clang::tidy::ClangTidyContext::getCurrentFile | ( |  | ) | const
| inline

Returns the main file name of the current translation unit.

Definition at line 147 of file ClangTidyDiagnosticConsumer.h.

Referenced by clang::tidy::ClangTidyCheck::getCurrentMainFile().

const std::vector<ClangTidyError>& clang::tidy::ClangTidyContext::getErrors | ( |  | ) | const
| inline

Returns all collected errors.

Definition at line 184 of file ClangTidyDiagnosticConsumer.h.

Referenced by clang::tidy::runClangTidy().

const ClangTidyGlobalOptions & ClangTidyContext::getGlobalOptions | ( |  | ) | const

Returns global options.

Definition at line 214 of file ClangTidyDiagnosticConsumer.cpp.

LangOptions clang::tidy::ClangTidyContext::getLangOpts | ( |  | ) | const
| inline

Gets the language options from the AST context.

Definition at line 153 of file ClangTidyDiagnosticConsumer.h.

Referenced by clang::tidy::ClangTidyCheck::getLangOpts().

const ClangTidyOptions & ClangTidyContext::getOptions | ( |  | ) | const

Returns options for `CurrentFile`.

The `CurrentFile` can be changed using `setCurrentFile`.

Definition at line 218 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer(), and setCurrentFile().

ClangTidyOptions ClangTidyContext::getOptionsForFile | ( | StringRef | File | ) | const

Returns options for `File`.

Does not change or depend on `CurrentFile`.

Definition at line 222 of file ClangTidyDiagnosticConsumer.cpp.

References clang::tidy::ClangTidyOptions::getDefaults(), and clang::tidy::ClangTidyOptions::mergeWith().

Referenced by clang::tidy::runClangTidy(), and setCurrentFile().

const ClangTidyStats& clang::tidy::ClangTidyContext::getStats | ( |  | ) | const
| inline

Returns `ClangTidyStats` containing issued and ignored diagnostic counters.

Definition at line 181 of file ClangTidyDiagnosticConsumer.h.

Referenced by clang::tidy::runClangTidy().

bool ClangTidyContext::isCheckEnabled | ( | StringRef | CheckName | ) | const

Returns true if the check name is enabled for the `CurrentFile`.

Definition at line 236 of file ClangTidyDiagnosticConsumer.cpp.

void ClangTidyContext::setASTContext | ( | ASTContext * | Context | ) |

Sets ASTContext for the current translation unit.

Definition at line 209 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer().

void ClangTidyContext::setCheckProfileData | ( | ProfileData * | Profile | ) |

Set the output struct for profile data.

Setting a non-null pointer here will enable profile collection in clang-tidy.

Definition at line 229 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::runClangTidy().

void ClangTidyContext::setCurrentFile | ( | StringRef | File | ) |

Should be called when starting to process new translation unit.

Definition at line 203 of file ClangTidyDiagnosticConsumer.cpp.

References Checks, File, getOptions(), and getOptionsForFile().

Referenced by ClangTidyContext(), and clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer().

void ClangTidyContext::setSourceManager | ( | SourceManager * | SourceMgr | ) |

Sets the `SourceManager` of the used `DiagnosticsEngine`.

This is called from the `ClangTidyCheck` base class.

Definition at line 199 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by clang::tidy::ClangTidyASTConsumerFactory::CreateASTConsumer().

## Friends And Related Function Documentation

friend class ClangTidyDiagnosticConsumer
| friend

Definition at line 198 of file ClangTidyDiagnosticConsumer.h.

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

- ClangTidyDiagnosticConsumer.h
- ClangTidyDiagnosticConsumer.cpp