|
|
|||
File indexing completed on 2026-05-10 08:36:23
0001 //===--- GlobList.h ---------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H 0011 0012 #include "clang/Basic/LLVM.h" 0013 #include "llvm/ADT/SmallVector.h" 0014 #include "llvm/ADT/StringMap.h" 0015 #include "llvm/ADT/StringRef.h" 0016 #include "llvm/Support/Regex.h" 0017 0018 namespace clang::tidy { 0019 0020 /// Read-only set of strings represented as a list of positive and negative 0021 /// globs. 0022 /// 0023 /// Positive globs add all matched strings to the set, negative globs remove 0024 /// them in the order of appearance in the list. 0025 class GlobList { 0026 public: 0027 virtual ~GlobList() = default; 0028 0029 /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is 0030 /// supported) with an optional '-' prefix to denote exclusion. 0031 /// 0032 /// An empty \p Globs string is interpreted as one glob that matches an empty 0033 /// string. 0034 /// 0035 /// \p KeepNegativeGlobs a bool flag indicating whether to keep negative 0036 /// globs from \p Globs or not. When false, negative globs are simply ignored. 0037 GlobList(StringRef Globs, bool KeepNegativeGlobs = true); 0038 0039 /// Returns \c true if the pattern matches \p S. The result is the last 0040 /// matching glob's Positive flag. 0041 virtual bool contains(StringRef S) const; 0042 0043 private: 0044 struct GlobListItem { 0045 bool IsPositive; 0046 llvm::Regex Regex; 0047 llvm::StringRef Text; 0048 }; 0049 SmallVector<GlobListItem, 0> Items; 0050 0051 public: 0052 const SmallVectorImpl<GlobListItem> &getItems() const { return Items; }; 0053 }; 0054 0055 /// A \p GlobList that caches search results, so that search is performed only 0056 /// once for the same query. 0057 class CachedGlobList final : public GlobList { 0058 public: 0059 using GlobList::GlobList; 0060 0061 /// \see GlobList::contains 0062 bool contains(StringRef S) const override; 0063 0064 private: 0065 mutable llvm::StringMap<bool> Cache; 0066 }; 0067 0068 } // namespace clang::tidy 0069 0070 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|