summaryrefslogtreecommitdiffstats
path: root/clang/include
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2018-07-27 17:26:11 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2018-07-27 17:26:11 +0000
commit079275b4dc23d6eb5fd539b2a48e4182cdfe8a59 (patch)
tree05bc476e11590ea3d18badb5c3e9d5f396ce9c2f /clang/include
parentfaea2d31304709b17cff19be8403952c0b3395cb (diff)
downloadbcm5719-llvm-079275b4dc23d6eb5fd539b2a48e4182cdfe8a59.tar.gz
bcm5719-llvm-079275b4dc23d6eb5fd539b2a48e4182cdfe8a59.zip
[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 llvm-svn: 338137
Diffstat (limited to 'clang/include')
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h16
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchersInternal.h9
2 files changed, 24 insertions, 1 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 75dc654905f..58f65a39fb4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/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/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index c5ca6188a22..b0a45789d9c 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/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.
OpenPOWER on IntegriCloud