1212#ifndef LLVM_SUPPORT_SPECIALCASELIST_H
1313#define LLVM_SUPPORT_SPECIALCASELIST_H
1414
15- #include " llvm/ADT/ArrayRef.h"
16- #include " llvm/ADT/RadixTree.h"
17- #include " llvm/ADT/SmallVector.h"
18- #include " llvm/ADT/StringMap.h"
19- #include " llvm/ADT/iterator_range.h"
2015#include " llvm/Support/Allocator.h"
21- #include " llvm/Support/Compiler.h"
22- #include " llvm/Support/GlobPattern.h"
23- #include " llvm/Support/Regex.h"
16+ #include " llvm/Support/Error.h"
2417#include < memory>
2518#include < string>
2619#include < utility>
27- #include < variant>
2820#include < vector>
2921
3022namespace llvm {
@@ -125,93 +117,20 @@ class SpecialCaseList {
125117 SpecialCaseList (SpecialCaseList const &) = delete ;
126118 SpecialCaseList &operator =(SpecialCaseList const &) = delete ;
127119
128- private:
129- // Lagacy v1 matcher.
130- class RegexMatcher {
120+ class Section {
131121 public:
132- LLVM_ABI Error insert (StringRef Pattern, unsigned LineNumber);
133- LLVM_ABI void preprocess (bool BySize);
134-
135- LLVM_ABI void
136- match (StringRef Query,
137- llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const ;
138-
139- struct Reg {
140- Reg (StringRef Name, unsigned LineNo, Regex &&Rg)
141- : Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
142- StringRef Name;
143- unsigned LineNo;
144- Regex Rg;
145- };
146-
147- std::vector<Reg> RegExes;
148- };
149-
150- class GlobMatcher {
151- public:
152- LLVM_ABI Error insert (StringRef Pattern, unsigned LineNumber);
153- LLVM_ABI void preprocess (bool BySize);
154-
155- LLVM_ABI void
156- match (StringRef Query,
157- llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const ;
158-
159- struct Glob {
160- Glob (StringRef Name, unsigned LineNo, GlobPattern &&Pattern)
161- : Name(Name), LineNo(LineNo), Pattern(std::move(Pattern)) {}
162- StringRef Name;
163- unsigned LineNo;
164- GlobPattern Pattern;
165- };
166-
167- std::vector<GlobMatcher::Glob> Globs;
168-
169- RadixTree<iterator_range<StringRef::const_iterator>,
170- RadixTree<iterator_range<StringRef::const_reverse_iterator>,
171- SmallVector<const GlobMatcher::Glob *, 1 >>>
172- PrefixSuffixToGlob;
173-
174- RadixTree<iterator_range<StringRef::const_iterator>,
175- SmallVector<const GlobMatcher::Glob *, 1 >>
176- SubstrToGlob;
177- };
178-
179- // / Represents a set of patterns and their line numbers
180- class Matcher {
181- public:
182- LLVM_ABI Matcher (bool UseGlobs, bool RemoveDotSlash);
183-
184- LLVM_ABI Error insert (StringRef Pattern, unsigned LineNumber);
185- LLVM_ABI void preprocess (bool BySize);
186-
187- LLVM_ABI void
188- match (StringRef Query,
189- llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const ;
122+ LLVM_ABI Section (StringRef Name, unsigned FileIdx, bool UseGlobs);
123+ LLVM_ABI Section (Section &&);
124+ LLVM_ABI ~Section ();
190125
191- LLVM_ABI bool matchAny (StringRef Query) const {
192- bool R = false ;
193- match (Query, [&](StringRef, unsigned ) { R = true ; });
194- return R;
195- }
126+ // Return name of the section, it's entire string in [].
127+ StringRef name () const { return Name; }
196128
197- std::variant<RegexMatcher, GlobMatcher> M;
198- bool RemoveDotSlash;
199- };
200-
201- using SectionEntries = StringMap<StringMap<Matcher>>;
129+ // Returns true of string 'Name' matches section name interpreted as a glob.
130+ LLVM_ABI bool matchName (StringRef Name) const ;
202131
203- protected:
204- struct Section {
205- Section (StringRef Str, unsigned FileIdx, bool UseGlobs)
206- : SectionMatcher(UseGlobs, /* RemoveDotSlash=*/ false ), SectionStr(Str),
207- FileIdx (FileIdx) {}
208-
209- Section (Section &&) = default;
210-
211- Matcher SectionMatcher;
212- SectionEntries Entries;
213- std::string SectionStr;
214- unsigned FileIdx;
132+ // Return sequence number of the file where this section is defined.
133+ unsigned fileIndex () const { return FileIdx; }
215134
216135 // Helper method to search by Prefix, Query, and Category. Returns
217136 // 1-based line number on which rule is defined, or 0 if there is no match.
@@ -223,14 +142,19 @@ class SpecialCaseList {
223142 LLVM_ABI StringRef getLongestMatch (StringRef Prefix, StringRef Query,
224143 StringRef Category) const ;
225144
145+ // / Returns true if the section has any entries for the given prefix.
146+ LLVM_ABI bool hasPrefix (StringRef Prefix) const ;
147+
226148 private:
227149 friend class SpecialCaseList ;
228- LLVM_ABI void preprocess (bool OrderBySize);
229- LLVM_ABI const SpecialCaseList::Matcher *
230- findMatcher (StringRef Prefix, StringRef Category) const ;
150+ class SectionImpl ;
151+
152+ StringRef Name;
153+ unsigned FileIdx;
154+ std::unique_ptr<SectionImpl> Impl;
231155 };
232156
233- ArrayRef< const Section> sections () const { return Sections; }
157+ const std::vector< Section> & sections () const ;
234158
235159private:
236160 BumpPtrAllocator StrAlloc;
0 commit comments