r356674 - [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.
Roman Lebedev via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 21 08:33:12 PDT 2019
Author: lebedevri
Date: Thu Mar 21 08:33:10 2019
New Revision: 356674
URL: http://llvm.org/viewvc/llvm-project?rev=356674&view=rev
Log:
[ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.
Summary:
A simple matcher for `OMPExecutableDirective` Stmt type.
Split off from D57113.
Reviewers: gribozavr, aaron.ballman, JonasToth, george.karpenkov
Reviewed By: gribozavr, aaron.ballman
Subscribers: guansong, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59453
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Mar 21 08:33:10 2019
@@ -1375,6 +1375,20 @@ Example matches @try
</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('ompExecutableDirective0')"><a name="ompExecutableDirective0Anchor">ompExecutableDirective</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>>...</td></tr>
+<tr><td colspan="4" class="doc" id="ompExecutableDirective0"><pre>Matches any ``#pragma omp`` executable directive.
+
+Given
+
+ #pragma omp parallel
+ #pragma omp parallel default(none)
+ #pragma omp taskyield
+
+``ompExecutableDirective()`` matches ``omp parallel``,
+``omp parallel default(none)`` and ``omp taskyield``.
+</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('opaqueValueExpr0')"><a name="opaqueValueExpr0Anchor">opaqueValueExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>>...</td></tr>
<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers
to reference another expressions and can be met
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Mar 21 08:33:10 2019
@@ -60,6 +60,7 @@
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenMP.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
@@ -6369,6 +6370,29 @@ AST_MATCHER(FunctionDecl, hasTrailingRet
return false;
}
+//----------------------------------------------------------------------------//
+// OpenMP handling.
+//----------------------------------------------------------------------------//
+
+/// Matches any ``#pragma omp`` executable directive.
+///
+/// Given
+///
+/// \code
+/// #pragma omp parallel
+/// #pragma omp parallel default(none)
+/// #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective()`` matches ``omp parallel``,
+/// ``omp parallel default(none)`` and ``omp taskyield``.
+extern const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
+ ompExecutableDirective;
+
+//----------------------------------------------------------------------------//
+// End OpenMP handling.
+//----------------------------------------------------------------------------//
+
} // namespace ast_matchers
} // namespace clang
Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Thu Mar 21 08:33:10 2019
@@ -845,5 +845,8 @@ AST_TYPELOC_TRAVERSE_MATCHER_DEF(
AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,
PointerType, ReferenceType));
+const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
+ ompExecutableDirective;
+
} // end namespace ast_matchers
} // end namespace clang
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Mar 21 08:33:10 2019
@@ -434,6 +434,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(objcThrowStmt);
REGISTER_MATCHER(objcTryStmt);
REGISTER_MATCHER(ofClass);
+ REGISTER_MATCHER(ompExecutableDirective);
REGISTER_MATCHER(on);
REGISTER_MATCHER(onImplicitObjectArgument);
REGISTER_MATCHER(opaqueValueExpr);
Modified: cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp (original)
+++ cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp Thu Mar 21 08:33:10 2019
@@ -28,10 +28,6 @@ namespace {
AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
const ast_matchers::internal::VariadicDynCastAllOfMatcher<
- Stmt, OMPExecutableDirective>
- ompExecutableDirective;
-
-const ast_matchers::internal::VariadicDynCastAllOfMatcher<
OMPExecutableDirective, OMPTargetDirective>
ompTargetDirective;
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Thu Mar 21 08:33:10 2019
@@ -1765,5 +1765,29 @@ TEST(ObjCAutoreleaseMatcher, Autorelease
EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt()));
}
+TEST(OMPExecutableDirective, Matches) {
+ auto Matcher = stmt(ompExecutableDirective());
+
+ const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source0, Matcher));
+
+ const std::string Source1 = R"(
+void x() {
+#pragma omp taskyield
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+
+ const std::string Source2 = R"(
+void x() {
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
+}
+
} // namespace ast_matchers
} // namespace clang
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h?rev=356674&r1=356673&r2=356674&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h Thu Mar 21 08:33:10 2019
@@ -235,6 +235,18 @@ testing::AssertionResult notMatchesWithC
}
template <typename T>
+testing::AssertionResult matchesWithOpenMP(const std::string &Code,
+ const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, true, "-fopenmp");
+}
+
+template <typename T>
+testing::AssertionResult notMatchesWithOpenMP(const std::string &Code,
+ const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, false, "-fopenmp");
+}
+
+template <typename T>
testing::AssertionResult
matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
std::unique_ptr<BoundNodesCallback> FindResultVerifier,
More information about the cfe-commits
mailing list