diff options
author | Ben Hamilton <benhamilton@google.com> | 2019-04-22 17:54:11 +0000 |
---|---|---|
committer | Ben Hamilton <benhamilton@google.com> | 2019-04-22 17:54:11 +0000 |
commit | 6b8fd557a1fb4e5ad6ccec5c3a582ec9c712284b (patch) | |
tree | 15e60e7da227178674f99f507e674507a269b983 /include | |
parent | 3711ba48f7e95cb2596ddcde16d2ad780fbd7877 (diff) |
[ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, and `isInstanceMethod`
Summary:
isClassMessage is an equivalent to isInstanceMessage for ObjCMessageExpr, but matches message expressions to classes.
isClassMethod and isInstanceMethod check whether a method declaration (or definition) is for a class method or instance method (respectively).
Contributed by @mywman!
Reviewers: benhamilton, klimek, mwyman
Reviewed By: benhamilton, mwyman
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60920
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358904 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index c5ec9f48a0..661dcbc767 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -2938,10 +2938,59 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>, return InnerMatcher.matches(TypeDecl, Finder, Builder); } +/// Returns true when the Objective-C method declaration is a class method. +/// +/// Example +/// matcher = objcMethodDecl(isClassMethod()) +/// matches +/// \code +/// @interface I + (void)foo; @end +/// \endcode +/// but not +/// \code +/// @interface I - (void)bar; @end +/// \endcode +AST_MATCHER(ObjCMethodDecl, isClassMethod) { + return Node.isClassMethod(); +} + +/// Returns true when the Objective-C method declaration is an instance method. +/// +/// Example +/// matcher = objcMethodDecl(isInstanceMethod()) +/// matches +/// \code +/// @interface I - (void)bar; @end +/// \endcode +/// but not +/// \code +/// @interface I + (void)foo; @end +/// \endcode +AST_MATCHER(ObjCMethodDecl, isInstanceMethod) { + return Node.isInstanceMethod(); +} + +/// Returns true when the Objective-C message is sent to a class. +/// +/// Example +/// matcher = objcMessageExpr(isClassMessage()) +/// matches +/// \code +/// [NSString stringWithFormat:@"format"]; +/// \endcode +/// but not +/// \code +/// NSString *x = @"hello"; +/// [x containsString:@"h"]; +/// \endcode +AST_MATCHER(ObjCMessageExpr, isClassMessage) { + return Node.isClassMessage(); +} + /// Returns true when the Objective-C message is sent to an instance. /// /// Example -/// matcher = objcMessagaeExpr(isInstanceMessage()) +/// matcher = objcMessageExpr(isInstanceMessage()) /// matches /// \code /// NSString *x = @"hello"; |