forked from OSchip/llvm-project
[clang-tidy][NFC] Use moves instead of copies when constructing OptionsProviders.
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D92267
This commit is contained in:
parent
958608285e
commit
bedf3a0f50
|
@ -195,14 +195,13 @@ DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigOptionsProvider::ConfigOptionsProvider(
|
ConfigOptionsProvider::ConfigOptionsProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &ConfigOptions,
|
|
||||||
const ClangTidyOptions &OverrideOptions,
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
|
||||||
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
|
: FileOptionsBaseProvider(std::move(GlobalOptions),
|
||||||
FS),
|
std::move(DefaultOptions),
|
||||||
ConfigOptions(ConfigOptions) {}
|
std::move(OverrideOptions), std::move(FS)),
|
||||||
|
ConfigOptions(std::move(ConfigOptions)) {}
|
||||||
|
|
||||||
std::vector<OptionsSource>
|
std::vector<OptionsSource>
|
||||||
ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
||||||
|
@ -227,24 +226,25 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOptionsBaseProvider::FileOptionsBaseProvider(
|
FileOptionsBaseProvider::FileOptionsBaseProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
||||||
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
|
: DefaultOptionsProvider(std::move(GlobalOptions),
|
||||||
OverrideOptions(OverrideOptions), FS(std::move(VFS)) {
|
std::move(DefaultOptions)),
|
||||||
|
OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
|
||||||
if (!FS)
|
if (!FS)
|
||||||
FS = llvm::vfs::getRealFileSystem();
|
FS = llvm::vfs::getRealFileSystem();
|
||||||
ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
|
ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOptionsBaseProvider::FileOptionsBaseProvider(
|
FileOptionsBaseProvider::FileOptionsBaseProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
FileOptionsBaseProvider::ConfigFileHandlers ConfigHandlers)
|
||||||
const FileOptionsBaseProvider::ConfigFileHandlers &ConfigHandlers)
|
: DefaultOptionsProvider(std::move(GlobalOptions),
|
||||||
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
|
std::move(DefaultOptions)),
|
||||||
OverrideOptions(OverrideOptions), ConfigHandlers(ConfigHandlers) {}
|
OverrideOptions(std::move(OverrideOptions)),
|
||||||
|
ConfigHandlers(std::move(ConfigHandlers)) {}
|
||||||
|
|
||||||
void FileOptionsBaseProvider::addRawFileOptions(
|
void FileOptionsBaseProvider::addRawFileOptions(
|
||||||
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
|
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
|
||||||
|
@ -286,20 +286,20 @@ void FileOptionsBaseProvider::addRawFileOptions(
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOptionsProvider::FileOptionsProvider(
|
FileOptionsProvider::FileOptionsProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
||||||
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
|
: FileOptionsBaseProvider(std::move(GlobalOptions),
|
||||||
VFS){}
|
std::move(DefaultOptions),
|
||||||
|
std::move(OverrideOptions), std::move(VFS)) {}
|
||||||
|
|
||||||
FileOptionsProvider::FileOptionsProvider(
|
FileOptionsProvider::FileOptionsProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
FileOptionsBaseProvider::ConfigFileHandlers ConfigHandlers)
|
||||||
const FileOptionsBaseProvider::ConfigFileHandlers &ConfigHandlers)
|
: FileOptionsBaseProvider(
|
||||||
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
|
std::move(GlobalOptions), std::move(DefaultOptions),
|
||||||
ConfigHandlers) {}
|
std::move(OverrideOptions), std::move(ConfigHandlers)) {}
|
||||||
|
|
||||||
// FIXME: This method has some common logic with clang::format::getStyle().
|
// FIXME: This method has some common logic with clang::format::getStyle().
|
||||||
// Consider pulling out common bits to a findParentFileWithName function or
|
// Consider pulling out common bits to a findParentFileWithName function or
|
||||||
|
|
|
@ -173,9 +173,10 @@ public:
|
||||||
/// returns the same options for all files.
|
/// returns the same options for all files.
|
||||||
class DefaultOptionsProvider : public ClangTidyOptionsProvider {
|
class DefaultOptionsProvider : public ClangTidyOptionsProvider {
|
||||||
public:
|
public:
|
||||||
DefaultOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
|
DefaultOptionsProvider(ClangTidyGlobalOptions GlobalOptions,
|
||||||
const ClangTidyOptions &Options)
|
ClangTidyOptions Options)
|
||||||
: GlobalOptions(GlobalOptions), DefaultOptions(Options) {}
|
: GlobalOptions(std::move(GlobalOptions)),
|
||||||
|
DefaultOptions(std::move(Options)) {}
|
||||||
const ClangTidyGlobalOptions &getGlobalOptions() override {
|
const ClangTidyGlobalOptions &getGlobalOptions() override {
|
||||||
return GlobalOptions;
|
return GlobalOptions;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +188,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileOptionsBaseProvider : public DefaultOptionsProvider {
|
class FileOptionsBaseProvider : public DefaultOptionsProvider {
|
||||||
public:
|
protected:
|
||||||
// A pair of configuration file base name and a function parsing
|
// A pair of configuration file base name and a function parsing
|
||||||
// configuration from text in the corresponding format.
|
// configuration from text in the corresponding format.
|
||||||
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
|
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
|
||||||
|
@ -213,16 +214,15 @@ public:
|
||||||
/// take precedence over ".clang-tidy" if both reside in the same directory.
|
/// take precedence over ".clang-tidy" if both reside in the same directory.
|
||||||
typedef std::vector<ConfigFileHandler> ConfigFileHandlers;
|
typedef std::vector<ConfigFileHandler> ConfigFileHandlers;
|
||||||
|
|
||||||
FileOptionsBaseProvider(
|
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
|
|
||||||
|
|
||||||
FileOptionsBaseProvider(const ClangTidyGlobalOptions &GlobalOptions,
|
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ConfigFileHandlers &ConfigHandlers);
|
ConfigFileHandlers ConfigHandlers);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addRawFileOptions(llvm::StringRef AbsolutePath,
|
void addRawFileOptions(llvm::StringRef AbsolutePath,
|
||||||
|
@ -243,10 +243,8 @@ protected:
|
||||||
class ConfigOptionsProvider : public FileOptionsBaseProvider {
|
class ConfigOptionsProvider : public FileOptionsBaseProvider {
|
||||||
public:
|
public:
|
||||||
ConfigOptionsProvider(
|
ConfigOptionsProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &ConfigOptions,
|
|
||||||
const ClangTidyOptions &OverrideOptions,
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
|
||||||
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
|
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
|
||||||
|
|
||||||
|
@ -275,9 +273,8 @@ public:
|
||||||
/// If any of the \param OverrideOptions fields are set, they will override
|
/// If any of the \param OverrideOptions fields are set, they will override
|
||||||
/// whatever options are read from the configuration file.
|
/// whatever options are read from the configuration file.
|
||||||
FileOptionsProvider(
|
FileOptionsProvider(
|
||||||
const ClangTidyGlobalOptions &GlobalOptions,
|
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
|
||||||
|
|
||||||
/// Initializes the \c FileOptionsProvider instance with a custom set
|
/// Initializes the \c FileOptionsProvider instance with a custom set
|
||||||
|
@ -297,10 +294,10 @@ public:
|
||||||
/// that can parse configuration from this file type. The configuration files
|
/// that can parse configuration from this file type. The configuration files
|
||||||
/// in each directory are searched for in the order of appearance in
|
/// in each directory are searched for in the order of appearance in
|
||||||
/// \p ConfigHandlers.
|
/// \p ConfigHandlers.
|
||||||
FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
|
FileOptionsProvider(ClangTidyGlobalOptions GlobalOptions,
|
||||||
const ClangTidyOptions &DefaultOptions,
|
ClangTidyOptions DefaultOptions,
|
||||||
const ClangTidyOptions &OverrideOptions,
|
ClangTidyOptions OverrideOptions,
|
||||||
const ConfigFileHandlers &ConfigHandlers);
|
ConfigFileHandlers ConfigHandlers);
|
||||||
|
|
||||||
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
|
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -318,9 +318,9 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
|
||||||
parseConfiguration(Configuration);
|
parseConfiguration(Configuration);
|
||||||
if (ParsedConfig)
|
if (ParsedConfig)
|
||||||
return std::make_unique<ConfigOptionsProvider>(
|
return std::make_unique<ConfigOptionsProvider>(
|
||||||
GlobalOptions,
|
std::move(GlobalOptions),
|
||||||
ClangTidyOptions::getDefaults().merge(DefaultOptions, 0),
|
ClangTidyOptions::getDefaults().merge(DefaultOptions, 0),
|
||||||
*ParsedConfig, OverrideOptions, std::move(FS));
|
std::move(*ParsedConfig), std::move(OverrideOptions), std::move(FS));
|
||||||
llvm::errs() << "Error: invalid configuration specified.\n"
|
llvm::errs() << "Error: invalid configuration specified.\n"
|
||||||
<< ParsedConfig.getError().message() << "\n";
|
<< ParsedConfig.getError().message() << "\n";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -347,8 +347,9 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
|
||||||
if (Config.getNumOccurrences() > 0)
|
if (Config.getNumOccurrences() > 0)
|
||||||
return LoadConfig(Config);
|
return LoadConfig(Config);
|
||||||
|
|
||||||
return std::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
|
return std::make_unique<FileOptionsProvider>(
|
||||||
OverrideOptions, std::move(FS));
|
std::move(GlobalOptions), std::move(DefaultOptions),
|
||||||
|
std::move(OverrideOptions), std::move(FS));
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::IntrusiveRefCntPtr<vfs::FileSystem>
|
llvm::IntrusiveRefCntPtr<vfs::FileSystem>
|
||||||
|
|
Loading…
Reference in New Issue