[PATCH] D135690: [ASTMatchers] Add matcher for functions that are effectively inline
Trass3r via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 11 14:30:46 PDT 2022
Trass3r created this revision.
Trass3r added a reviewer: ziqingluo-90.
Herald added a project: All.
Trass3r updated this revision to Diff 466881.
Trass3r added a comment.
Trass3r updated this revision to Diff 466882.
Trass3r published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
fix test
Trass3r added a comment.
fix formatting
The existing isInline matcher only catches the ones explicitly marked inline.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135690
Files:
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/ASTMatchers/ASTMatchersMacros.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -306,6 +306,14 @@
varDecl(isInline(), hasName("Foo")), {Lang_CXX17}));
}
+TEST(IsInlineMatcher, IsEffectivelyInline) {
+ EXPECT_TRUE(matches("class X { void f() {} void g(); };",
+ functionDecl(isEffectivelyInline(), hasName("f"))));
+ EXPECT_TRUE(matches("constexpr int f() { return 0; }",
+ functionDecl(isEffectivelyInline(), hasName("f")),
+ {Lang_CXX11}));
+}
+
// FIXME: Figure out how to specify paths so the following tests pass on
// Windows.
#ifndef _WIN32
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -432,6 +432,7 @@
REGISTER_MATCHER(isInTemplateInstantiation);
REGISTER_MATCHER(isInitCapture);
REGISTER_MATCHER(isInline);
+ REGISTER_MATCHER(isEffectivelyInline);
REGISTER_MATCHER(isInstanceMessage);
REGISTER_MATCHER(isInstanceMethod);
REGISTER_MATCHER(isInstantiated);
Index: clang/include/clang/ASTMatchers/ASTMatchersMacros.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchersMacros.h
+++ clang/include/clang/ASTMatchers/ASTMatchersMacros.h
@@ -93,7 +93,7 @@
/// The code should return true if 'Node' matches.
#define AST_MATCHER(Type, DefineMatcher) \
namespace internal { \
- class matcher_##DefineMatcher##Matcher \
+ class matcher_##DefineMatcher##Matcher final \
: public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
public: \
explicit matcher_##DefineMatcher##Matcher() = default; \
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7777,6 +7777,19 @@
llvm_unreachable("Not a valid polymorphic type");
}
+/// Matches function declarations that are either marked with
+/// the inline keyword or are implicitly inline.
+///
+/// Given
+/// \code
+/// class A {
+/// void f() {}
+/// void g();
+/// };
+/// \endcode
+/// functionDecl(isEffectivelyInline()) will match f().
+AST_MATCHER(FunctionDecl, isEffectivelyInline) { return Node.isInlined(); }
+
/// Matches anonymous namespace declarations.
///
/// Given
Index: clang/docs/LibASTMatchersReference.html
===================================================================
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -4347,6 +4347,19 @@
</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('isEffectivelyInline0')"><a name="isEffectivelyInline0Anchor">isEffectivelyInline</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isEffectivelyInline0"><pre>Matches function declarations that are either marked with
+the inline keyword or are implicitly inline.
+
+Given
+ class A {
+ void f() {}
+ void g();
+ };
+functionDecl(isEffectivelyInline()) will match ::f().
+</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('isMain0')"><a name="isMain0Anchor">isMain</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isMain0"><pre>Determines whether the function is "main", which is the entry point
into an executable program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135690.466882.patch
Type: text/x-patch
Size: 4099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221011/99ad29d2/attachment-0001.bin>
More information about the cfe-commits
mailing list