diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2018-07-27 17:26:11 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2018-07-27 17:26:11 +0000 |
commit | f0389c4d454a484b8c48b1e5c4d9aafa5444aed6 (patch) | |
tree | 3d3f2a3d189c3cd1c20e19082736eff7cd2bc5bc /include | |
parent | 3ef733230abb3cb8a8b7327fe8081525ffc5a61d (diff) | |
download | clang-f0389c4d454a484b8c48b1e5c4d9aafa5444aed6.tar.gz |
[ASTMatchers] Introduce a matcher for `ObjCIvarExpr`, support getting it's declaration.
ObjCIvarExpr is *not* a subclass of MemberExpr, and a separate matcher
is required to support it.
Adding a hasDeclaration support as well, as it's not very useful without
it.
Differential Revision: https://reviews.llvm.org/D49701
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338137 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 16 | ||||
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchersInternal.h | 9 |
2 files changed, 24 insertions, 1 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 75dc654905..58f65a39fb 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -1644,6 +1644,21 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; +/// Matches a reference to an ObjCIvar. +/// +/// Example: matches "a" in "init" method: +/// \code +/// @implementation A { +/// NSString *a; +/// } +/// - (void) init { +/// a = @"hello"; +/// } +//} +/// \endcode +extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> + objcIvarRefExpr; + /// Matches if statements. /// /// Example matches 'if (x) {}' @@ -2655,6 +2670,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless; /// - for MemberExpr, the declaration of the referenced member /// - for CXXConstructExpr, the declaration of the constructor /// - for CXXNewExpr, the declaration of the operator new +/// - for ObjCIvarExpr, the declaration of the ivar /// /// For type nodes, hasDeclaration will generally match the declaration of the /// sugared type. Given diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index c5ca6188a2..b0a45789d9 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -42,6 +42,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/Stmt.h" #include "clang/AST/TemplateName.h" @@ -865,6 +866,12 @@ private: return matchesDecl(Node.getConstructor(), Finder, Builder); } + bool matchesSpecialized(const ObjCIvarRefExpr &Node, + ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const { + return matchesDecl(Node.getDecl(), Finder, Builder); + } + /// Extracts the operator new of the new call and returns whether the /// inner matcher matches on it. bool matchesSpecialized(const CXXNewExpr &Node, @@ -1110,7 +1117,7 @@ using HasDeclarationSupportedTypes = ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr, QualType, RecordType, TagType, TemplateSpecializationType, TemplateTypeParmType, TypedefType, - UnresolvedUsingType>; + UnresolvedUsingType, ObjCIvarRefExpr>; /// Converts a \c Matcher<T> to a matcher of desired type \c To by /// "adapting" a \c To into a \c T. |