[clang-tidy] matchesAnyListedTypeName support non canonical types (#134869)

This commit is contained in:
Congcong Cai 2025-04-13 12:06:48 +08:00 committed by GitHub
parent 3ff634dee8
commit 302bc41410
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -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;

View File

@ -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 @@ public:
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