clang-tools  8.0.0svn
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::tidy::FileOptionsProvider Class Reference

Implementation of the ClangTidyOptionsProvider interface, which tries to find a configuration file in the closest parent directory of each source file. More...

#include <ClangTidyOptions.h>

Inheritance diagram for clang::tidy::FileOptionsProvider:
Inheritance graph
[legend]
Collaboration diagram for clang::tidy::FileOptionsProvider:
Collaboration graph
[legend]

Public Types

typedef std::pair< std::string, std::function< llvm::ErrorOr< ClangTidyOptions > llvm::StringRef)> > ConfigFileHandler
 
typedef std::vector< ConfigFileHandlerConfigFileHandlers
 Configuration file handlers listed in the order of priority. More...
 
- Public Types inherited from clang::tidy::ClangTidyOptionsProvider
typedef std::pair< ClangTidyOptions, std::string > OptionsSource
 ClangTidyOptions and its source. More...
 

Public Member Functions

 FileOptionsProvider (const ClangTidyGlobalOptions &GlobalOptions, const ClangTidyOptions &DefaultOptions, const ClangTidyOptions &OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
 Initializes the FileOptionsProvider instance. More...
 
 FileOptionsProvider (const ClangTidyGlobalOptions &GlobalOptions, const ClangTidyOptions &DefaultOptions, const ClangTidyOptions &OverrideOptions, const ConfigFileHandlers &ConfigHandlers)
 Initializes the FileOptionsProvider instance with a custom set of configuration file handlers. More...
 
std::vector< OptionsSourcegetRawOptions (llvm::StringRef FileName) override
 Returns an ordered vector of OptionsSources, in order of increasing priority. More...
 
- Public Member Functions inherited from clang::tidy::DefaultOptionsProvider
 DefaultOptionsProvider (const ClangTidyGlobalOptions &GlobalOptions, const ClangTidyOptions &Options)
 
const ClangTidyGlobalOptionsgetGlobalOptions () override
 Returns global options, which are independent of the file. More...
 
- Public Member Functions inherited from clang::tidy::ClangTidyOptionsProvider
virtual ~ClangTidyOptionsProvider ()
 
ClangTidyOptions getOptions (llvm::StringRef FileName)
 Returns options applying to a specific translation unit with the specified FileName. More...
 

Protected Member Functions

llvm::Optional< OptionsSourcetryReadConfigFile (llvm::StringRef Directory)
 Try to read configuration files from Directory using registered ConfigHandlers. More...
 

Protected Attributes

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

Additional Inherited Members

- Static Public Attributes inherited from clang::tidy::ClangTidyOptionsProvider
static const char OptionsSourceTypeDefaultBinary []
 
static const char OptionsSourceTypeCheckCommandLineOption []
 
static const char OptionsSourceTypeConfigCommandLineOption []
 

Detailed Description

Implementation of the ClangTidyOptionsProvider interface, which tries to find a configuration file in the closest parent directory of each source file.

By default, files named ".clang-tidy" will be considered, and the clang::tidy::parseConfiguration function will be used for parsing, but a custom set of configuration file names and parsing functions can be specified using the appropriate constructor.

Definition at line 184 of file ClangTidyOptions.h.

Member Typedef Documentation

◆ ConfigFileHandler

typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions> llvm::StringRef)> > clang::tidy::FileOptionsProvider::ConfigFileHandler

Definition at line 190 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 llvm::make_unique<FileOptionsProvider>(
GlobalOptions, DefaultOptions, OverrideOptions, ConfigHandlers);

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 209 of file ClangTidyOptions.h.

Constructor & Destructor Documentation

◆ FileOptionsProvider() [1/2]

clang::tidy::FileOptionsProvider::FileOptionsProvider ( const ClangTidyGlobalOptions GlobalOptions,
const ClangTidyOptions DefaultOptions,
const ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem >  FS = nullptr 
)

Initializes the FileOptionsProvider instance.

Parameters
GlobalOptionsare just stored and returned to the caller of getGlobalOptions.
DefaultOptionsare used for all settings not specified in a configuration file.

If any of the

Parameters
OverrideOptionsfields are set, they will override whatever options are read from the configuration file.

Definition at line 203 of file ClangTidyOptions.cpp.

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

◆ FileOptionsProvider() [2/2]

clang::tidy::FileOptionsProvider::FileOptionsProvider ( const ClangTidyGlobalOptions GlobalOptions,
const ClangTidyOptions DefaultOptions,
const ClangTidyOptions OverrideOptions,
const ConfigFileHandlers ConfigHandlers 
)

Initializes the FileOptionsProvider instance with a custom set of configuration file handlers.

Parameters
GlobalOptionsare just stored and returned to the caller of getGlobalOptions.
DefaultOptionsare used for all settings not specified in a configuration file.

If any of the

Parameters
OverrideOptionsfields are set, they will override whatever options are read from the configuration file.
ConfigHandlersspecifies a custom set of configuration file handlers. Each handler is a pair of configuration file name and a function that can parse configuration from this file type. The configuration files in each directory are searched for in the order of appearance in ConfigHandlers.

Definition at line 215 of file ClangTidyOptions.cpp.

Member Function Documentation

◆ getRawOptions()

std::vector< OptionsSource > clang::tidy::FileOptionsProvider::getRawOptions ( llvm::StringRef  FileName)
overridevirtual

Returns an ordered vector of OptionsSources, in order of increasing priority.

Reimplemented from clang::tidy::DefaultOptionsProvider.

Definition at line 227 of file ClangTidyOptions.cpp.

References FS, clang::tidy::DefaultOptionsProvider::getRawOptions(), clang::tidy::ClangTidyOptionsProvider::OptionsSourceTypeCheckCommandLineOption, OverrideOptions, and Path.

◆ tryReadConfigFile()

llvm::Optional< OptionsSource > clang::tidy::FileOptionsProvider::tryReadConfigFile ( llvm::StringRef  Directory)
protected

Try to read configuration files from Directory using registered ConfigHandlers.

Definition at line 274 of file ClangTidyOptions.cpp.

References ConfigHandlers.

Member Data Documentation

◆ CachedOptions

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

Definition at line 256 of file ClangTidyOptions.h.

◆ ConfigHandlers

ConfigFileHandlers clang::tidy::FileOptionsProvider::ConfigHandlers
protected

Definition at line 258 of file ClangTidyOptions.h.

Referenced by FileOptionsProvider(), and tryReadConfigFile().

◆ FS

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

Definition at line 259 of file ClangTidyOptions.h.

Referenced by FileOptionsProvider(), and getRawOptions().

◆ OverrideOptions

ClangTidyOptions clang::tidy::FileOptionsProvider::OverrideOptions
protected

Definition at line 257 of file ClangTidyOptions.h.

Referenced by getRawOptions().


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