-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
472 changed files
with
39,811 additions
and
17,596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===--- tools/extra/clang-tidy/GlobList.cpp ------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "GlobList.h" | ||
#include "llvm/ADT/SmallString.h" | ||
|
||
using namespace clang; | ||
using namespace tidy; | ||
|
||
// Returns true if GlobList starts with the negative indicator ('-'), removes it | ||
// from the GlobList. | ||
static bool ConsumeNegativeIndicator(StringRef &GlobList) { | ||
GlobList = GlobList.trim(" \r\n"); | ||
if (GlobList.startswith("-")) { | ||
GlobList = GlobList.substr(1); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// Converts first glob from the comma-separated list of globs to Regex and | ||
// removes it and the trailing comma from the GlobList. | ||
static llvm::Regex ConsumeGlob(StringRef &GlobList) { | ||
StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(',')); | ||
StringRef Glob = UntrimmedGlob.trim(' '); | ||
GlobList = GlobList.substr(UntrimmedGlob.size() + 1); | ||
SmallString<128> RegexText("^"); | ||
StringRef MetaChars("()^$|*+?.[]\\{}"); | ||
for (char C : Glob) { | ||
if (C == '*') | ||
RegexText.push_back('.'); | ||
else if (MetaChars.find(C) != StringRef::npos) | ||
RegexText.push_back('\\'); | ||
RegexText.push_back(C); | ||
} | ||
RegexText.push_back('$'); | ||
return llvm::Regex(RegexText); | ||
} | ||
|
||
GlobList::GlobList(StringRef Globs) | ||
: Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)), | ||
NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {} | ||
|
||
bool GlobList::contains(StringRef S, bool Contains) { | ||
if (Regex.match(S)) | ||
Contains = Positive; | ||
|
||
if (NextGlob) | ||
Contains = NextGlob->contains(S, Contains); | ||
return Contains; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===--- GlobList.h ---------------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H | ||
|
||
#include "clang/Basic/LLVM.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/Regex.h" | ||
#include <memory> | ||
|
||
namespace clang { | ||
namespace tidy { | ||
|
||
/// Read-only set of strings represented as a list of positive and | ||
/// negative globs. Positive globs add all matched strings to the set, negative | ||
/// globs remove them in the order of appearance in the list. | ||
class GlobList { | ||
public: | ||
/// \p GlobList is a comma-separated list of globs (only '*' | ||
/// metacharacter is supported) with optional '-' prefix to denote exclusion. | ||
GlobList(StringRef Globs); | ||
|
||
/// Returns \c true if the pattern matches \p S. The result is the last | ||
/// matching glob's Positive flag. | ||
bool contains(StringRef S) { return contains(S, false); } | ||
|
||
private: | ||
bool contains(StringRef S, bool Contains); | ||
|
||
bool Positive; | ||
llvm::Regex Regex; | ||
std::unique_ptr<GlobList> NextGlob; | ||
}; | ||
|
||
} // end namespace tidy | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.