summaryrefslogtreecommitdiffstats
path: root/include/clang/ASTMatchers
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2016-07-06 18:25:16 +0000
committerAaron Ballman <aaron@aaronballman.com>2016-07-06 18:25:16 +0000
commit7e3d158f1baee9fe6ce34c89b09b54e68c26d077 (patch)
treee6111326440ef8c3457455964b1d337a3fac8adf /include/clang/ASTMatchers
parentb8689ee716d893209ae58d29fd5a7ea372f3be8e (diff)
Add AST matchers for handling bit-fields and narrowing based on their width.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/ASTMatchers')
-rw-r--r--include/clang/ASTMatchers/ASTMatchers.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index 5ba154d335..a546518993 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -519,6 +519,38 @@ AST_MATCHER(Decl, isPrivate) {
return Node.getAccess() == AS_private;
}
+/// \brief Matches non-static data members that are bit-fields.
+///
+/// Given
+/// \code
+/// class C {
+/// int a : 2;
+/// int b;
+/// };
+/// \endcode
+/// fieldDecl(isBitField())
+/// matches 'int a;' but not 'int b;'.
+AST_MATCHER(FieldDecl, isBitField) {
+ return Node.isBitField();
+}
+
+/// \brief Matches non-static data members that are bit-fields.
+///
+/// Given
+/// \code
+/// class C {
+/// int a : 2;
+/// int b : 4;
+/// int c : 2;
+/// };
+/// \endcode
+/// fieldDecl(isBitField())
+/// matches 'int a;' and 'int c;' but not 'int b;'.
+AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width) {
+ return Node.isBitField() &&
+ Node.getBitWidthValue(Finder->getASTContext()) == Width;
+}
+
/// \brief Matches a declaration that has been implicitly added
/// by the compiler (eg. implicit default/copy constructors).
AST_MATCHER(Decl, isImplicit) {