-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy] matchesAnyListedTypeName
support non canonical types
#134869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HerrCai0907
merged 1 commit into
main
from
users/ccc04-08-_clang-tidy_matchesanylistedtypename_support_non_canonical_types
Apr 13, 2025
Merged
[clang-tidy] matchesAnyListedTypeName
support non canonical types
#134869
HerrCai0907
merged 1 commit into
main
from
users/ccc04-08-_clang-tidy_matchesanylistedtypename_support_non_canonical_types
Apr 13, 2025
Conversation
This file contains hidden or 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
@llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134869.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index 7e89cae1c3316..742dc6fda8c92 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -18,8 +18,9 @@ bool NotIdenticalStatementsPredicate::operator()(
}
MatchesAnyListedTypeNameMatcher::MatchesAnyListedTypeNameMatcher(
- llvm::ArrayRef<StringRef> NameList)
- : NameMatchers(NameList.begin(), NameList.end()) {}
+ llvm::ArrayRef<StringRef> NameList, bool CanonicalTypes)
+ : NameMatchers(NameList.begin(), NameList.end()),
+ CanonicalTypes(CanonicalTypes) {}
MatchesAnyListedTypeNameMatcher::~MatchesAnyListedTypeNameMatcher() = default;
@@ -32,7 +33,7 @@ bool MatchesAnyListedTypeNameMatcher::matches(
PrintingPolicy PrintingPolicyWithSuppressedTag(
Finder->getASTContext().getLangOpts());
- PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = true;
+ PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = CanonicalTypes;
PrintingPolicyWithSuppressedTag.SuppressElaboration = true;
PrintingPolicyWithSuppressedTag.SuppressScope = false;
PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h
index 451c4ce92585b..2b6d377b8fd10 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -172,7 +172,8 @@ AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID) {
class MatchesAnyListedTypeNameMatcher
: public ast_matchers::internal::MatcherInterface<QualType> {
public:
- explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList);
+ explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList,
+ bool CanonicalTypes);
~MatchesAnyListedTypeNameMatcher() override;
bool matches(
const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
@@ -180,13 +181,19 @@ class MatchesAnyListedTypeNameMatcher
private:
std::vector<llvm::Regex> NameMatchers;
+ bool CanonicalTypes;
};
// Returns a matcher that matches QualType against a list of provided regular.
inline ::clang::ast_matchers::internal::Matcher<QualType>
-matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
+matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList,
+ bool CanonicalTypes) {
return ::clang::ast_matchers::internal::makeMatcher(
- new MatchesAnyListedTypeNameMatcher(NameList));
+ new MatchesAnyListedTypeNameMatcher(NameList, CanonicalTypes));
+}
+inline ::clang::ast_matchers::internal::Matcher<QualType>
+matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
+ return matchesAnyListedTypeName(NameList, true);
}
} // namespace clang::tidy::matchers
|
@llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134869.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index 7e89cae1c3316..742dc6fda8c92 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -18,8 +18,9 @@ bool NotIdenticalStatementsPredicate::operator()(
}
MatchesAnyListedTypeNameMatcher::MatchesAnyListedTypeNameMatcher(
- llvm::ArrayRef<StringRef> NameList)
- : NameMatchers(NameList.begin(), NameList.end()) {}
+ llvm::ArrayRef<StringRef> NameList, bool CanonicalTypes)
+ : NameMatchers(NameList.begin(), NameList.end()),
+ CanonicalTypes(CanonicalTypes) {}
MatchesAnyListedTypeNameMatcher::~MatchesAnyListedTypeNameMatcher() = default;
@@ -32,7 +33,7 @@ bool MatchesAnyListedTypeNameMatcher::matches(
PrintingPolicy PrintingPolicyWithSuppressedTag(
Finder->getASTContext().getLangOpts());
- PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = true;
+ PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = CanonicalTypes;
PrintingPolicyWithSuppressedTag.SuppressElaboration = true;
PrintingPolicyWithSuppressedTag.SuppressScope = false;
PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h
index 451c4ce92585b..2b6d377b8fd10 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -172,7 +172,8 @@ AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID) {
class MatchesAnyListedTypeNameMatcher
: public ast_matchers::internal::MatcherInterface<QualType> {
public:
- explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList);
+ explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList,
+ bool CanonicalTypes);
~MatchesAnyListedTypeNameMatcher() override;
bool matches(
const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
@@ -180,13 +181,19 @@ class MatchesAnyListedTypeNameMatcher
private:
std::vector<llvm::Regex> NameMatchers;
+ bool CanonicalTypes;
};
// Returns a matcher that matches QualType against a list of provided regular.
inline ::clang::ast_matchers::internal::Matcher<QualType>
-matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
+matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList,
+ bool CanonicalTypes) {
return ::clang::ast_matchers::internal::makeMatcher(
- new MatchesAnyListedTypeNameMatcher(NameList));
+ new MatchesAnyListedTypeNameMatcher(NameList, CanonicalTypes));
+}
+inline ::clang::ast_matchers::internal::Matcher<QualType>
+matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
+ return matchesAnyListedTypeName(NameList, true);
}
} // namespace clang::tidy::matchers
|
Base automatically changed from
users/ccc04-08-_clang-tidy_nfc_update_test_name_and_config_for_bugprone-unintended-char-ostream-output
to
main
April 8, 2025 15:46
164409d
to
27b7028
Compare
NagyDonat
approved these changes
Apr 9, 2025
Merge activity
|
27b7028
to
833d092
Compare
833d092
to
104d0cc
Compare
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this pull request
Apr 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.