mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[clang] Make 'fileScopeAsmDecl' matcher public (#165319)
This PR makes the `fileScopeAsmDecl` matcher public.
This commit is contained in:
@@ -13,17 +13,10 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang::tidy::hicpp {
|
||||
|
||||
namespace {
|
||||
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
|
||||
const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
|
||||
FileScopeAsmDecl>
|
||||
fileScopeAsmDecl; // NOLINT(readability-identifier-*) preserve clang style
|
||||
} // namespace
|
||||
|
||||
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
|
||||
Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
|
||||
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);
|
||||
Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this);
|
||||
Finder->addMatcher(varDecl(hasAttr(attr::AsmLabel)).bind("asm-var"), this);
|
||||
}
|
||||
|
||||
void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
|
||||
@@ -825,6 +825,20 @@ fieldDecl()
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('fileScopeAsmDecl0')"><a name="fileScopeAsmDecl0Anchor">fileScopeAsmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FileScopeAsmDecl.html">FileScopeAsmDecl</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="fileScopeAsmDecl0"><pre>Matches top level asm declarations.
|
||||
|
||||
Given
|
||||
__asm("nop");
|
||||
void f() {
|
||||
__asm("mov al, 2");
|
||||
}
|
||||
fileScopeAsmDecl()
|
||||
matches '__asm("nop")',
|
||||
but not '__asm("mov al, 2")'.
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('friendDecl0')"><a name="friendDecl0Anchor">friendDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations.
|
||||
|
||||
|
||||
@@ -2478,6 +2478,21 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
|
||||
/// matches '__asm("mov al, 2")'
|
||||
extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
|
||||
|
||||
/// Matches top level asm declarations.
|
||||
///
|
||||
/// Given
|
||||
/// \code
|
||||
/// __asm("nop");
|
||||
/// void f() {
|
||||
/// __asm("mov al, 2");
|
||||
/// }
|
||||
/// \endcode
|
||||
/// fileScopeAsmDecl()
|
||||
/// matches '__asm("nop")',
|
||||
/// but not '__asm("mov al, 2")'.
|
||||
extern const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
|
||||
fileScopeAsmDecl;
|
||||
|
||||
/// Matches bool literals.
|
||||
///
|
||||
/// Example matches true
|
||||
|
||||
@@ -954,6 +954,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
|
||||
fileScopeAsmDecl;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
|
||||
cxxBoolLiteral;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral;
|
||||
|
||||
@@ -246,6 +246,7 @@ RegistryMaps::RegistryMaps() {
|
||||
REGISTER_MATCHER(expr);
|
||||
REGISTER_MATCHER(exprWithCleanups);
|
||||
REGISTER_MATCHER(fieldDecl);
|
||||
REGISTER_MATCHER(fileScopeAsmDecl);
|
||||
REGISTER_MATCHER(fixedPointLiteral);
|
||||
REGISTER_MATCHER(floatLiteral);
|
||||
REGISTER_MATCHER(forCallable);
|
||||
|
||||
@@ -1179,6 +1179,12 @@ TEST_P(ASTMatchersTest, PredefinedExpr) {
|
||||
has(stringLiteral()))));
|
||||
}
|
||||
|
||||
TEST_P(ASTMatchersTest, FileScopeAsmDecl) {
|
||||
EXPECT_TRUE(matches("__asm(\"nop\");", fileScopeAsmDecl()));
|
||||
EXPECT_TRUE(
|
||||
notMatches("void f() { __asm(\"mov al, 2\"); }", fileScopeAsmDecl()));
|
||||
}
|
||||
|
||||
TEST_P(ASTMatchersTest, AsmStatement) {
|
||||
EXPECT_TRUE(matches("void foo() { __asm(\"mov al, 2\"); }", asmStmt()));
|
||||
}
|
||||
@@ -2442,7 +2448,8 @@ TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
|
||||
"int main() {"
|
||||
" int a;"
|
||||
" f(a);"
|
||||
"}", matcher));
|
||||
"}",
|
||||
matcher));
|
||||
EXPECT_FALSE(matches("template <class ...T> void f(T &...args) {"
|
||||
" [...args = args] () mutable {"
|
||||
" }();"
|
||||
@@ -2450,7 +2457,8 @@ TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
|
||||
"int main() {"
|
||||
" int a;"
|
||||
" f(a);"
|
||||
"}", matcher));
|
||||
"}",
|
||||
matcher));
|
||||
}
|
||||
|
||||
TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
|
||||
@@ -2628,7 +2636,7 @@ TEST(ASTMatchersTestObjC, ObjCStringLiteral) {
|
||||
" [Test someFunction:@\"Ola!\"]; "
|
||||
"}\n"
|
||||
"@end ";
|
||||
EXPECT_TRUE(matchesObjC(Objc1String, objcStringLiteral()));
|
||||
EXPECT_TRUE(matchesObjC(Objc1String, objcStringLiteral()));
|
||||
}
|
||||
|
||||
TEST(ASTMatchersTestObjC, ObjCDecls) {
|
||||
|
||||
Reference in New Issue
Block a user