diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy')
4 files changed, 21 insertions, 23 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 511cbb8a2b1..c3ddc458b89 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -302,7 +302,7 @@ static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts, typedef std::vector<std::pair<std::string, bool>> CheckersList; -static CheckersList getCheckersControlList(GlobList &Filter) { +static CheckersList getCheckersControlList(ClangTidyContext &Context) { CheckersList List; const auto &RegisteredCheckers = @@ -310,7 +310,7 @@ static CheckersList getCheckersControlList(GlobList &Filter) { bool AnalyzerChecksEnabled = false; for (StringRef CheckName : RegisteredCheckers) { std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str()); - AnalyzerChecksEnabled |= Filter.contains(ClangTidyCheckName); + AnalyzerChecksEnabled |= Context.isCheckEnabled(ClangTidyCheckName); } if (!AnalyzerChecksEnabled) @@ -324,8 +324,10 @@ static CheckersList getCheckersControlList(GlobList &Filter) { 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; } @@ -371,8 +373,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer( 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; @@ -391,13 +392,12 @@ ClangTidyASTConsumerFactory::CreateASTConsumer( 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()); diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp index ca3494fd2a9..741bac603f8 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -214,14 +214,14 @@ ClangTidyOptions ClangTidyContext::getOptionsForFile(StringRef File) const { 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. @@ -252,7 +252,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer( 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(); @@ -384,9 +384,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic( 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); } diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h index ad447fdedaf..19dd6f22f2b 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -136,14 +136,14 @@ public: /// 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; diff --git a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp index 3a3ae82e6a9..9dbf01619ce 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp @@ -24,9 +24,8 @@ void ClangTidyCheckFactories::registerCheckFactory(StringRef Name, 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)); } } |

