typedef std::vector<std::pair<std::string, bool>> CheckersList;
-static CheckersList getCheckersControlList(GlobList &Filter) {
+static CheckersList getCheckersControlList(ClangTidyContext &Context) {
CheckersList List;
const auto &RegisteredCheckers =
bool AnalyzerChecksEnabled = false;
for (StringRef CheckName : RegisteredCheckers) {
std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
- AnalyzerChecksEnabled |= Filter.contains(ClangTidyCheckName);
+ AnalyzerChecksEnabled |= Context.isCheckEnabled(ClangTidyCheckName);
}
if (!AnalyzerChecksEnabled)
for (StringRef CheckName : RegisteredCheckers) {
std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
- if (CheckName.startswith("core") || Filter.contains(ClangTidyCheckName))
+ if (CheckName.startswith("core") ||
+ Context.isCheckEnabled(ClangTidyCheckName)) {
List.emplace_back(CheckName, true);
+ }
}
return List;
}
AnalyzerOptions->Config["cfg-temporary-dtors"] =
Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";
- GlobList &Filter = Context.getChecksFilter();
- AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
+ AnalyzerOptions->CheckersControlList = getCheckersControlList(Context);
if (!AnalyzerOptions->CheckersControlList.empty()) {
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
std::vector<std::string> CheckNames;
- GlobList &Filter = Context.getChecksFilter();
for (const auto &CheckFactory : *CheckFactories) {
- if (Filter.contains(CheckFactory.first))
+ if (Context.isCheckEnabled(CheckFactory.first))
CheckNames.push_back(CheckFactory.first);
}
- for (const auto &AnalyzerCheck : getCheckersControlList(Filter))
+ for (const auto &AnalyzerCheck : getCheckersControlList(Context))
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
std::sort(CheckNames.begin(), CheckNames.end());
void ClangTidyContext::setCheckProfileData(ProfileData *P) { Profile = P; }
-GlobList &ClangTidyContext::getChecksFilter() {
+bool ClangTidyContext::isCheckEnabled(StringRef CheckName) const {
assert(CheckFilter != nullptr);
- return *CheckFilter;
+ return CheckFilter->contains(CheckName);
}
-GlobList &ClangTidyContext::getWarningAsErrorFilter() {
+bool ClangTidyContext::treatAsError(StringRef CheckName) const {
assert(WarningAsErrorFilter != nullptr);
- return *WarningAsErrorFilter;
+ return WarningAsErrorFilter->contains(CheckName);
}
/// \brief Store a \c ClangTidyError.
void ClangTidyDiagnosticConsumer::finalizeLastError() {
if (!Errors.empty()) {
ClangTidyError &Error = Errors.back();
- if (!Context.getChecksFilter().contains(Error.DiagnosticName) &&
+ if (!Context.isCheckEnabled(Error.DiagnosticName) &&
Error.DiagLevel != ClangTidyError::Error) {
++Context.Stats.ErrorsIgnoredCheckFilter;
Errors.pop_back();
LastErrorRelatesToUserCode = true;
LastErrorPassesLineFilter = true;
}
- bool IsWarningAsError =
- DiagLevel == DiagnosticsEngine::Warning &&
- Context.getWarningAsErrorFilter().contains(CheckName);
+ bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
+ Context.treatAsError(CheckName);
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
IsWarningAsError);
}
/// diagnostic ID.
StringRef getCheckName(unsigned DiagnosticID) const;
- /// \brief Returns check filter for the \c CurrentFile.
+ /// \brief Returns \c true if the check is enabled for the \c CurrentFile.
///
/// The \c CurrentFile can be changed using \c setCurrentFile.
- GlobList &getChecksFilter();
+ bool isCheckEnabled(StringRef CheckName) const;
- /// \brief Returns check filter for the \c CurrentFile which
- /// selects checks for upgrade to error.
- GlobList &getWarningAsErrorFilter();
+ /// \brief Returns \c true if the check should be upgraded to error for the
+ /// \c CurrentFile.
+ bool treatAsError(StringRef CheckName) const;
/// \brief Returns global options.
const ClangTidyGlobalOptions &getGlobalOptions() const;
void ClangTidyCheckFactories::createChecks(
ClangTidyContext *Context,
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
- GlobList &Filter = Context->getChecksFilter();
for (const auto &Factory : Factories) {
- if (Filter.contains(Factory.first))
+ if (Context->isCheckEnabled(Factory.first))
Checks.emplace_back(Factory.second(Factory.first, Context));
}
}