clang-tools 19.0.0git
Protected Types | Protected Member Functions | Protected Attributes | List of all members
clang::tidy::FileOptionsBaseProvider Class Reference

#include <ClangTidyOptions.h>

Inheritance diagram for clang::tidy::FileOptionsBaseProvider:
Inheritance graph
[legend]

Protected Types

using ConfigFileHandler = std::pair< std::string, std::function< llvm::ErrorOr< ClangTidyOptions >(llvm::MemoryBufferRef)> >
 
using ConfigFileHandlers = std::vector< ConfigFileHandler >
 Configuration file handlers listed in the order of priority.
 

Protected Member Functions

 FileOptionsBaseProvider (ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
 
 FileOptionsBaseProvider (ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, ConfigFileHandlers ConfigHandlers)
 
void addRawFileOptions (llvm::StringRef AbsolutePath, std::vector< OptionsSource > &CurOptions)
 
std::optional< OptionsSourcetryReadConfigFile (llvm::StringRef Directory)
 Try to read configuration files from Directory using registered ConfigHandlers.
 

Protected Attributes

llvm::StringMap< OptionsSourceCachedOptions
 
ClangTidyOptions OverrideOptions
 
ConfigFileHandlers ConfigHandlers
 
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
 

Additional Inherited Members

- Public Types inherited from clang::tidy::ClangTidyOptionsProvider
using OptionsSource = std::pair< ClangTidyOptions, std::string >
 ClangTidyOptions and its source.
 
- Public Member Functions inherited from clang::tidy::DefaultOptionsProvider
 DefaultOptionsProvider (ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions Options)
 
const ClangTidyGlobalOptionsgetGlobalOptions () override
 Returns global options, which are independent of the file.
 
std::vector< OptionsSourcegetRawOptions (llvm::StringRef FileName) override
 Returns an ordered vector of OptionsSources, in order of increasing priority.
 
- Public Member Functions inherited from clang::tidy::ClangTidyOptionsProvider
virtual ~ClangTidyOptionsProvider ()
 
virtual const ClangTidyGlobalOptionsgetGlobalOptions ()=0
 Returns global options, which are independent of the file.
 
virtual std::vector< OptionsSourcegetRawOptions (llvm::StringRef FileName)=0
 Returns an ordered vector of OptionsSources, in order of increasing priority.
 
ClangTidyOptions getOptions (llvm::StringRef FileName)
 Returns options applying to a specific translation unit with the specified FileName.
 
- Static Public Attributes inherited from clang::tidy::ClangTidyOptionsProvider
static const char OptionsSourceTypeDefaultBinary []
 
static const char OptionsSourceTypeCheckCommandLineOption []
 
static const char OptionsSourceTypeConfigCommandLineOption []
 

Detailed Description

Definition at line 198 of file ClangTidyOptions.h.

Member Typedef Documentation

◆ ConfigFileHandler

using clang::tidy::FileOptionsBaseProvider::ConfigFileHandler = std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions> (llvm::MemoryBufferRef)> >
protected

Definition at line 202 of file ClangTidyOptions.h.

◆ ConfigFileHandlers

Configuration file handlers listed in the order of priority.

Custom configuration file formats can be supported by constructing the list of handlers and passing it to the appropriate FileOptionsProvider constructor. E.g. initialization of a FileOptionsProvider with support of a custom configuration file format for files named ".my-tidy-config" could look similar to this:

ConfigHandlers.emplace_back(".my-tidy-config", parseMyConfigFormat);
ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
return std::make_unique<FileOptionsProvider>(
GlobalOptions, DefaultOptions, OverrideOptions, ConfigHandlers);
std::vector< ConfigFileHandler > ConfigFileHandlers
Configuration file handlers listed in the order of priority.
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(llvm::MemoryBufferRef Config)
Parses configuration from JSON and returns ClangTidyOptions or an error.

With the order of handlers shown above, the ".my-tidy-config" file would take precedence over ".clang-tidy" if both reside in the same directory.

Definition at line 221 of file ClangTidyOptions.h.

Constructor & Destructor Documentation

◆ FileOptionsBaseProvider() [1/2]

clang::tidy::FileOptionsBaseProvider::FileOptionsBaseProvider ( ClangTidyGlobalOptions  GlobalOptions,
ClangTidyOptions  DefaultOptions,
ClangTidyOptions  OverrideOptions,
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem >  FS 
)
protected

Definition at line 312 of file ClangTidyOptions.cpp.

References ConfigHandlers, FS, and clang::tidy::parseConfiguration().

◆ FileOptionsBaseProvider() [2/2]

clang::tidy::FileOptionsBaseProvider::FileOptionsBaseProvider ( ClangTidyGlobalOptions  GlobalOptions,
ClangTidyOptions  DefaultOptions,
ClangTidyOptions  OverrideOptions,
FileOptionsBaseProvider::ConfigFileHandlers  ConfigHandlers 
)
protected

Definition at line 324 of file ClangTidyOptions.cpp.

Member Function Documentation

◆ addRawFileOptions()

void clang::tidy::FileOptionsBaseProvider::addRawFileOptions ( llvm::StringRef  AbsolutePath,
std::vector< OptionsSource > &  CurOptions 
)
protected

◆ tryReadConfigFile()

std::optional< OptionsSource > clang::tidy::FileOptionsBaseProvider::tryReadConfigFile ( llvm::StringRef  Directory)
protected

Try to read configuration files from Directory using registered ConfigHandlers.

Definition at line 413 of file ClangTidyOptions.cpp.

References ConfigFile(), ConfigHandlers, Directory, FS, and Text.

Referenced by addRawFileOptions().

Member Data Documentation

◆ CachedOptions

llvm::StringMap<OptionsSource> clang::tidy::FileOptionsBaseProvider::CachedOptions
protected

Definition at line 240 of file ClangTidyOptions.h.

Referenced by addRawFileOptions().

◆ ConfigHandlers

ConfigFileHandlers clang::tidy::FileOptionsBaseProvider::ConfigHandlers
protected

Definition at line 242 of file ClangTidyOptions.h.

Referenced by FileOptionsBaseProvider(), and tryReadConfigFile().

◆ FS

llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> clang::tidy::FileOptionsBaseProvider::FS
protected

◆ OverrideOptions

ClangTidyOptions clang::tidy::FileOptionsBaseProvider::OverrideOptions
protected

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