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 {
@@ -118,114 +110,45 @@ class SpecialCaseList {
118110 // classes.
119111 LLVM_ABI bool createInternal (const std::vector<std::string> &Paths,
120112 vfs::FileSystem &VFS, std::string &Error);
121- LLVM_ABI bool createInternal (const MemoryBuffer *MB, std::string &Error,
122- bool OrderBySize = false );
113+ LLVM_ABI bool createInternal (const MemoryBuffer *MB, std::string &Error);
123114
124115 SpecialCaseList () = default ;
125116 SpecialCaseList (SpecialCaseList const &) = delete ;
126117 SpecialCaseList &operator =(SpecialCaseList const &) = delete ;
127118
128- private:
129- // Lagacy v1 matcher.
130- class RegexMatcher {
119+ class Section {
131120 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 ;
121+ LLVM_ABI Section (StringRef Name, unsigned FileIdx, bool UseGlobs);
122+ LLVM_ABI Section (Section &&);
123+ LLVM_ABI ~Section ();
190124
191- LLVM_ABI bool matchAny (StringRef Query) const {
192- bool R = false ;
193- match (Query, [&](StringRef, unsigned ) { R = true ; });
194- return R;
195- }
125+ // Return name of the section, it's entire string in [].
126+ StringRef name () const { return Name; }
196127
197- std::variant<RegexMatcher, GlobMatcher> M;
198- bool RemoveDotSlash;
199- };
200-
201- using SectionEntries = StringMap<StringMap<Matcher>>;
128+ // Returns true of string 'Name' matches section name interpreted as a glob.
129+ LLVM_ABI bool matchName (StringRef Name) const ;
202130
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;
131+ // Return sequence number of the file where this section is defined.
132+ unsigned fileIndex () const { return FileIdx; }
215133
216134 // Helper method to search by Prefix, Query, and Category. Returns
217135 // 1-based line number on which rule is defined, or 0 if there is no match.
218136 LLVM_ABI unsigned getLastMatch (StringRef Prefix, StringRef Query,
219137 StringRef Category) const ;
220138
139+ // / Returns true if the section has any entries for the given prefix.
140+ LLVM_ABI bool hasPrefix (StringRef Prefix) const ;
141+
221142 private:
222143 friend class SpecialCaseList ;
223- LLVM_ABI void preprocess (bool OrderBySize);
224- LLVM_ABI const SpecialCaseList::Matcher *
225- findMatcher (StringRef Prefix, StringRef Category) const ;
144+ class SectionImpl ;
145+
146+ StringRef Name;
147+ unsigned FileIdx;
148+ std::unique_ptr<SectionImpl> Impl;
226149 };
227150
228- ArrayRef< const Section> sections () const { return Sections; }
151+ const std::vector< Section> & sections () const ;
229152
230153private:
231154 BumpPtrAllocator StrAlloc;
@@ -237,7 +160,7 @@ class SpecialCaseList {
237160
238161 // / Parses just-constructed SpecialCaseList entries from a memory buffer.
239162 LLVM_ABI bool parse (unsigned FileIdx, const MemoryBuffer *MB,
240- std::string &Error, bool OrderBySize );
163+ std::string &Error);
241164};
242165
243166} // namespace llvm
0 commit comments