Skip to content

Commit

Permalink
Merged master:10ddb927c1c3 into amd-gfx:e8442293e545
Browse files Browse the repository at this point in the history
Local branch amd-gfx e844229 Merged master:07f234be1ccb into amd-gfx:d297d238073e
Remote branch master 10ddb92 [SCEV] Use isa<> pattern for testing for CouldNotCompute [NFC]
  • Loading branch information
Sw authored and Sw committed Nov 25, 2020
2 parents e844229 + 10ddb92 commit b20f02e
Show file tree
Hide file tree
Showing 66 changed files with 1,057 additions and 377 deletions.
35 changes: 30 additions & 5 deletions clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,32 @@ static StringRef const StyleNames[] = {
#undef NAMING_KEYS
// clang-format on

IdentifierNamingCheck::NamingStyle::NamingStyle(
llvm::Optional<IdentifierNamingCheck::CaseType> Case,
const std::string &Prefix, const std::string &Suffix,
const std::string &IgnoredRegexpStr)
: Case(Case), Prefix(Prefix), Suffix(Suffix),
IgnoredRegexpStr(IgnoredRegexpStr) {
if (!IgnoredRegexpStr.empty()) {
IgnoredRegexp =
llvm::Regex(llvm::SmallString<128>({"^", IgnoredRegexpStr, "$"}));
if (!IgnoredRegexp.isValid())
llvm::errs() << "Invalid IgnoredRegexp regular expression: "
<< IgnoredRegexpStr;
}
}

static IdentifierNamingCheck::FileStyle
getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles(
SK_Count);
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles;
Styles.resize(SK_Count);
SmallString<64> StyleString;
for (unsigned I = 0; I < SK_Count; ++I) {
StyleString = StyleNames[I];
size_t StyleSize = StyleString.size();
StyleString.append("IgnoredRegexp");
std::string IgnoredRegexpStr = Options.get(StyleString, "");
StyleString.resize(StyleSize);
StyleString.append("Prefix");
std::string Prefix(Options.get(StyleString, ""));
// Fast replacement of [Pre]fix -> [Suf]fix.
Expand All @@ -141,9 +159,10 @@ getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
auto CaseOptional =
Options.getOptional<IdentifierNamingCheck::CaseType>(StyleString);

if (CaseOptional || !Prefix.empty() || !Postfix.empty())
if (CaseOptional || !Prefix.empty() || !Postfix.empty() ||
!IgnoredRegexpStr.empty())
Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
std::move(Postfix));
std::move(Postfix), std::move(IgnoredRegexpStr));
}
bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
return {std::move(Styles), IgnoreMainLike};
Expand Down Expand Up @@ -175,6 +194,9 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
continue;
StyleString = StyleNames[I];
size_t StyleSize = StyleString.size();
StyleString.append("IgnoredRegexp");
Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr);
StyleString.resize(StyleSize);
StyleString.append("Prefix");
Options.store(Opts, StyleString, Styles[I]->Prefix);
// Fast replacement of [Pre]fix -> [Suf]fix.
Expand All @@ -194,7 +216,7 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}

static bool matchesStyle(StringRef Name,
IdentifierNamingCheck::NamingStyle Style) {
const IdentifierNamingCheck::NamingStyle &Style) {
static llvm::Regex Matchers[] = {
llvm::Regex("^.*$"),
llvm::Regex("^[a-z][a-z0-9_]*$"),
Expand Down Expand Up @@ -681,6 +703,9 @@ static llvm::Optional<RenamerClangTidyCheck::FailureInfo> getFailureInfo(
return None;

const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
return None;

if (matchesStyle(Name, Style))
return None;

Expand Down
10 changes: 8 additions & 2 deletions clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
NamingStyle() = default;

NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix,
const std::string &Suffix)
: Case(Case), Prefix(Prefix), Suffix(Suffix) {}
const std::string &Suffix, const std::string &IgnoredRegexpStr);
NamingStyle(const NamingStyle &O) = delete;
NamingStyle &operator=(NamingStyle &&O) = default;
NamingStyle(NamingStyle &&O) = default;

llvm::Optional<CaseType> Case;
std::string Prefix;
std::string Suffix;
// Store both compiled and non-compiled forms so original value can be
// serialized
llvm::Regex IgnoredRegexp;
std::string IgnoredRegexpStr;
};

struct FileStyle {
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Changes in existing checks
Added support for specifying the style of scoped ``enum`` constants. If
unspecified, will fall back to the style for regular ``enum`` constants.

Added an option `IgnoredRegexp` per identifier type to suppress identifier
naming checks for names matching a regular expression.

- Removed `google-runtime-references` check because the rule it checks does
not exist in the Google Style Guide anymore.

Expand Down
Loading

0 comments on commit b20f02e

Please sign in to comment.