Change getChecksFilter() interface to hide implementation details.

llvm-svn: 303264
This commit is contained in:
Alexander Kornienko 2017-05-17 14:39:47 +00:00
parent c321a4f2b9
commit 21375185e7
4 changed files with 21 additions and 23 deletions

View File

@ -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());

View File

@ -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);
}

View File

@ -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;

View File

@ -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));
}
}