Skip to content

Commit 61948d2

Browse files
committed
[NFC][SpecialCaseList] Hide Section internal in private section
Preparing to moving most of implementation out of the header file. Pull Request: llvm#167276
1 parent afbe6ca commit 61948d2

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
534534
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
535535
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
536536
for (const auto &SectionEntry : sections()) {
537-
StringRef DiagGroup = SectionEntry.SectionStr;
537+
StringRef DiagGroup = SectionEntry.name();
538538
if (DiagGroup == "*") {
539539
// Drop the default section introduced by special case list, we only
540540
// support exact diagnostic group names.

clang/lib/Basic/ProfileList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList {
3636

3737
bool hasPrefix(StringRef Prefix) const {
3838
for (const auto &It : sections())
39-
if (It.Entries.count(Prefix) > 0)
39+
if (It.hasPrefix(Prefix))
4040
return true;
4141
return false;
4242
}

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
4242
SanitizerMask Mask;
4343

4444
#define SANITIZER(NAME, ID) \
45-
if (S.SectionMatcher.matchAny(NAME)) \
45+
if (S.matchName(NAME)) \
4646
Mask |= SanitizerKind::ID;
4747
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
4848

@@ -68,7 +68,7 @@ SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask, StringRef Prefix,
6868
if (S.Mask & Mask) {
6969
unsigned LineNum = S.S.getLastMatch(Prefix, Query, Category);
7070
if (LineNum > 0)
71-
return {S.S.FileIdx, LineNum};
71+
return {S.S.fileIndex(), LineNum};
7272
}
7373
}
7474
return NotFound;

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,22 @@ class SpecialCaseList {
195195
using SectionEntries = StringMap<StringMap<Matcher>>;
196196

197197
protected:
198-
struct Section {
198+
class Section {
199+
public:
199200
Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
200201
: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
201202
FileIdx(FileIdx) {}
202203

203204
Section(Section &&) = default;
204205

205-
Matcher SectionMatcher;
206-
SectionEntries Entries;
207-
std::string SectionStr;
208-
unsigned FileIdx;
206+
// Return name of the section, it's entire string in [].
207+
StringRef name() const { return SectionStr; }
208+
209+
// Returns true of string 'Name' matches section name interpreted as a glob.
210+
LLVM_ABI bool matchName(StringRef Name) const;
211+
212+
// Return sequence number of the file where this section is defined.
213+
unsigned fileIndex() const { return FileIdx; }
209214

210215
// Helper method to search by Prefix, Query, and Category. Returns
211216
// 1-based line number on which rule is defined, or 0 if there is no match.
@@ -217,11 +222,19 @@ class SpecialCaseList {
217222
LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
218223
StringRef Category) const;
219224

225+
/// Returns true if the section has any entries for the given prefix.
226+
LLVM_ABI bool hasPrefix(StringRef Prefix) const;
227+
220228
private:
221229
friend class SpecialCaseList;
222230
LLVM_ABI void preprocess(bool OrderBySize);
223231
LLVM_ABI const SpecialCaseList::Matcher *
224232
findMatcher(StringRef Prefix, StringRef Category) const;
233+
234+
Matcher SectionMatcher;
235+
std::string SectionStr;
236+
SectionEntries Entries;
237+
unsigned FileIdx;
225238
};
226239

227240
ArrayRef<const Section> sections() const { return Sections; }

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
358358
return NotFound;
359359
}
360360

361+
bool SpecialCaseList::Section::matchName(StringRef Name) const {
362+
return SectionMatcher.matchAny(Name);
363+
}
364+
361365
const SpecialCaseList::Matcher *
362366
SpecialCaseList::Section::findMatcher(StringRef Prefix,
363367
StringRef Category) const {
@@ -394,4 +398,8 @@ StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
394398
return {};
395399
}
396400

401+
bool SpecialCaseList::Section::hasPrefix(StringRef Prefix) const {
402+
return Entries.find(Prefix) != Entries.end();
403+
}
404+
397405
} // namespace llvm

0 commit comments

Comments
 (0)