[clang] Add 'isPODType' AST matcher (PR #86233)
June Rhodes via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 21 19:48:58 PDT 2024
https://github.com/hach-que updated https://github.com/llvm/llvm-project/pull/86233
>From 0e6cfaba6ab55166b7b08eecb28714c0746707f1 Mon Sep 17 00:00:00 2001
From: June Rhodes <jrhodes at redpoint.games>
Date: Fri, 22 Mar 2024 13:36:54 +1100
Subject: [PATCH] Add 'isPODType' AST matcher
---
clang/include/clang/ASTMatchers/ASTMatchers.h | 17 +++++++++++++++++
clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 +
2 files changed, 18 insertions(+)
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..b114d681828212 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4087,6 +4087,23 @@ AST_POLYMORPHIC_MATCHER_P(
return Inner.matches(source->getTypeLoc(), Finder, Builder);
}
+/// Matches if the matched type is a Plain Old Data (POD) type.
+///
+/// Given
+/// \code
+/// class Y
+/// {
+/// public:
+/// int a;
+/// std::string b;
+/// };
+/// \endcode
+/// fieldDecl(hasType(qualType(isPODType())))
+/// matches Y::a
+AST_MATCHER(QualType, isPODType) {
+ return Node.isPODType(Finder->getASTContext());
+}
+
/// Matches if the matched type is represented by the given string.
///
/// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..4f716d9f166495 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -377,6 +377,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasTypeLoc);
REGISTER_MATCHER(hasUnaryOperand);
REGISTER_MATCHER(hasUnarySelector);
+ REGISTER_MATCHER(isPODType);
REGISTER_MATCHER(hasUnderlyingDecl);
REGISTER_MATCHER(hasUnderlyingType);
REGISTER_MATCHER(hasUnqualifiedDesugaredType);
More information about the cfe-commits
mailing list