Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ static bool parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
void ClangTidyContext::setCurrentFile(StringRef File) {
CurrentFile = std::string(File);
CurrentOptions = getOptionsForFile(CurrentFile);
CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
WarningAsErrorFilter =
std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
CheckFilter = {*getOptions().Checks};
WarningAsErrorFilter = {*getOptions().WarningsAsErrors};
if (!parseFileExtensions(*getOptions().HeaderFileExtensions,
HeaderFileExtensions))
this->configurationDiag("Invalid header file extensions");
Expand Down Expand Up @@ -284,13 +283,11 @@ ClangTidyContext::getProfileStorageParams() const {
}

bool ClangTidyContext::isCheckEnabled(StringRef CheckName) const {
assert(CheckFilter != nullptr);
return CheckFilter->contains(CheckName);
return CheckFilter.contains(CheckName);
}

bool ClangTidyContext::treatAsError(StringRef CheckName) const {
assert(WarningAsErrorFilter != nullptr);
return WarningAsErrorFilter->contains(CheckName);
return WarningAsErrorFilter.contains(CheckName);
}

std::string ClangTidyContext::getCheckName(unsigned DiagnosticID) const {
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ClangTidyOptions.h"
#include "ClangTidyProfiling.h"
#include "FileExtensionsSet.h"
#include "GlobList.h"
#include "NoLintDirectiveHandler.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Tooling/Core/Diagnostic.h"
Expand All @@ -27,7 +28,6 @@ class ASTContext;
class SourceManager;

namespace tidy {
class CachedGlobList;

/// A detected error complete with information to display diagnostic and
/// automatic fix.
Expand Down Expand Up @@ -247,8 +247,8 @@ class ClangTidyContext {
std::string CurrentFile;
ClangTidyOptions CurrentOptions;

std::unique_ptr<CachedGlobList> CheckFilter;
std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
CachedGlobList CheckFilter;
CachedGlobList WarningAsErrorFilter;

FileExtensionsSet HeaderFileExtensions;
FileExtensionsSet ImplementationFileExtensions;
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/GlobList.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace clang::tidy {
/// them in the order of appearance in the list.
class GlobList {
public:
virtual ~GlobList() = default;
GlobList() = default;

/// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
/// supported) with an optional '-' prefix to denote exclusion.
Expand All @@ -38,7 +38,7 @@ class GlobList {

/// Returns \c true if the pattern matches \p S. The result is the last
/// matching glob's Positive flag.
virtual bool contains(StringRef S) const;
bool contains(StringRef S) const;

private:
struct GlobListItem {
Expand All @@ -54,12 +54,12 @@ class GlobList {

/// A \p GlobList that caches search results, so that search is performed only
/// once for the same query.
class CachedGlobList final : public GlobList {
class CachedGlobList : public GlobList {
public:
using GlobList::GlobList;

/// \see GlobList::contains
bool contains(StringRef S) const override;
bool contains(StringRef S) const;

private:
mutable llvm::StringMap<bool> Cache;
Expand Down
16 changes: 7 additions & 9 deletions clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ class NoLintToken {
// - Negative globs ignored (which would effectively disable the suppression).
NoLintToken(NoLintType Type, size_t Pos,
const std::optional<StringRef> &Checks)
: Type(Type), Pos(Pos), ChecksGlob(std::make_unique<CachedGlobList>(
Checks.value_or("*"),
/*KeepNegativeGlobs=*/false)) {
: Type(Type), Pos(Pos), ChecksGlob(Checks.value_or("*"),
/*KeepNegativeGlobs=*/false) {
if (Checks)
this->Checks = trimWhitespace(*Checks);
}
Expand All @@ -93,13 +92,13 @@ class NoLintToken {
size_t Pos;

// A glob of the checks this NOLINT token disables.
std::unique_ptr<CachedGlobList> ChecksGlob;
CachedGlobList ChecksGlob;

// If this NOLINT specifies checks, return the checks.
const std::optional<std::string> &checks() const { return Checks; }

// Whether this NOLINT applies to the provided check.
bool suppresses(StringRef Check) const { return ChecksGlob->contains(Check); }
bool suppresses(StringRef Check) const { return ChecksGlob.contains(Check); }

private:
std::optional<std::string> Checks;
Expand Down Expand Up @@ -156,21 +155,20 @@ namespace {
// Represents a source range within a pair of NOLINT(BEGIN/END) comments.
class NoLintBlockToken {
public:
NoLintBlockToken(size_t BeginPos, size_t EndPos,
std::unique_ptr<CachedGlobList> ChecksGlob)
NoLintBlockToken(size_t BeginPos, size_t EndPos, CachedGlobList ChecksGlob)
: BeginPos(BeginPos), EndPos(EndPos), ChecksGlob(std::move(ChecksGlob)) {}

// Whether the provided diagnostic is within and is suppressible by this block
// of NOLINT(BEGIN/END) comments.
bool suppresses(size_t DiagPos, StringRef DiagName) const {
return (BeginPos < DiagPos) && (DiagPos < EndPos) &&
ChecksGlob->contains(DiagName);
ChecksGlob.contains(DiagName);
}

private:
size_t BeginPos;
size_t EndPos;
std::unique_ptr<CachedGlobList> ChecksGlob;
CachedGlobList ChecksGlob;
};

} // namespace
Expand Down