[PATCH] D128103: Adds AST Matcher for ObjCStringLiteral
Rashmi Mudduluru via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 28 14:08:30 PDT 2022
t-rasmud updated this revision to Diff 440766.
t-rasmud added a comment.
Removes manually added documentation and adds it in the header file.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128103/new/
https://reviews.llvm.org/D128103
Files:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2352,6 +2352,26 @@
argumentCountIs(0))));
}
+TEST(ASTMatchersTestObjC, ObjCStringLiteral) {
+
+ StringRef Objc1String = "@interface NSObject "
+ "@end "
+ "@interface NSString "
+ "@end "
+ "@interface Test : NSObject "
+ "+ (void)someFunction:(NSString *)Desc; "
+ "@end "
+ "@implementation Test "
+ "+ (void)someFunction:(NSString *)Desc { "
+ " return; "
+ "} "
+ "- (void) foo { "
+ " [Test someFunction:@\"Ola!\"]; "
+ "}\n"
+ "@end ";
+ EXPECT_TRUE(matchesObjC(Objc1String, objcStringLiteral()));
+}
+
TEST(ASTMatchersTestObjC, ObjCDecls) {
StringRef ObjCString = "@protocol Proto "
"- (void)protoDidThing; "
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -505,6 +505,7 @@
REGISTER_MATCHER(objcObjectPointerType);
REGISTER_MATCHER(objcPropertyDecl);
REGISTER_MATCHER(objcProtocolDecl);
+ REGISTER_MATCHER(objcStringLiteral);
REGISTER_MATCHER(objcThrowStmt);
REGISTER_MATCHER(objcTryStmt);
REGISTER_MATCHER(ofClass);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -917,6 +917,7 @@
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
cxxBoolLiteral;
const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral;
+const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral> objcStringLiteral;
const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
characterLiteral;
const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1515,6 +1515,15 @@
extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
objcMessageExpr;
+/// Matches ObjectiveC String literal expressions.
+///
+/// Example matches @"abcd"
+/// \code
+/// NSString *s = @"abcd";
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral>
+ objcStringLiteral;
+
/// Matches Objective-C interface declarations.
///
/// Example matches Foo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128103.440766.patch
Type: text/x-patch
Size: 3122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/9f542c17/attachment.bin>
More information about the cfe-commits
mailing list