clang-tools 22.0.0git
Matchers.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Matchers.h"
10#include "ASTUtils.h"
11
13
15 const clang::ast_matchers::internal::BoundNodesMap &Nodes) const {
16 return !utils::areStatementsIdentical(Node.get<Stmt>(),
17 Nodes.getNodeAs<Stmt>(ID), *Context);
18}
19
21 llvm::ArrayRef<StringRef> NameList, bool CanonicalTypes)
22 : NameMatchers(NameList.begin(), NameList.end()),
23 CanonicalTypes(CanonicalTypes) {}
24
26
28 const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
29 ast_matchers::internal::BoundNodesTreeBuilder *Builder) const {
30
31 if (NameMatchers.empty())
32 return false;
33
34 PrintingPolicy PrintingPolicyWithSuppressedTag(
35 Finder->getASTContext().getLangOpts());
36 PrintingPolicyWithSuppressedTag.PrintAsCanonical = CanonicalTypes;
37 PrintingPolicyWithSuppressedTag.FullyQualifiedName = true;
38 PrintingPolicyWithSuppressedTag.SuppressScope = false;
39 PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
40 PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
41 std::string TypeName =
42 Node.getUnqualifiedType().getAsString(PrintingPolicyWithSuppressedTag);
43
44 return llvm::any_of(NameMatchers, [&TypeName](const llvm::Regex &NM) {
45 return NM.isValid() && NM.match(TypeName);
46 });
47}
48
49} // namespace clang::tidy::matchers
MatchesAnyListedTypeNameMatcher(llvm::ArrayRef< StringRef > NameList, bool CanonicalTypes)
Definition Matchers.cpp:20
bool matches(const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder, ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override
Definition Matchers.cpp:27
bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt *SecondStmt, const ASTContext &Context, bool Canonical)
Definition ASTUtils.cpp:91
bool operator()(const clang::ast_matchers::internal::BoundNodesMap &Nodes) const
Definition Matchers.cpp:14