From 079275b4dc23d6eb5fd539b2a48e4182cdfe8a59 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Fri, 27 Jul 2018 17:26:11 +0000 Subject: [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 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 16 ++++++++++++++++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'clang/include') 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 expr; extern const internal::VariadicDynCastAllOfMatcher 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 + 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 to a matcher of desired type \c To by /// "adapting" a \c To into a \c T. -- cgit v1.2.1