t-rasmud updated this revision to Diff 441179. Herald added a reviewer: jdoerfert. Herald added a subscriber: sstefan1.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128103/new/ https://reviews.llvm.org/D128103 Files: clang/docs/LibASTMatchersReference.html clang/docs/ReleaseNotes.rst 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 Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -536,6 +536,9 @@ - Added ``forEachTemplateArgument`` matcher which creates a match every time a ``templateArgument`` matches the matcher supplied to it. + +- Added ``objcStringLiteral`` matcher which matches ObjectiveC String + literal expressions. clang-format ------------ Index: clang/docs/LibASTMatchersReference.html =================================================================== --- clang/docs/LibASTMatchersReference.html +++ clang/docs/LibASTMatchersReference.html @@ -1236,7 +1236,7 @@ #pragma omp parallel ``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``, -``default(private)`` and ``default(firstprivate)`` +`` default(private)`` and ``default(firstprivate)`` </pre></td></tr> @@ -2036,6 +2036,14 @@ </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('objcStringLiteral0')"><a name="objcStringLiteral0Anchor">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="objcStringLiteral0"><pre>Matches ObjectiveC String literal expressions. + +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. @@ -4716,8 +4724,8 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isPrivateKind0')"><a name="isPrivateKind0Anchor">isFirstPrivateKind</a></td><td></td></tr> -<tr><td colspan="4" class="doc" id="isPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``private`` kind +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isFirstPrivateKind0')"><a name="isFirstPrivateKind0Anchor">isFirstPrivateKind</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isFirstPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``firstprivate`` kind specified. Given @@ -4729,12 +4737,12 @@ #pragma omp parallel default(firstprivate) ``ompDefaultClause(isFirstPrivateKind())`` matches only -``default(private)``. +``default(firstprivate)``. </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isFirstPrivateKind0')"><a name="isFirstPrivateKind0Anchor">isFirstPrivateKind</a></td><td></td></tr> -<tr><td colspan="4" class="doc" id="isFirstPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``firstprivate`` kind -specified. + +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isNoneKind0')"><a name="isNoneKind0Anchor">isNoneKind</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified. Given @@ -4744,13 +4752,13 @@ #pragma omp parallel default(private) #pragma omp parallel default(firstprivate) -``ompDefaultClause(isFirstPrivateKind())`` matches only -``default(firstprivate)``. +``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isNoneKind0')"><a name="isNoneKind0Anchor">isNoneKind</a></td><td></td></tr> -<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified. +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isPrivateKind0')"><a name="isPrivateKind0Anchor">isPrivateKind</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``private`` kind +specified. Given @@ -4760,7 +4768,8 @@ #pragma omp parallel default(private) #pragma omp parallel default(firstprivate) -``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. +``ompDefaultClause(isPrivateKind())`` matches only +``default(private)``. </pre></td></tr> @@ -7411,8 +7420,9 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument0')"><a name="forEachTemplateArgument0Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> -<tr><td colspan="4" class="doc" id="forEachTemplateArgument0"><pre>Matches classTemplateSpecialization, templateSpecializationType and functionDecl nodes where the template argument matches the inner matcher. +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument0')"><a name="forEachTemplateArgument0Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="forEachTemplateArgument0"><pre>Matches classTemplateSpecialization, templateSpecializationType and +functionDecl nodes where the template argument matches the inner matcher. This matcher may produce multiple matches. Given @@ -7427,10 +7437,8 @@ bool B = false; f(R, B); - templateSpecializationType(forEachTemplateArgument(isExpr(expr()))) matches twice, with expr() matching 'R * 2' and 'R * 4' - functionDecl(forEachTemplateArgument(refersToType(builtinType()))) matches the specialization f<unsigned, bool> twice, for 'unsigned' and 'bool' @@ -8180,6 +8188,31 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument2')"><a name="forEachTemplateArgument2Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="forEachTemplateArgument2"><pre>Matches classTemplateSpecialization, templateSpecializationType and +functionDecl nodes where the template argument matches the inner matcher. +This matcher may produce multiple matches. + +Given + template <typename T, unsigned N, unsigned M> + struct Matrix {}; + + constexpr unsigned R = 2; + Matrix<int, R * 2, R * 4> M; + + template <typename T, typename U> + void f(T&& t, U&& u) {} + + bool B = false; + f(R, B); +templateSpecializationType(forEachTemplateArgument(isExpr(expr()))) + matches twice, with expr() matching 'R * 2' and 'R * 4' +functionDecl(forEachTemplateArgument(refersToType(builtinType()))) + matches the specialization f<unsigned, bool> twice, for 'unsigned' + and 'bool' +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyBody0')"><a name="hasAnyBody0Anchor">hasAnyBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasAnyBody0"><pre>Matches a function declaration that has a given body present in the AST. Note that this matcher matches all the declarations of a function whose @@ -8227,32 +8260,6 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument1')"><a name="forEachTemplateArgument1Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> -<tr><td colspan="4" class="doc" id="forEachTemplateArgument1"><pre>Matches classTemplateSpecialization, templateSpecializationType and functionDecl nodes where the template argument matches the inner matcher. -This matcher may produce multiple matches. - -Given - template <typename T, unsigned N, unsigned M> - struct Matrix {}; - - constexpr unsigned R = 2; - Matrix<int, R * 2, R * 4> M; - - template <typename T, typename U> - void f(T&& t, U&& u) {} - - bool B = false; - f(R, B); - -templateSpecializationType(forEachTemplateArgument(isExpr(expr()))) - matches twice, with expr() matching 'R * 2' and 'R * 4' - -functionDecl(forEachTemplateArgument(refersToType(builtinType()))) - matches the specialization f<unsigned, bool> twice, for 'unsigned' - and 'bool' -</pre></td></tr> - - <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument2')"><a name="hasAnyTemplateArgument2Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and functionDecl that have at least one TemplateArgument matching the given @@ -9477,11 +9484,11 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('forEachTemplateArgument2')"><a name="forEachTemplateArgument2Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> -<tr><td colspan="4" class="doc" id="forEachTemplateArgument2"><pre>Matches classTemplateSpecialization, templateSpecializationType and functionDecl nodes where the template argument matches the inner matcher. +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('forEachTemplateArgument1')"><a name="forEachTemplateArgument1Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="forEachTemplateArgument1"><pre>Matches classTemplateSpecialization, templateSpecializationType and +functionDecl nodes where the template argument matches the inner matcher. This matcher may produce multiple matches. - Given template <typename T, unsigned N, unsigned M> struct Matrix {}; @@ -9494,10 +9501,8 @@ bool B = false; f(R, B); - templateSpecializationType(forEachTemplateArgument(isExpr(expr()))) matches twice, with expr() matching 'R * 2' and 'R * 4' - functionDecl(forEachTemplateArgument(refersToType(builtinType()))) matches the specialization f<unsigned, bool> twice, for 'unsigned' and 'bool'
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits