2014-05-23 00:07:11 +08:00
|
|
|
//===--- ClangTidyOptions.cpp - clang-tidy ----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-05-23 00:07:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangTidyOptions.h"
|
2014-10-16 19:27:57 +08:00
|
|
|
#include "ClangTidyModuleRegistry.h"
|
2014-09-04 22:23:36 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2015-01-14 19:24:38 +08:00
|
|
|
#include "llvm/Support/Errc.h"
|
2014-09-04 22:23:36 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2014-05-23 00:07:11 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2015-01-14 19:24:38 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-09-04 22:23:36 +08:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "clang-tidy-options"
|
2014-05-23 00:07:11 +08:00
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
using clang::tidy::ClangTidyOptions;
|
2014-05-23 00:07:11 +08:00
|
|
|
using clang::tidy::FileFilter;
|
2016-04-27 17:15:01 +08:00
|
|
|
using OptionsSource = clang::tidy::ClangTidyOptionsProvider::OptionsSource;
|
2014-05-23 00:07:11 +08:00
|
|
|
|
|
|
|
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter)
|
|
|
|
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter::LineRange)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
|
|
|
// Map std::pair<int, int> to a JSON array of size 2.
|
|
|
|
template <> struct SequenceTraits<FileFilter::LineRange> {
|
|
|
|
static size_t size(IO &IO, FileFilter::LineRange &Range) {
|
|
|
|
return Range.first == 0 ? 0 : Range.second == 0 ? 1 : 2;
|
|
|
|
}
|
|
|
|
static unsigned &element(IO &IO, FileFilter::LineRange &Range, size_t Index) {
|
|
|
|
if (Index > 1)
|
|
|
|
IO.setError("Too many elements in line range.");
|
|
|
|
return Index == 0 ? Range.first : Range.second;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MappingTraits<FileFilter> {
|
|
|
|
static void mapping(IO &IO, FileFilter &File) {
|
|
|
|
IO.mapRequired("name", File.Name);
|
|
|
|
IO.mapOptional("lines", File.LineRanges);
|
|
|
|
}
|
|
|
|
static StringRef validate(IO &io, FileFilter &File) {
|
|
|
|
if (File.Name.empty())
|
|
|
|
return "No file name specified";
|
|
|
|
for (const FileFilter::LineRange &Range : File.LineRanges) {
|
|
|
|
if (Range.first <= 0 || Range.second <= 0)
|
|
|
|
return "Invalid line range";
|
|
|
|
}
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-12 16:53:36 +08:00
|
|
|
template <> struct MappingTraits<ClangTidyOptions::StringPair> {
|
|
|
|
static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue) {
|
|
|
|
IO.mapRequired("key", KeyValue.first);
|
|
|
|
IO.mapRequired("value", KeyValue.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NOptionMap {
|
|
|
|
NOptionMap(IO &) {}
|
2020-04-01 17:08:53 +08:00
|
|
|
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
|
|
|
|
Options.reserve(OptionMap.size());
|
|
|
|
for (const auto &KeyValue : OptionMap)
|
|
|
|
Options.emplace_back(KeyValue.first, KeyValue.second.Value);
|
|
|
|
}
|
2014-09-12 16:53:36 +08:00
|
|
|
ClangTidyOptions::OptionMap denormalize(IO &) {
|
|
|
|
ClangTidyOptions::OptionMap Map;
|
|
|
|
for (const auto &KeyValue : Options)
|
2020-04-01 17:08:53 +08:00
|
|
|
Map[KeyValue.first] = ClangTidyOptions::ClangTidyValue(KeyValue.second);
|
2014-09-12 16:53:36 +08:00
|
|
|
return Map;
|
|
|
|
}
|
|
|
|
std::vector<ClangTidyOptions::StringPair> Options;
|
|
|
|
};
|
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
template <> struct MappingTraits<ClangTidyOptions> {
|
|
|
|
static void mapping(IO &IO, ClangTidyOptions &Options) {
|
2014-09-12 16:53:36 +08:00
|
|
|
MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts(
|
|
|
|
IO, Options.CheckOptions);
|
2018-05-09 07:15:58 +08:00
|
|
|
bool Ignored = false;
|
2014-06-05 21:31:45 +08:00
|
|
|
IO.mapOptional("Checks", Options.Checks);
|
2016-01-14 01:36:41 +08:00
|
|
|
IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
|
2014-06-05 21:31:45 +08:00
|
|
|
IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
|
2018-05-09 07:15:58 +08:00
|
|
|
IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // legacy compatibility
|
2017-04-06 21:41:29 +08:00
|
|
|
IO.mapOptional("FormatStyle", Options.FormatStyle);
|
2014-09-25 02:36:03 +08:00
|
|
|
IO.mapOptional("User", Options.User);
|
2014-09-12 16:53:36 +08:00
|
|
|
IO.mapOptional("CheckOptions", NOpts->Options);
|
2015-11-10 00:28:11 +08:00
|
|
|
IO.mapOptional("ExtraArgs", Options.ExtraArgs);
|
|
|
|
IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
|
2020-04-01 17:08:53 +08:00
|
|
|
IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
|
2014-06-05 21:31:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-23 00:07:11 +08:00
|
|
|
} // namespace yaml
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
|
2014-10-16 19:27:57 +08:00
|
|
|
ClangTidyOptions ClangTidyOptions::getDefaults() {
|
|
|
|
ClangTidyOptions Options;
|
|
|
|
Options.Checks = "";
|
2016-01-14 01:36:41 +08:00
|
|
|
Options.WarningsAsErrors = "";
|
2014-10-16 19:27:57 +08:00
|
|
|
Options.HeaderFilterRegex = "";
|
2014-10-29 06:16:13 +08:00
|
|
|
Options.SystemHeaders = false;
|
2017-04-06 21:41:29 +08:00
|
|
|
Options.FormatStyle = "none";
|
2014-10-16 19:27:57 +08:00
|
|
|
Options.User = llvm::None;
|
2020-04-01 17:08:53 +08:00
|
|
|
unsigned Priority = 0;
|
2014-10-16 19:27:57 +08:00
|
|
|
for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
|
|
|
|
E = ClangTidyModuleRegistry::end();
|
|
|
|
I != E; ++I)
|
2020-04-01 17:08:53 +08:00
|
|
|
Options =
|
|
|
|
Options.mergeWith(I->instantiate()->getModuleOptions(), ++Priority);
|
2014-10-16 19:27:57 +08:00
|
|
|
return Options;
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:48:29 +08:00
|
|
|
template <typename T>
|
|
|
|
static void mergeVectors(Optional<T> &Dest, const Optional<T> &Src) {
|
|
|
|
if (Src) {
|
|
|
|
if (Dest)
|
|
|
|
Dest->insert(Dest->end(), Src->begin(), Src->end());
|
|
|
|
else
|
|
|
|
Dest = Src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mergeCommaSeparatedLists(Optional<std::string> &Dest,
|
|
|
|
const Optional<std::string> &Src) {
|
|
|
|
if (Src)
|
|
|
|
Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void overrideValue(Optional<T> &Dest, const Optional<T> &Src) {
|
|
|
|
if (Src)
|
|
|
|
Dest = Src;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:08:53 +08:00
|
|
|
ClangTidyOptions ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
|
|
|
|
unsigned Priority) const {
|
2014-09-04 22:23:36 +08:00
|
|
|
ClangTidyOptions Result = *this;
|
|
|
|
|
2016-08-23 22:48:29 +08:00
|
|
|
mergeCommaSeparatedLists(Result.Checks, Other.Checks);
|
|
|
|
mergeCommaSeparatedLists(Result.WarningsAsErrors, Other.WarningsAsErrors);
|
|
|
|
overrideValue(Result.HeaderFilterRegex, Other.HeaderFilterRegex);
|
|
|
|
overrideValue(Result.SystemHeaders, Other.SystemHeaders);
|
2017-04-06 21:41:29 +08:00
|
|
|
overrideValue(Result.FormatStyle, Other.FormatStyle);
|
2016-08-23 22:48:29 +08:00
|
|
|
overrideValue(Result.User, Other.User);
|
|
|
|
mergeVectors(Result.ExtraArgs, Other.ExtraArgs);
|
|
|
|
mergeVectors(Result.ExtraArgsBefore, Other.ExtraArgsBefore);
|
2014-09-12 16:53:36 +08:00
|
|
|
|
2020-04-01 17:08:53 +08:00
|
|
|
for (const auto &KeyValue : Other.CheckOptions) {
|
|
|
|
Result.CheckOptions[KeyValue.first] = ClangTidyValue(
|
|
|
|
KeyValue.second.Value, KeyValue.second.Priority + Priority);
|
|
|
|
}
|
2014-09-12 16:53:36 +08:00
|
|
|
|
2014-09-04 22:23:36 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2016-04-27 17:15:01 +08:00
|
|
|
const char ClangTidyOptionsProvider::OptionsSourceTypeDefaultBinary[] =
|
|
|
|
"clang-tidy binary";
|
|
|
|
const char ClangTidyOptionsProvider::OptionsSourceTypeCheckCommandLineOption[] =
|
|
|
|
"command-line option '-checks'";
|
|
|
|
const char
|
|
|
|
ClangTidyOptionsProvider::OptionsSourceTypeConfigCommandLineOption[] =
|
|
|
|
"command-line option '-config'";
|
|
|
|
|
|
|
|
ClangTidyOptions
|
|
|
|
ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
|
|
|
|
ClangTidyOptions Result;
|
2020-04-01 17:08:53 +08:00
|
|
|
unsigned Priority = 0;
|
2016-04-27 17:15:01 +08:00
|
|
|
for (const auto &Source : getRawOptions(FileName))
|
2020-04-01 17:08:53 +08:00
|
|
|
Result = Result.mergeWith(Source.first, ++Priority);
|
2016-04-27 17:15:01 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<OptionsSource>
|
|
|
|
DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
|
|
|
std::vector<OptionsSource> Result;
|
|
|
|
Result.emplace_back(DefaultOptions, OptionsSourceTypeDefaultBinary);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigOptionsProvider::ConfigOptionsProvider(
|
|
|
|
const ClangTidyGlobalOptions &GlobalOptions,
|
|
|
|
const ClangTidyOptions &DefaultOptions,
|
|
|
|
const ClangTidyOptions &ConfigOptions,
|
|
|
|
const ClangTidyOptions &OverrideOptions)
|
|
|
|
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
|
|
|
|
ConfigOptions(ConfigOptions), OverrideOptions(OverrideOptions) {}
|
|
|
|
|
|
|
|
std::vector<OptionsSource>
|
|
|
|
ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
|
|
|
|
std::vector<OptionsSource> RawOptions =
|
|
|
|
DefaultOptionsProvider::getRawOptions(FileName);
|
|
|
|
RawOptions.emplace_back(ConfigOptions,
|
|
|
|
OptionsSourceTypeConfigCommandLineOption);
|
|
|
|
RawOptions.emplace_back(OverrideOptions,
|
|
|
|
OptionsSourceTypeCheckCommandLineOption);
|
|
|
|
return RawOptions;
|
|
|
|
}
|
|
|
|
|
2014-09-04 22:23:36 +08:00
|
|
|
FileOptionsProvider::FileOptionsProvider(
|
|
|
|
const ClangTidyGlobalOptions &GlobalOptions,
|
2014-09-25 02:36:03 +08:00
|
|
|
const ClangTidyOptions &DefaultOptions,
|
2018-04-18 16:54:28 +08:00
|
|
|
const ClangTidyOptions &OverrideOptions,
|
2018-10-10 21:27:25 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
2014-09-25 02:36:03 +08:00
|
|
|
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
|
2018-04-18 16:54:28 +08:00
|
|
|
OverrideOptions(OverrideOptions), FS(std::move(VFS)) {
|
|
|
|
if (!FS)
|
2018-10-10 21:27:25 +08:00
|
|
|
FS = llvm::vfs::getRealFileSystem();
|
2014-10-20 20:29:15 +08:00
|
|
|
ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
|
2014-09-04 22:23:36 +08:00
|
|
|
}
|
|
|
|
|
2014-10-20 20:29:15 +08:00
|
|
|
FileOptionsProvider::FileOptionsProvider(
|
|
|
|
const ClangTidyGlobalOptions &GlobalOptions,
|
|
|
|
const ClangTidyOptions &DefaultOptions,
|
|
|
|
const ClangTidyOptions &OverrideOptions,
|
|
|
|
const FileOptionsProvider::ConfigFileHandlers &ConfigHandlers)
|
|
|
|
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
|
2016-11-08 15:50:19 +08:00
|
|
|
OverrideOptions(OverrideOptions), ConfigHandlers(ConfigHandlers) {}
|
2014-09-04 22:23:36 +08:00
|
|
|
|
|
|
|
// FIXME: This method has some common logic with clang::format::getStyle().
|
|
|
|
// Consider pulling out common bits to a findParentFileWithName function or
|
|
|
|
// similar.
|
2016-04-27 17:15:01 +08:00
|
|
|
std::vector<OptionsSource>
|
|
|
|
FileOptionsProvider::getRawOptions(StringRef FileName) {
|
2018-05-16 00:37:45 +08:00
|
|
|
LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
|
|
|
|
<< "...\n");
|
2018-04-18 16:54:28 +08:00
|
|
|
assert(FS && "FS must be set.");
|
|
|
|
|
|
|
|
llvm::SmallString<128> AbsoluteFilePath(FileName);
|
2018-04-19 21:34:03 +08:00
|
|
|
|
|
|
|
if (FS->makeAbsolute(AbsoluteFilePath))
|
2018-04-18 16:54:28 +08:00
|
|
|
return {};
|
2014-09-04 22:23:36 +08:00
|
|
|
|
2016-04-27 17:15:01 +08:00
|
|
|
std::vector<OptionsSource> RawOptions =
|
2018-04-18 16:54:28 +08:00
|
|
|
DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
|
2016-04-27 17:15:01 +08:00
|
|
|
OptionsSource CommandLineOptions(OverrideOptions,
|
|
|
|
OptionsSourceTypeCheckCommandLineOption);
|
2020-04-01 17:08:53 +08:00
|
|
|
size_t FirstFileConfig = RawOptions.size();
|
2014-09-04 22:23:36 +08:00
|
|
|
// Look for a suitable configuration file in all parent directories of the
|
|
|
|
// file. Start with the immediate parent directory and move up.
|
2018-04-18 16:54:28 +08:00
|
|
|
StringRef Path = llvm::sys::path::parent_path(AbsoluteFilePath.str());
|
2016-04-27 17:15:01 +08:00
|
|
|
for (StringRef CurrentPath = Path; !CurrentPath.empty();
|
2014-09-04 22:23:36 +08:00
|
|
|
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
|
2016-04-27 17:15:01 +08:00
|
|
|
llvm::Optional<OptionsSource> Result;
|
2014-09-04 22:23:36 +08:00
|
|
|
|
|
|
|
auto Iter = CachedOptions.find(CurrentPath);
|
|
|
|
if (Iter != CachedOptions.end())
|
|
|
|
Result = Iter->second;
|
|
|
|
|
|
|
|
if (!Result)
|
2016-04-27 17:15:01 +08:00
|
|
|
Result = tryReadConfigFile(CurrentPath);
|
2014-09-04 22:23:36 +08:00
|
|
|
|
|
|
|
if (Result) {
|
|
|
|
// Store cached value for all intermediate directories.
|
|
|
|
while (Path != CurrentPath) {
|
2018-05-16 00:37:45 +08:00
|
|
|
LLVM_DEBUG(llvm::dbgs()
|
|
|
|
<< "Caching configuration for path " << Path << ".\n");
|
2020-04-01 17:08:53 +08:00
|
|
|
if (!CachedOptions.count(Path))
|
|
|
|
CachedOptions[Path] = *Result;
|
2014-09-04 22:23:36 +08:00
|
|
|
Path = llvm::sys::path::parent_path(Path);
|
|
|
|
}
|
2016-04-27 17:15:01 +08:00
|
|
|
CachedOptions[Path] = *Result;
|
|
|
|
|
|
|
|
RawOptions.push_back(*Result);
|
2020-04-01 17:08:53 +08:00
|
|
|
if (!Result->first.InheritParentConfig ||
|
|
|
|
!*Result->first.InheritParentConfig)
|
|
|
|
break;
|
2014-09-04 22:23:36 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-01 17:08:53 +08:00
|
|
|
// Reverse order of file configs because closer configs should have higher
|
|
|
|
// priority.
|
|
|
|
std::reverse(RawOptions.begin() + FirstFileConfig, RawOptions.end());
|
2016-04-27 17:15:01 +08:00
|
|
|
RawOptions.push_back(CommandLineOptions);
|
|
|
|
return RawOptions;
|
2014-09-04 22:23:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-27 17:15:01 +08:00
|
|
|
llvm::Optional<OptionsSource>
|
|
|
|
FileOptionsProvider::tryReadConfigFile(StringRef Directory) {
|
2014-09-04 22:23:36 +08:00
|
|
|
assert(!Directory.empty());
|
|
|
|
|
2014-10-20 20:29:15 +08:00
|
|
|
if (!llvm::sys::fs::is_directory(Directory)) {
|
|
|
|
llvm::errs() << "Error reading configuration from " << Directory
|
|
|
|
<< ": directory doesn't exist.\n";
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const ConfigFileHandler &ConfigHandler : ConfigHandlers) {
|
|
|
|
SmallString<128> ConfigFile(Directory);
|
|
|
|
llvm::sys::path::append(ConfigFile, ConfigHandler.first);
|
2018-05-16 00:37:45 +08:00
|
|
|
LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
|
2014-10-20 20:29:15 +08:00
|
|
|
|
|
|
|
bool IsFile = false;
|
|
|
|
// Ignore errors from is_regular_file: we only need to know if we can read
|
|
|
|
// the file or not.
|
|
|
|
llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
|
|
|
|
if (!IsFile)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
|
|
|
|
llvm::MemoryBuffer::getFile(ConfigFile.c_str());
|
|
|
|
if (std::error_code EC = Text.getError()) {
|
|
|
|
llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
|
|
|
|
<< "\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip empty files, e.g. files opened for writing via shell output
|
|
|
|
// redirection.
|
|
|
|
if ((*Text)->getBuffer().empty())
|
|
|
|
continue;
|
|
|
|
llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
|
|
|
|
ConfigHandler.second((*Text)->getBuffer());
|
|
|
|
if (!ParsedOptions) {
|
2014-11-04 23:25:22 +08:00
|
|
|
if (ParsedOptions.getError())
|
|
|
|
llvm::errs() << "Error parsing " << ConfigFile << ": "
|
|
|
|
<< ParsedOptions.getError().message() << "\n";
|
2014-10-20 20:29:15 +08:00
|
|
|
continue;
|
|
|
|
}
|
2016-04-27 17:15:01 +08:00
|
|
|
return OptionsSource(*ParsedOptions, ConfigFile.c_str());
|
2014-09-25 02:36:03 +08:00
|
|
|
}
|
2014-10-20 20:29:15 +08:00
|
|
|
return llvm::None;
|
2014-09-04 22:23:36 +08:00
|
|
|
}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Parses -line-filter option and stores it to the \c Options.
|
2014-09-04 22:23:36 +08:00
|
|
|
std::error_code parseLineFilter(StringRef LineFilter,
|
2014-06-12 21:32:11 +08:00
|
|
|
clang::tidy::ClangTidyGlobalOptions &Options) {
|
2014-05-23 00:07:11 +08:00
|
|
|
llvm::yaml::Input Input(LineFilter);
|
|
|
|
Input >> Options.LineFilter;
|
|
|
|
return Input.error();
|
|
|
|
}
|
|
|
|
|
2014-09-25 02:36:03 +08:00
|
|
|
llvm::ErrorOr<ClangTidyOptions> parseConfiguration(StringRef Config) {
|
2014-06-05 21:31:45 +08:00
|
|
|
llvm::yaml::Input Input(Config);
|
2014-09-25 02:36:03 +08:00
|
|
|
ClangTidyOptions Options;
|
2014-06-05 21:31:45 +08:00
|
|
|
Input >> Options;
|
2014-09-25 02:36:03 +08:00
|
|
|
if (Input.error())
|
|
|
|
return Input.error();
|
|
|
|
return Options;
|
2014-06-05 21:31:45 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 22:23:36 +08:00
|
|
|
std::string configurationAsText(const ClangTidyOptions &Options) {
|
|
|
|
std::string Text;
|
|
|
|
llvm::raw_string_ostream Stream(Text);
|
|
|
|
llvm::yaml::Output Output(Stream);
|
|
|
|
// We use the same mapping method for input and output, so we need a non-const
|
|
|
|
// reference here.
|
|
|
|
ClangTidyOptions NonConstValue = Options;
|
|
|
|
Output << NonConstValue;
|
|
|
|
return Stream.str();
|
|
|
|
}
|
|
|
|
|
2014-05-23 00:07:11 +08:00
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|