Skip to content

Commit 36ae457

Browse files
committed
Implement with new glob defintion.
Created using spr 1.3.6
1 parent 13bbadc commit 36ae457

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,11 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
554554
// line.
555555
const auto &DiagSectionMatcher = Entry.SectionMatcher;
556556
unsigned DiagLine = 0;
557-
for (const auto &[Pattern, Pair] : DiagSectionMatcher->Globs)
558-
if (Pattern == DiagName)
559-
DiagLine = Pair.second;
557+
for (const auto &Glob : DiagSectionMatcher->Globs)
558+
if (Glob->Name == DiagName) {
559+
DiagLine = Glob->LineNo;
560+
break;
561+
}
560562
LineAndSectionEntry.emplace_back(DiagLine, &Entry);
561563
}
562564
llvm::sort(LineAndSectionEntry);
@@ -628,12 +630,12 @@ bool WarningsSpecialCaseList::globsMatches(
628630
StringRef Category = Entry.getKey();
629631
const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue();
630632
bool IsPositive = Category != "emit";
631-
for (const auto &[Pattern, Glob] : Matcher.Globs) {
632-
if (Pattern.size() < LongestMatch.size())
633+
for (const auto &Glob : Matcher.Globs) {
634+
if (Glob->Name.size() < LongestMatch.size())
633635
continue;
634-
if (!Glob.first.match(FilePath))
636+
if (!Glob->Pattern.match(FilePath))
635637
continue;
636-
LongestMatch = Pattern;
638+
LongestMatch = Glob->Name;
637639
LongestIsPositive = IsPositive;
638640
}
639641
}

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@ class SpecialCaseList {
125125
// Returns zero if no match is found.
126126
LLVM_ABI unsigned match(StringRef Query) const;
127127

128-
std::vector<std::pair<std::string, std::pair<GlobPattern, unsigned>>> Globs;
128+
struct Glob {
129+
std::string Name;
130+
unsigned LineNo;
131+
GlobPattern Pattern;
132+
Glob(Glob &&) = delete;
133+
};
134+
135+
std::vector<std::unique_ptr<Matcher::Glob>> Globs;
129136
std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
130137
};
131138

llvm/lib/Support/GlobPattern.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
139139
// Store the prefix that does not contain any metacharacter.
140140
size_t PrefixSize = S.find_first_of("?*[{\\");
141141
Pat.Prefix = S.substr(0, PrefixSize);
142-
llvm::errs() << "GlobPattern::create: Prefix: " << Pat.Prefix << "\n";
143142
if (PrefixSize == std::string::npos)
144143
return Pat;
145144
S = S.substr(PrefixSize);
@@ -192,17 +191,8 @@ GlobPattern::SubGlobPattern::create(StringRef S) {
192191
}
193192

194193
bool GlobPattern::match(StringRef S) const {
195-
int debug = 0;
196-
if (S == "hello") {
197-
llvm::errs() << "Prefix: " << Prefix << "\n";
198-
debug = 1;
199-
}
200-
if (!S.consume_front(Prefix)) {
201-
if (debug == 1) {
202-
llvm::errs() << "consume_front: " << Prefix << "\n";
203-
}
194+
if (!S.consume_front(Prefix))
204195
return false;
205-
}
206196
if (SubGlobs.empty() && S.empty())
207197
return true;
208198
for (auto &Glob : SubGlobs)

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,22 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
5353
return Error::success();
5454
}
5555

56-
Globs.emplace_back();
57-
auto &Glob = Globs.back();
58-
Glob.first = Pattern.str();
59-
auto &Pair = Glob.second;
56+
std::unique_ptr<Matcher::Glob> Glob = std::make_unique<Matcher::Glob>();
57+
Glob->Name = Pattern.str();
58+
Glob->LineNo = LineNumber;
6059
// We must be sure to use the string in the map rather than the provided
6160
// reference which could be destroyed before match() is called
62-
llvm::errs() << __func__ << " GlobPattern::create: " << Glob.first << "\n";
63-
if (auto Err = GlobPattern::create(Glob.first, /*MaxSubPatterns=*/1024)
64-
.moveInto(Pair.first))
61+
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
62+
.moveInto(Glob->Pattern))
6563
return Err;
66-
Pair.second = LineNumber;
64+
Globs.push_back(std::move(Glob));
6765
return Error::success();
6866
}
6967

7068
unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
71-
for (const auto &[Pattern, Pair] : Globs) {
72-
llvm::outs() << "Inside match: " << Pattern
73-
<< " Line number: " << Pair.second << "\n";
74-
if (Pair.first.match(Query))
75-
return Pair.second;
69+
for (const auto &Glob : Globs) {
70+
if (Glob->Pattern.match(Query))
71+
return Glob->LineNo;
7672
}
7773
for (const auto &[Regex, LineNumber] : RegExes)
7874
if (Regex->match(Query))

llvm/unittests/Support/SpecialCaseListTest.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ TEST_F(SpecialCaseListTest, Basic) {
6363
"src:hi=category\n"
6464
"src:z*=category\n");
6565
EXPECT_TRUE(SCL->inSection("", "src", "hello"));
66-
// EXPECT_TRUE(SCL->inSection("", "src", "bye"));
67-
// EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
68-
// EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category"));
69-
// EXPECT_FALSE(SCL->inSection("", "src", "hi"));
70-
// EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
71-
// EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
72-
73-
// EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
74-
// EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
75-
// EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
76-
// EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category"));
77-
// EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
78-
// EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
79-
// EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
66+
EXPECT_TRUE(SCL->inSection("", "src", "bye"));
67+
EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
68+
EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category"));
69+
EXPECT_FALSE(SCL->inSection("", "src", "hi"));
70+
EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
71+
EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
72+
73+
EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
74+
EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
75+
EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
76+
EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category"));
77+
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
78+
EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
79+
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
8080
}
8181

8282
TEST_F(SpecialCaseListTest, CorrectErrorLineNumberWithBlankLine) {

0 commit comments

Comments
 (0)