clang-tools  10.0.0svn
Classes | Public Types | 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>

Classes

class  CachedGlobList
 

Public Types

using DiagLevelAndFormatString = std::pair< DiagnosticIDs::Level, std::string >
 

Public Member Functions

 ClangTidyContext (std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider, bool AllowEnablingAnalyzerAlphaCheckers=false)
 Initializes ClangTidyContext instance. More...
 
void setDiagnosticsEngine (DiagnosticsEngine *DiagEngine)
 Sets the DiagnosticsEngine that diag() will emit diagnostics to. More...
 
 ~ClangTidyContext ()
 
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...
 
const LangOptions & getLangOpts () const
 Gets the language options from the AST context. More...
 
std::string getCheckName (unsigned DiagnosticID) const
 Returns the name of the clang-tidy check which produced this diagnostic ID. More...
 
bool isCheckEnabled (StringRef CheckName) const
 Returns true if the check is enabled for the CurrentFile. More...
 
bool treatAsError (StringRef CheckName) const
 Returns true if the check should be upgraded to error for the CurrentFile. More...
 
const ClangTidyGlobalOptionsgetGlobalOptions () const
 Returns global options. More...
 
const ClangTidyOptionsgetOptions () const
 Returns options for CurrentFile. More...
 
ClangTidyOptions getOptionsForFile (StringRef File) const
 Returns options for File. More...
 
const ClangTidyStatsgetStats () const
 Returns ClangTidyStats containing issued and ignored diagnostic counters. More...
 
void setEnableProfiling (bool Profile)
 Control profile collection in clang-tidy. More...
 
bool getEnableProfiling () const
 
void setProfileStoragePrefix (StringRef ProfilePrefix)
 Control storage of profile date. More...
 
llvm::Optional< ClangTidyProfiling::StorageParamsgetProfileStorageParams () const
 
void setCurrentBuildDirectory (StringRef BuildDirectory)
 Should be called when starting to process new translation unit. More...
 
const std::string & getCurrentBuildDirectory ()
 Returns build directory of the current translation unit. More...
 
bool canEnableAnalyzerAlphaCheckers () const
 If the experimental alpha checkers from the static analyzer can be enabled. More...
 
DiagLevelAndFormatString getDiagLevelAndFormatString (unsigned DiagnosticID, SourceLocation Loc)
 

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 77 of file ClangTidyDiagnosticConsumer.h.

Member Typedef Documentation

◆ DiagLevelAndFormatString

using clang::tidy::ClangTidyContext::DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>

Definition at line 171 of file ClangTidyDiagnosticConsumer.h.

Constructor & Destructor Documentation

◆ ClangTidyContext()

ClangTidyContext::ClangTidyContext ( std::unique_ptr< ClangTidyOptionsProvider OptionsProvider,
bool  AllowEnablingAnalyzerAlphaCheckers = false 
)

Initializes ClangTidyContext instance.

Definition at line 146 of file ClangTidyDiagnosticConsumer.cpp.

References setCurrentFile(), and ~ClangTidyContext().

◆ ~ClangTidyContext()

ClangTidyContext::~ClangTidyContext ( )
default

Referenced by ClangTidyContext().

Member Function Documentation

◆ canEnableAnalyzerAlphaCheckers()

bool clang::tidy::ClangTidyContext::canEnableAnalyzerAlphaCheckers ( ) const
inline

If the experimental alpha checkers from the static analyzer can be enabled.

Definition at line 167 of file ClangTidyDiagnosticConsumer.h.

References AllowEnablingAnalyzerAlphaCheckers().

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

◆ diag()

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 159 of file ClangTidyDiagnosticConsumer.cpp.

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

◆ getCheckName()

std::string ClangTidyContext::getCheckName ( unsigned  DiagnosticID) const

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

Definition at line 225 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by IsNOLINTFound(), and clang::clangd::StoreDiags::take().

◆ getCurrentBuildDirectory()

const std::string& clang::tidy::ClangTidyContext::getCurrentBuildDirectory ( )
inline

Returns build directory of the current translation unit.

Definition at line 161 of file ClangTidyDiagnosticConsumer.h.

◆ getCurrentFile()

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

Returns the main file name of the current translation unit.

Definition at line 109 of file ClangTidyDiagnosticConsumer.h.

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

◆ getDiagLevelAndFormatString()

DiagLevelAndFormatString clang::tidy::ClangTidyContext::getDiagLevelAndFormatString ( unsigned  DiagnosticID,
SourceLocation  Loc 
)
inline

Definition at line 172 of file ClangTidyDiagnosticConsumer.h.

◆ getEnableProfiling()

bool clang::tidy::ClangTidyContext::getEnableProfiling ( ) const
inline

Definition at line 148 of file ClangTidyDiagnosticConsumer.h.

◆ getGlobalOptions()

const ClangTidyGlobalOptions & ClangTidyContext::getGlobalOptions ( ) const

Returns global options.

Definition at line 186 of file ClangTidyDiagnosticConsumer.cpp.

◆ getLangOpts()

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

Gets the language options from the AST context.

Definition at line 115 of file ClangTidyDiagnosticConsumer.h.

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

◆ getOptions()

const ClangTidyOptions & ClangTidyContext::getOptions ( ) const

Returns options for CurrentFile.

The CurrentFile can be changed using setCurrentFile.

Definition at line 190 of file ClangTidyDiagnosticConsumer.cpp.

Referenced by setCurrentFile().

◆ getOptionsForFile()

ClangTidyOptions ClangTidyContext::getOptionsForFile ( StringRef  File) const

Returns options for File.

Does not change or depend on CurrentFile.

Definition at line 194 of file ClangTidyDiagnosticConsumer.cpp.

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

Referenced by setCurrentFile().

◆ getProfileStorageParams()

llvm::Optional< ClangTidyProfiling::StorageParams > ClangTidyContext::getProfileStorageParams ( ) const

Definition at line 208 of file ClangTidyDiagnosticConsumer.cpp.

◆ getStats()

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

Returns ClangTidyStats containing issued and ignored diagnostic counters.

Definition at line 144 of file ClangTidyDiagnosticConsumer.h.

◆ isCheckEnabled()

bool ClangTidyContext::isCheckEnabled ( StringRef  CheckName) const

Returns true if the check is enabled for the CurrentFile.

The CurrentFile can be changed using setCurrentFile.

Definition at line 215 of file ClangTidyDiagnosticConsumer.cpp.

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

◆ setASTContext()

void ClangTidyContext::setASTContext ( ASTContext *  Context)

Sets ASTContext for the current translation unit.

Definition at line 181 of file ClangTidyDiagnosticConsumer.cpp.

◆ setCurrentBuildDirectory()

void clang::tidy::ClangTidyContext::setCurrentBuildDirectory ( StringRef  BuildDirectory)
inline

Should be called when starting to process new translation unit.

Definition at line 156 of file ClangTidyDiagnosticConsumer.h.

◆ setCurrentFile()

void ClangTidyContext::setCurrentFile ( StringRef  File)

Should be called when starting to process new translation unit.

Definition at line 173 of file ClangTidyDiagnosticConsumer.cpp.

References clang::tidy::ClangTidyOptions::Checks, getOptions(), getOptionsForFile(), and clang::tidy::ClangTidyOptions::WarningsAsErrors.

Referenced by ClangTidyContext().

◆ setDiagnosticsEngine()

void clang::tidy::ClangTidyContext::setDiagnosticsEngine ( DiagnosticsEngine *  DiagEngine)
inline

Sets the DiagnosticsEngine that diag() will emit diagnostics to.

Definition at line 85 of file ClangTidyDiagnosticConsumer.h.

References Loc, and clang::tidy::modernize::Message.

◆ setEnableProfiling()

void ClangTidyContext::setEnableProfiling ( bool  Profile)

Control profile collection in clang-tidy.

Definition at line 201 of file ClangTidyDiagnosticConsumer.cpp.

◆ setProfileStoragePrefix()

void ClangTidyContext::setProfileStoragePrefix ( StringRef  ProfilePrefix)

Control storage of profile date.

Definition at line 203 of file ClangTidyDiagnosticConsumer.cpp.

◆ setSourceManager()

void ClangTidyContext::setSourceManager ( SourceManager *  SourceMgr)

Sets the SourceManager of the used DiagnosticsEngine.

This is called from the ClangTidyCheck base class.

Definition at line 169 of file ClangTidyDiagnosticConsumer.cpp.

◆ treatAsError()

bool ClangTidyContext::treatAsError ( StringRef  CheckName) const

Returns true if the check should be upgraded to error for the CurrentFile.

Definition at line 220 of file ClangTidyDiagnosticConsumer.cpp.

Friends And Related Function Documentation

◆ ClangTidyDiagnosticConsumer

friend class ClangTidyDiagnosticConsumer
friend

Definition at line 182 of file ClangTidyDiagnosticConsumer.h.


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