clang-tools 20.0.0git
GlobList.h
Go to the documentation of this file.
1//===--- GlobList.h ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
11
12#include "clang/Basic/LLVM.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/ADT/StringMap.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/Regex.h"
17
18namespace clang::tidy {
19
20/// Read-only set of strings represented as a list of positive and negative
21/// globs.
22///
23/// Positive globs add all matched strings to the set, negative globs remove
24/// them in the order of appearance in the list.
25class GlobList {
26public:
27 virtual ~GlobList() = default;
28
29 /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
30 /// supported) with an optional '-' prefix to denote exclusion.
31 ///
32 /// An empty \p Globs string is interpreted as one glob that matches an empty
33 /// string.
34 ///
35 /// \p KeepNegativeGlobs a bool flag indicating whether to keep negative
36 /// globs from \p Globs or not. When false, negative globs are simply ignored.
37 GlobList(StringRef Globs, bool KeepNegativeGlobs = true);
38
39 /// Returns \c true if the pattern matches \p S. The result is the last
40 /// matching glob's Positive flag.
41 virtual bool contains(StringRef S) const;
42
43private:
44 struct GlobListItem {
45 bool IsPositive;
46 llvm::Regex Regex;
47 llvm::StringRef Text;
48 };
49 SmallVector<GlobListItem, 0> Items;
50
51public:
52 const SmallVectorImpl<GlobListItem> &getItems() const { return Items; };
53};
54
55/// A \p GlobList that caches search results, so that search is performed only
56/// once for the same query.
57class CachedGlobList final : public GlobList {
58public:
60
61 /// \see GlobList::contains
62 bool contains(StringRef S) const override;
63
64private:
65 mutable llvm::StringMap<bool> Cache;
66};
67
68} // namespace clang::tidy
69
70#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
std::string Text
A GlobList that caches search results, so that search is performed only once for the same query.
Definition: GlobList.h:57
bool contains(StringRef S) const override
Definition: GlobList.cpp:68
Read-only set of strings represented as a list of positive and negative globs.
Definition: GlobList.h:25
GlobList(StringRef Globs, bool KeepNegativeGlobs=true)
Globs is a comma-separated list of globs (only the '*' metacharacter is supported) with an optional '...
Definition: GlobList.cpp:46
virtual bool contains(StringRef S) const
Returns true if the pattern matches S.
Definition: GlobList.cpp:58
const SmallVectorImpl< GlobListItem > & getItems() const
Definition: GlobList.h:52
virtual ~GlobList()=default