Options.User = llvm::None;
for (const ClangTidyModuleRegistry::entry &Module :
ClangTidyModuleRegistry::entries())
- Options = Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
+ Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
return Options;
}
Dest = Src;
}
-ClangTidyOptions ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
- unsigned Priority) const {
- ClangTidyOptions Result = *this;
-
- mergeCommaSeparatedLists(Result.Checks, Other.Checks);
- mergeCommaSeparatedLists(Result.WarningsAsErrors, Other.WarningsAsErrors);
- overrideValue(Result.HeaderFilterRegex, Other.HeaderFilterRegex);
- overrideValue(Result.SystemHeaders, Other.SystemHeaders);
- overrideValue(Result.FormatStyle, Other.FormatStyle);
- overrideValue(Result.User, Other.User);
- overrideValue(Result.UseColor, Other.UseColor);
- mergeVectors(Result.ExtraArgs, Other.ExtraArgs);
- mergeVectors(Result.ExtraArgsBefore, Other.ExtraArgsBefore);
+ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
+ unsigned Order) {
+ mergeCommaSeparatedLists(Checks, Other.Checks);
+ mergeCommaSeparatedLists(WarningsAsErrors, Other.WarningsAsErrors);
+ overrideValue(HeaderFilterRegex, Other.HeaderFilterRegex);
+ overrideValue(SystemHeaders, Other.SystemHeaders);
+ overrideValue(FormatStyle, Other.FormatStyle);
+ overrideValue(User, Other.User);
+ overrideValue(UseColor, Other.UseColor);
+ mergeVectors(ExtraArgs, Other.ExtraArgs);
+ mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
for (const auto &KeyValue : Other.CheckOptions) {
- Result.CheckOptions.insert_or_assign(
+ CheckOptions.insert_or_assign(
KeyValue.getKey(),
ClangTidyValue(KeyValue.getValue().Value,
- KeyValue.getValue().Priority + Priority));
+ KeyValue.getValue().Priority + Order));
}
+ return *this;
+}
+ClangTidyOptions ClangTidyOptions::merge(const ClangTidyOptions &Other,
+ unsigned Order) const {
+ ClangTidyOptions Result = *this;
+ Result.mergeWith(Other, Order);
return Result;
}
ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
ClangTidyOptions Result;
unsigned Priority = 0;
- for (const auto &Source : getRawOptions(FileName))
- Result = Result.mergeWith(Source.first, ++Priority);
+ for (auto &Source : getRawOptions(FileName))
+ Result.mergeWith(Source.first, ++Priority);
return Result;
}
/// of each registered \c ClangTidyModule.
static ClangTidyOptions getDefaults();
+ /// Overwrites all fields in here by the fields of \p Other that have a value.
+ /// \p Order specifies precedence of \p Other option.
+ ClangTidyOptions &mergeWith(const ClangTidyOptions &Other, unsigned Order);
+
/// Creates a new \c ClangTidyOptions instance combined from all fields
/// of this instance overridden by the fields of \p Other that have a value.
/// \p Order specifies precedence of \p Other option.
- ClangTidyOptions mergeWith(const ClangTidyOptions &Other,
- unsigned Order) const;
+ LLVM_NODISCARD ClangTidyOptions merge(const ClangTidyOptions &Other,
+ unsigned Order) const;
/// Checks filter.
llvm::Optional<std::string> Checks;
if (ParsedConfig)
return std::make_unique<ConfigOptionsProvider>(
GlobalOptions,
- ClangTidyOptions::getDefaults().mergeWith(DefaultOptions, 0),
+ ClangTidyOptions::getDefaults().merge(DefaultOptions, 0),
*ParsedConfig, OverrideOptions, std::move(FS));
llvm::errs() << "Error: invalid configuration specified.\n"
<< ParsedConfig.getError().message() << "\n";
if (DumpConfig) {
EffectiveOptions.CheckOptions =
getCheckOptions(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
- llvm::outs() << configurationAsText(
- ClangTidyOptions::getDefaults().mergeWith(
- EffectiveOptions, 0))
+ llvm::outs() << configurationAsText(ClangTidyOptions::getDefaults().merge(
+ EffectiveOptions, 0))
<< "\n";
return 0;
}