[PATCH] D128103: Adds AST Matcher for ObjCStringLiteral
Rashmi Mudduluru via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 27 17:26:41 PDT 2022
t-rasmud updated this revision to Diff 440443.
t-rasmud added a comment.
Documentation edits and other fixes, thanks to suggestions from @ziqingluo-90
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128103/new/
https://reviews.llvm.org/D128103
Files:
clang/docs/LibASTMatchersReference.html
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,9 @@
extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
objcMessageExpr;
+extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral>
+ objcStringLiteral;
+
/// Matches Objective-C interface declarations.
///
/// Example matches Foo
Index: clang/docs/LibASTMatchersReference.html
===================================================================
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2035,6 +2035,13 @@
[[NSString alloc] initWithString:@"Hello"]
</pre></td></tr>
+<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stringLiteral0')"><a name="stringLiteral0Anchor">objcStringLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCStringLiteral.html">ObjCStringLiteral</a>>...</td></tr>
+<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches objective-C string literals.
+
+Example matches "abcd"
+ NSString *s = @"abcd";
+</pre></td></tr>
+
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcThrowStmt0')"><a name="objcThrowStmt0Anchor">objcThrowStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtThrowStmt.html">ObjCAtThrowStmt</a>>...</td></tr>
<tr><td colspan="4" class="doc" id="objcThrowStmt0"><pre>Matches Objective-C statements.
@@ -2146,7 +2153,6 @@
wchar_t *ws = L"abcd";
</pre></td></tr>
-
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('substNonTypeTemplateParmExpr0')"><a name="substNonTypeTemplateParmExpr0Anchor">substNonTypeTemplateParmExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstNonTypeTemplateParmExpr.html">SubstNonTypeTemplateParmExpr</a>>...</td></tr>
<tr><td colspan="4" class="doc" id="substNonTypeTemplateParmExpr0"><pre>Matches substitutions of non-type template parameters.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128103.440443.patch
Type: text/x-patch
Size: 4815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/da326dae/attachment.bin>
More information about the cfe-commits
mailing list