[PATCH] D118900: [ASTMatchers] Expand isInline matcher to VarDecl
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 3 06:41:22 PST 2022
njames93 created this revision.
njames93 added reviewers: klimek, aaron.ballman.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Add support to the `isInline` matcher for C++17's inline variables.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118900
Files:
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -197,6 +197,8 @@
functionDecl(isInline(), hasName("f"))));
EXPECT_TRUE(matches("namespace n { inline namespace m {} }",
namespaceDecl(isInline(), hasName("m"))));
+ EXPECT_TRUE(matches("inline int Foo = 5;",
+ varDecl(isInline(), hasName("Foo")), {Lang_CXX17}));
}
// FIXME: Figure out how to specify paths so the following tests pass on
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7683,18 +7683,22 @@
/// namespace n {
/// inline namespace m {}
/// }
+/// inline int Foo = 5;
/// \endcode
/// functionDecl(isInline()) will match ::f().
/// namespaceDecl(isInline()) will match n::m.
-AST_POLYMORPHIC_MATCHER(isInline,
- AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl,
- FunctionDecl)) {
+/// varDecl(isInline()) will match Foo;
+AST_POLYMORPHIC_MATCHER(isInline, AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl,
+ FunctionDecl,
+ VarDecl)) {
// This is required because the spelling of the function used to determine
// whether inline is specified or not differs between the polymorphic types.
if (const auto *FD = dyn_cast<FunctionDecl>(&Node))
return FD->isInlineSpecified();
- else if (const auto *NSD = dyn_cast<NamespaceDecl>(&Node))
+ if (const auto *NSD = dyn_cast<NamespaceDecl>(&Node))
return NSD->isInline();
+ if (const auto *VD = dyn_cast<VarDecl>(&Node))
+ return VD->isInline();
llvm_unreachable("Not a valid polymorphic type");
}
Index: clang/docs/LibASTMatchersReference.html
===================================================================
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -4331,8 +4331,10 @@
namespace n {
inline namespace m {}
}
+ inline int Foo = 5;
functionDecl(isInline()) will match ::f().
namespaceDecl(isInline()) will match n::m.
+varDecl(isInline()) will match Foo;
</pre></td></tr>
@@ -4706,8 +4708,10 @@
namespace n {
inline namespace m {}
}
+ inline int Foo = 5;
functionDecl(isInline()) will match ::f().
namespaceDecl(isInline()) will match n::m.
+varDecl(isInline()) will match Foo;
</pre></td></tr>
@@ -5728,6 +5732,23 @@
</pre></td></tr>
+<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isInline2')"><a name="isInline2Anchor">isInline</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isInline2"><pre>Matches function and namespace declarations that are marked with
+the inline keyword.
+
+Given
+ inline void f();
+ void g();
+ namespace n {
+ inline namespace m {}
+ }
+ inline int Foo = 5;
+functionDecl(isInline()) will match ::f().
+namespaceDecl(isInline()) will match n::m.
+varDecl(isInline()) will match Foo;
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isStaticLocal0')"><a name="isStaticLocal0Anchor">isStaticLocal</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isStaticLocal0"><pre>Matches a static variable with local scope.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118900.405620.patch
Type: text/x-patch
Size: 3777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220203/0b9834dd/attachment.bin>
More information about the cfe-commits
mailing list