Coverage Report

Created: 2022-05-17 06:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ASTMatchersInternal.cpp - Structural query framework ---------------===//
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
//  Implements the base layer of the matcher framework.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/ASTMatchers/ASTMatchersInternal.h"
14
#include "clang/AST/ASTContext.h"
15
#include "clang/AST/ASTTypeTraits.h"
16
#include "clang/AST/Decl.h"
17
#include "clang/AST/DeclTemplate.h"
18
#include "clang/AST/ParentMapContext.h"
19
#include "clang/AST/PrettyPrinter.h"
20
#include "clang/ASTMatchers/ASTMatchers.h"
21
#include "clang/Basic/LLVM.h"
22
#include "clang/Lex/Lexer.h"
23
#include "llvm/ADT/ArrayRef.h"
24
#include "llvm/ADT/IntrusiveRefCntPtr.h"
25
#include "llvm/ADT/None.h"
26
#include "llvm/ADT/SmallString.h"
27
#include "llvm/ADT/SmallVector.h"
28
#include "llvm/ADT/StringRef.h"
29
#include "llvm/Support/Casting.h"
30
#include "llvm/Support/ErrorHandling.h"
31
#include "llvm/Support/ManagedStatic.h"
32
#include "llvm/Support/Regex.h"
33
#include "llvm/Support/WithColor.h"
34
#include "llvm/Support/raw_ostream.h"
35
#include <algorithm>
36
#include <cassert>
37
#include <cstddef>
38
#include <string>
39
#include <utility>
40
#include <vector>
41
42
namespace clang {
43
namespace ast_matchers {
44
45
AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector<std::string>,
46
59
              Matches) {
47
59
  return llvm::is_contained(Matches, Node.getSelector().getAsString());
48
59
}
49
50
namespace internal {
51
52
static bool notUnaryOperator(const DynTypedNode &DynNode,
53
                             ASTMatchFinder *Finder,
54
                             BoundNodesTreeBuilder *Builder,
55
                             ArrayRef<DynTypedMatcher> InnerMatchers);
56
57
static bool allOfVariadicOperator(const DynTypedNode &DynNode,
58
                                  ASTMatchFinder *Finder,
59
                                  BoundNodesTreeBuilder *Builder,
60
                                  ArrayRef<DynTypedMatcher> InnerMatchers);
61
62
static bool eachOfVariadicOperator(const DynTypedNode &DynNode,
63
                                   ASTMatchFinder *Finder,
64
                                   BoundNodesTreeBuilder *Builder,
65
                                   ArrayRef<DynTypedMatcher> InnerMatchers);
66
67
static bool anyOfVariadicOperator(const DynTypedNode &DynNode,
68
                                  ASTMatchFinder *Finder,
69
                                  BoundNodesTreeBuilder *Builder,
70
                                  ArrayRef<DynTypedMatcher> InnerMatchers);
71
72
static bool optionallyVariadicOperator(const DynTypedNode &DynNode,
73
                                       ASTMatchFinder *Finder,
74
                                       BoundNodesTreeBuilder *Builder,
75
                                       ArrayRef<DynTypedMatcher> InnerMatchers);
76
77
bool matchesAnyBase(const CXXRecordDecl &Node,
78
                    const Matcher<CXXBaseSpecifier> &BaseSpecMatcher,
79
1.72k
                    ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) {
80
1.72k
  if (!Node.hasDefinition())
81
1.02k
    return false;
82
83
704
  CXXBasePaths Paths;
84
704
  Paths.setOrigin(&Node);
85
86
704
  const auto basePredicate =
87
704
      [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec,
88
704
                                          CXXBasePath &IgnoredParam) {
89
402
        BoundNodesTreeBuilder Result(*Builder);
90
402
        if (BaseSpecMatcher.matches(*BaseSpec, Finder, Builder)) {
91
182
          *Builder = std::move(Result);
92
182
          return true;
93
182
        }
94
220
        return false;
95
402
      };
96
97
704
  return Node.lookupInBases(basePredicate, Paths,
98
704
                            /*LookupInDependent =*/true);
99
1.72k
}
100
101
36.0k
void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) {
102
36.0k
  if (Bindings.empty())
103
21.2k
    Bindings.push_back(BoundNodesMap());
104
37.7k
  for (BoundNodesMap &Binding : Bindings) {
105
37.7k
    ResultVisitor->visitMatch(BoundNodes(Binding));
106
37.7k
  }
107
36.0k
}
108
109
namespace {
110
111
using VariadicOperatorFunction = bool (*)(
112
    const DynTypedNode &DynNode, ASTMatchFinder *Finder,
113
    BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers);
114
115
template <VariadicOperatorFunction Func>
116
class VariadicMatcher : public DynMatcherInterface {
117
public:
118
  VariadicMatcher(std::vector<DynTypedMatcher> InnerMatchers)
119
220k
      : InnerMatchers(std::move(InnerMatchers)) {}
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::VariadicMatcher(std::__1::vector<clang::ast_matchers::internal::DynTypedMatcher, std::__1::allocator<clang::ast_matchers::internal::DynTypedMatcher> >)
Line
Count
Source
119
85.9k
      : InnerMatchers(std::move(InnerMatchers)) {}
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::anyOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::VariadicMatcher(std::__1::vector<clang::ast_matchers::internal::DynTypedMatcher, std::__1::allocator<clang::ast_matchers::internal::DynTypedMatcher> >)
Line
Count
Source
119
99.6k
      : InnerMatchers(std::move(InnerMatchers)) {}
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::eachOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::VariadicMatcher(std::__1::vector<clang::ast_matchers::internal::DynTypedMatcher, std::__1::allocator<clang::ast_matchers::internal::DynTypedMatcher> >)
Line
Count
Source
119
2.70k
      : InnerMatchers(std::move(InnerMatchers)) {}
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::optionallyVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::VariadicMatcher(std::__1::vector<clang::ast_matchers::internal::DynTypedMatcher, std::__1::allocator<clang::ast_matchers::internal::DynTypedMatcher> >)
Line
Count
Source
119
229
      : InnerMatchers(std::move(InnerMatchers)) {}
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::notUnaryOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::VariadicMatcher(std::__1::vector<clang::ast_matchers::internal::DynTypedMatcher, std::__1::allocator<clang::ast_matchers::internal::DynTypedMatcher> >)
Line
Count
Source
119
31.5k
      : InnerMatchers(std::move(InnerMatchers)) {}
120
121
  bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
122
225k
                  BoundNodesTreeBuilder *Builder) const override {
123
225k
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
225k
  }
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const
Line
Count
Source
122
112k
                  BoundNodesTreeBuilder *Builder) const override {
123
112k
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
112k
  }
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::anyOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const
Line
Count
Source
122
99.3k
                  BoundNodesTreeBuilder *Builder) const override {
123
99.3k
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
99.3k
  }
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::eachOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const
Line
Count
Source
122
2.89k
                  BoundNodesTreeBuilder *Builder) const override {
123
2.89k
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
2.89k
  }
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::optionallyVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const
Line
Count
Source
122
268
                  BoundNodesTreeBuilder *Builder) const override {
123
268
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
268
  }
ASTMatchersInternal.cpp:clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&(clang::ast_matchers::internal::notUnaryOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>))>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const
Line
Count
Source
122
10.3k
                  BoundNodesTreeBuilder *Builder) const override {
123
10.3k
    return Func(DynNode, Finder, Builder, InnerMatchers);
124
10.3k
  }
125
126
private:
127
  std::vector<DynTypedMatcher> InnerMatchers;
128
};
129
130
class IdDynMatcher : public DynMatcherInterface {
131
public:
132
  IdDynMatcher(StringRef ID,
133
               IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher)
134
32.7k
      : ID(ID), InnerMatcher(std::move(InnerMatcher)) {}
135
136
  bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
137
111k
                  BoundNodesTreeBuilder *Builder) const override {
138
111k
    bool Result = InnerMatcher->dynMatches(DynNode, Finder, Builder);
139
111k
    if (Result) 
Builder->setBinding(ID, DynNode)21.2k
;
140
111k
    return Result;
141
111k
  }
142
143
269k
  llvm::Optional<clang::TraversalKind> TraversalKind() const override {
144
269k
    return InnerMatcher->TraversalKind();
145
269k
  }
146
147
private:
148
  const std::string ID;
149
  const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher;
150
};
151
152
/// A matcher that always returns true.
153
class TrueMatcherImpl : public DynMatcherInterface {
154
public:
155
241
  TrueMatcherImpl() = default;
156
157
  bool dynMatches(const DynTypedNode &, ASTMatchFinder *,
158
16.4k
                  BoundNodesTreeBuilder *) const override {
159
16.4k
    return true;
160
16.4k
  }
161
};
162
163
/// A matcher that specifies a particular \c TraversalKind.
164
///
165
/// The kind provided to the constructor overrides any kind that may be
166
/// specified by the `InnerMatcher`.
167
class DynTraversalMatcherImpl : public DynMatcherInterface {
168
public:
169
  explicit DynTraversalMatcherImpl(
170
      clang::TraversalKind TK,
171
      IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher)
172
2.98k
      : TK(TK), InnerMatcher(std::move(InnerMatcher)) {}
173
174
  bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
175
13.2k
                  BoundNodesTreeBuilder *Builder) const override {
176
13.2k
    return this->InnerMatcher->dynMatches(DynNode, Finder, Builder);
177
13.2k
  }
178
179
51.8k
  llvm::Optional<clang::TraversalKind> TraversalKind() const override {
180
51.8k
    return TK;
181
51.8k
  }
182
183
private:
184
  clang::TraversalKind TK;
185
  IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher;
186
};
187
188
} // namespace
189
190
2.07M
bool ASTMatchFinder::isTraversalIgnoringImplicitNodes() const {
191
2.07M
  return getASTContext().getParentMapContext().getTraversalKind() ==
192
2.07M
         TK_IgnoreUnlessSpelledInSource;
193
2.07M
}
194
195
DynTypedMatcher
196
DynTypedMatcher::constructVariadic(DynTypedMatcher::VariadicOperator Op,
197
                                   ASTNodeKind SupportedKind,
198
220k
                                   std::vector<DynTypedMatcher> InnerMatchers) {
199
220k
  assert(!InnerMatchers.empty() && "Array must not be empty.");
200
0
  assert(llvm::all_of(InnerMatchers,
201
220k
                      [SupportedKind](const DynTypedMatcher &M) {
202
220k
                        return M.canConvertTo(SupportedKind);
203
220k
                      }) &&
204
220k
         "InnerMatchers must be convertible to SupportedKind!");
205
206
  // We must relax the restrict kind here.
207
  // The different operators might deal differently with a mismatch.
208
  // Make it the same as SupportedKind, since that is the broadest type we are
209
  // allowed to accept.
210
0
  auto RestrictKind = SupportedKind;
211
212
220k
  switch (Op) {
213
85.9k
  case VO_AllOf:
214
    // In the case of allOf() we must pass all the checks, so making
215
    // RestrictKind the most restrictive can save us time. This way we reject
216
    // invalid types earlier and we can elide the kind checks inside the
217
    // matcher.
218
182k
    for (auto &IM : InnerMatchers) {
219
182k
      RestrictKind =
220
182k
          ASTNodeKind::getMostDerivedType(RestrictKind, IM.RestrictKind);
221
182k
    }
222
85.9k
    return DynTypedMatcher(
223
85.9k
        SupportedKind, RestrictKind,
224
85.9k
        new VariadicMatcher<allOfVariadicOperator>(std::move(InnerMatchers)));
225
226
99.6k
  case VO_AnyOf:
227
99.6k
    return DynTypedMatcher(
228
99.6k
        SupportedKind, RestrictKind,
229
99.6k
        new VariadicMatcher<anyOfVariadicOperator>(std::move(InnerMatchers)));
230
231
2.70k
  case VO_EachOf:
232
2.70k
    return DynTypedMatcher(
233
2.70k
        SupportedKind, RestrictKind,
234
2.70k
        new VariadicMatcher<eachOfVariadicOperator>(std::move(InnerMatchers)));
235
236
229
  case VO_Optionally:
237
229
    return DynTypedMatcher(SupportedKind, RestrictKind,
238
229
                           new VariadicMatcher<optionallyVariadicOperator>(
239
229
                               std::move(InnerMatchers)));
240
241
31.5k
  case VO_UnaryNot:
242
    // FIXME: Implement the Not operator to take a single matcher instead of a
243
    // vector.
244
31.5k
    return DynTypedMatcher(
245
31.5k
        SupportedKind, RestrictKind,
246
31.5k
        new VariadicMatcher<notUnaryOperator>(std::move(InnerMatchers)));
247
220k
  }
248
0
  llvm_unreachable("Invalid Op value.");
249
0
}
250
251
DynTypedMatcher
252
DynTypedMatcher::constructRestrictedWrapper(const DynTypedMatcher &InnerMatcher,
253
1.67k
                                            ASTNodeKind RestrictKind) {
254
1.67k
  DynTypedMatcher Copy = InnerMatcher;
255
1.67k
  Copy.RestrictKind = RestrictKind;
256
1.67k
  return Copy;
257
1.67k
}
258
259
2.98k
DynTypedMatcher DynTypedMatcher::withTraversalKind(TraversalKind TK) {
260
2.98k
  auto Copy = *this;
261
2.98k
  Copy.Implementation =
262
2.98k
      new DynTraversalMatcherImpl(TK, std::move(Copy.Implementation));
263
2.98k
  return Copy;
264
2.98k
}
265
266
38.0k
DynTypedMatcher DynTypedMatcher::trueMatcher(ASTNodeKind NodeKind) {
267
  // We only ever need one instance of TrueMatcherImpl, so we create a static
268
  // instance and reuse it to reduce the overhead of the matcher and increase
269
  // the chance of cache hits.
270
38.0k
  static const llvm::IntrusiveRefCntPtr<TrueMatcherImpl> Instance =
271
38.0k
      new TrueMatcherImpl();
272
38.0k
  return DynTypedMatcher(NodeKind, NodeKind, Instance);
273
38.0k
}
274
275
303k
bool DynTypedMatcher::canMatchNodesOfKind(ASTNodeKind Kind) const {
276
303k
  return RestrictKind.isBaseOf(Kind);
277
303k
}
278
279
1.00M
DynTypedMatcher DynTypedMatcher::dynCastTo(const ASTNodeKind Kind) const {
280
1.00M
  auto Copy = *this;
281
1.00M
  Copy.SupportedKind = Kind;
282
1.00M
  Copy.RestrictKind = ASTNodeKind::getMostDerivedType(Kind, RestrictKind);
283
1.00M
  return Copy;
284
1.00M
}
285
286
bool DynTypedMatcher::matches(const DynTypedNode &DynNode,
287
                              ASTMatchFinder *Finder,
288
865k
                              BoundNodesTreeBuilder *Builder) const {
289
865k
  TraversalKindScope RAII(Finder->getASTContext(),
290
865k
                          Implementation->TraversalKind());
291
292
865k
  if (Finder->isTraversalIgnoringImplicitNodes() &&
293
865k
      
Finder->IsMatchingInASTNodeNotSpelledInSource()56.0k
)
294
2.26k
    return false;
295
296
863k
  if (!Finder->isTraversalIgnoringImplicitNodes() &&
297
863k
      
Finder->IsMatchingInASTNodeNotAsIs()809k
)
298
173
    return false;
299
300
863k
  auto N =
301
863k
      Finder->getASTContext().getParentMapContext().traverseIgnored(DynNode);
302
303
863k
  if (RestrictKind.isBaseOf(N.getNodeKind()) &&
304
863k
      
Implementation->dynMatches(N, Finder, Builder)461k
) {
305
117k
    return true;
306
117k
  }
307
  // Delete all bindings when a matcher does not match.
308
  // This prevents unexpected exposure of bound nodes in unmatches
309
  // branches of the match tree.
310
745k
  Builder->removeBindings([](const BoundNodesMap &) 
{ return true; }32.0k
);
311
745k
  return false;
312
863k
}
313
314
bool DynTypedMatcher::matchesNoKindCheck(const DynTypedNode &DynNode,
315
                                         ASTMatchFinder *Finder,
316
152k
                                         BoundNodesTreeBuilder *Builder) const {
317
152k
  TraversalKindScope raii(Finder->getASTContext(),
318
152k
                          Implementation->TraversalKind());
319
320
152k
  if (Finder->isTraversalIgnoringImplicitNodes() &&
321
152k
      
Finder->IsMatchingInASTNodeNotSpelledInSource()4.42k
)
322
0
    return false;
323
324
152k
  if (!Finder->isTraversalIgnoringImplicitNodes() &&
325
152k
      
Finder->IsMatchingInASTNodeNotAsIs()147k
)
326
0
    return false;
327
328
152k
  auto N =
329
152k
      Finder->getASTContext().getParentMapContext().traverseIgnored(DynNode);
330
331
152k
  assert(RestrictKind.isBaseOf(N.getNodeKind()));
332
152k
  if (Implementation->dynMatches(N, Finder, Builder)) {
333
55.3k
    return true;
334
55.3k
  }
335
  // Delete all bindings when a matcher does not match.
336
  // This prevents unexpected exposure of bound nodes in unmatches
337
  // branches of the match tree.
338
96.8k
  Builder->removeBindings([](const BoundNodesMap &) 
{ return true; }572
);
339
96.8k
  return false;
340
152k
}
341
342
32.7k
llvm::Optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const {
343
32.7k
  if (!AllowBind) 
return llvm::None0
;
344
32.7k
  auto Result = *this;
345
32.7k
  Result.Implementation =
346
32.7k
      new IdDynMatcher(ID, std::move(Result.Implementation));
347
32.7k
  return std::move(Result);
348
32.7k
}
349
350
531k
bool DynTypedMatcher::canConvertTo(ASTNodeKind To) const {
351
531k
  const auto From = getSupportedKind();
352
531k
  auto QualKind = ASTNodeKind::getFromNodeKind<QualType>();
353
531k
  auto TypeKind = ASTNodeKind::getFromNodeKind<Type>();
354
  /// Mimic the implicit conversions of Matcher<>.
355
  /// - From Matcher<Type> to Matcher<QualType>
356
531k
  if (From.isSame(TypeKind) && 
To.isSame(QualKind)2.17k
)
return true1.44k
;
357
  /// - From Matcher<Base> to Matcher<Derived>
358
530k
  return From.isBaseOf(To);
359
531k
}
360
361
7.91k
void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder &Other) {
362
7.91k
  Bindings.append(Other.Bindings.begin(), Other.Bindings.end());
363
7.91k
}
364
365
static bool notUnaryOperator(const DynTypedNode &DynNode,
366
                             ASTMatchFinder *Finder,
367
                             BoundNodesTreeBuilder *Builder,
368
10.3k
                             ArrayRef<DynTypedMatcher> InnerMatchers) {
369
10.3k
  if (InnerMatchers.size() != 1)
370
0
    return false;
371
372
  // The 'unless' matcher will always discard the result:
373
  // If the inner matcher doesn't match, unless returns true,
374
  // but the inner matcher cannot have bound anything.
375
  // If the inner matcher matches, the result is false, and
376
  // any possible binding will be discarded.
377
  // We still need to hand in all the bound nodes up to this
378
  // point so the inner matcher can depend on bound nodes,
379
  // and we need to actively discard the bound nodes, otherwise
380
  // the inner matcher will reset the bound nodes if it doesn't
381
  // match, but this would be inversed by 'unless'.
382
10.3k
  BoundNodesTreeBuilder Discard(*Builder);
383
10.3k
  return !InnerMatchers[0].matches(DynNode, Finder, &Discard);
384
10.3k
}
385
386
static bool allOfVariadicOperator(const DynTypedNode &DynNode,
387
                                  ASTMatchFinder *Finder,
388
                                  BoundNodesTreeBuilder *Builder,
389
112k
                                  ArrayRef<DynTypedMatcher> InnerMatchers) {
390
  // allOf leads to one matcher for each alternative in the first
391
  // matcher combined with each alternative in the second matcher.
392
  // Thus, we can reuse the same Builder.
393
152k
  return llvm::all_of(InnerMatchers, [&](const DynTypedMatcher &InnerMatcher) {
394
152k
    return InnerMatcher.matchesNoKindCheck(DynNode, Finder, Builder);
395
152k
  });
396
112k
}
397
398
static bool eachOfVariadicOperator(const DynTypedNode &DynNode,
399
                                   ASTMatchFinder *Finder,
400
                                   BoundNodesTreeBuilder *Builder,
401
2.89k
                                   ArrayRef<DynTypedMatcher> InnerMatchers) {
402
2.89k
  BoundNodesTreeBuilder Result;
403
2.89k
  bool Matched = false;
404
5.78k
  for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
405
5.78k
    BoundNodesTreeBuilder BuilderInner(*Builder);
406
5.78k
    if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) {
407
1.02k
      Matched = true;
408
1.02k
      Result.addMatch(BuilderInner);
409
1.02k
    }
410
5.78k
  }
411
2.89k
  *Builder = std::move(Result);
412
2.89k
  return Matched;
413
2.89k
}
414
415
static bool anyOfVariadicOperator(const DynTypedNode &DynNode,
416
                                  ASTMatchFinder *Finder,
417
                                  BoundNodesTreeBuilder *Builder,
418
99.3k
                                  ArrayRef<DynTypedMatcher> InnerMatchers) {
419
347k
  for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
420
347k
    BoundNodesTreeBuilder Result = *Builder;
421
347k
    if (InnerMatcher.matches(DynNode, Finder, &Result)) {
422
14.8k
      *Builder = std::move(Result);
423
14.8k
      return true;
424
14.8k
    }
425
347k
  }
426
84.5k
  return false;
427
99.3k
}
428
429
static bool
430
optionallyVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
431
                           BoundNodesTreeBuilder *Builder,
432
268
                           ArrayRef<DynTypedMatcher> InnerMatchers) {
433
268
  if (InnerMatchers.size() != 1)
434
0
    return false;
435
436
268
  BoundNodesTreeBuilder Result(*Builder);
437
268
  if (InnerMatchers[0].matches(DynNode, Finder, &Result))
438
46
    *Builder = std::move(Result);
439
268
  return true;
440
268
}
441
442
inline static
443
1.99k
std::vector<std::string> vectorFromRefs(ArrayRef<const StringRef *> NameRefs) {
444
1.99k
  std::vector<std::string> Names;
445
1.99k
  Names.reserve(NameRefs.size());
446
1.99k
  for (auto *Name : NameRefs)
447
12.5k
    Names.emplace_back(*Name);
448
1.99k
  return Names;
449
1.99k
}
450
451
1.66k
Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs) {
452
1.66k
  return internal::Matcher<NamedDecl>(
453
1.66k
      new internal::HasNameMatcher(vectorFromRefs(NameRefs)));
454
1.66k
}
455
456
Matcher<ObjCMessageExpr> hasAnySelectorFunc(
457
271
    ArrayRef<const StringRef *> NameRefs) {
458
271
  return hasAnySelectorMatcher(vectorFromRefs(NameRefs));
459
271
}
460
461
50
HasOpNameMatcher hasAnyOperatorNameFunc(ArrayRef<const StringRef *> NameRefs) {
462
50
  return HasOpNameMatcher(vectorFromRefs(NameRefs));
463
50
}
464
465
HasOverloadOpNameMatcher
466
10
hasAnyOverloadedOperatorNameFunc(ArrayRef<const StringRef *> NameRefs) {
467
10
  return HasOverloadOpNameMatcher(vectorFromRefs(NameRefs));
468
10
}
469
470
HasNameMatcher::HasNameMatcher(std::vector<std::string> N)
471
    : UseUnqualifiedMatch(
472
44.6k
          llvm::all_of(N, [](StringRef Name) { return !Name.contains("::"); })),
473
43.8k
      Names(std::move(N)) {
474
43.8k
#ifndef NDEBUG
475
43.8k
  for (StringRef Name : Names)
476
47.1k
    assert(!Name.empty());
477
43.8k
#endif
478
43.8k
}
479
480
370k
static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) {
481
370k
  StringRef Name = FullName;
482
370k
  if (!Name.endswith(Suffix))
483
247k
    return false;
484
123k
  Name = Name.drop_back(Suffix.size());
485
123k
  if (!Name.empty()) {
486
12.6k
    if (!Name.endswith("::"))
487
390
      return false;
488
12.2k
    Name = Name.drop_back(2);
489
12.2k
  }
490
122k
  FullName = Name;
491
122k
  return true;
492
123k
}
493
494
static StringRef getNodeName(const NamedDecl &Node,
495
354k
                             llvm::SmallString<128> &Scratch) {
496
  // Simple name.
497
354k
  if (Node.getIdentifier())
498
305k
    return Node.getName();
499
500
48.4k
  if (Node.getDeclName()) {
501
    // Name needs to be constructed.
502
35.3k
    Scratch.clear();
503
35.3k
    llvm::raw_svector_ostream OS(Scratch);
504
35.3k
    Node.printName(OS);
505
35.3k
    return OS.str();
506
35.3k
  }
507
508
13.1k
  return "(anonymous)";
509
48.4k
}
510
511
static StringRef getNodeName(const RecordDecl &Node,
512
2.14k
                             llvm::SmallString<128> &Scratch) {
513
2.14k
  if (Node.getIdentifier()) {
514
1.90k
    return Node.getName();
515
1.90k
  }
516
240
  Scratch.clear();
517
240
  return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch);
518
2.14k
}
519
520
static StringRef getNodeName(const NamespaceDecl &Node,
521
7.36k
                             llvm::SmallString<128> &Scratch) {
522
7.36k
  return Node.isAnonymousNamespace() ? 
"(anonymous namespace)"160
:
Node.getName()7.20k
;
523
7.36k
}
524
525
namespace {
526
527
class PatternSet {
528
public:
529
188k
  PatternSet(ArrayRef<std::string> Names) {
530
188k
    Patterns.reserve(Names.size());
531
188k
    for (StringRef Name : Names)
532
194k
      Patterns.push_back({Name, Name.startswith("::")});
533
188k
  }
534
535
  /// Consumes the name suffix from each pattern in the set and removes the ones
536
  /// that didn't match.
537
  /// Return true if there are still any patterns left.
538
198k
  bool consumeNameSuffix(StringRef NodeName, bool CanSkip) {
539
402k
    for (size_t I = 0; I < Patterns.size();) {
540
204k
      if (::clang::ast_matchers::internal::consumeNameSuffix(Patterns[I].P,
541
204k
                                                             NodeName) ||
542
204k
          
CanSkip134k
) {
543
69.9k
        ++I;
544
134k
      } else {
545
134k
        Patterns.erase(Patterns.begin() + I);
546
134k
      }
547
204k
    }
548
198k
    return !Patterns.empty();
549
198k
  }
550
551
  /// Check if any of the patterns are a match.
552
  /// A match will be a pattern that was fully consumed, that also matches the
553
  /// 'fully qualified' requirement.
554
69.2k
  bool foundMatch(bool AllowFullyQualified) const {
555
69.9k
    return llvm::any_of(Patterns, [&](const Pattern &Pattern) {
556
69.9k
      return Pattern.P.empty() &&
557
69.9k
             
(60.0k
AllowFullyQualified60.0k
||
!Pattern.IsFullyQualified20.3k
);
558
69.9k
    });
559
69.2k
  }
560
561
private:
562
  struct Pattern {
563
    StringRef P;
564
    bool IsFullyQualified;
565
  };
566
567
  llvm::SmallVector<Pattern, 8> Patterns;
568
};
569
570
} // namespace
571
572
165k
bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const {
573
165k
  assert(UseUnqualifiedMatch);
574
0
  llvm::SmallString<128> Scratch;
575
165k
  StringRef NodeName = getNodeName(Node, Scratch);
576
166k
  return llvm::any_of(Names, [&](StringRef Name) {
577
166k
    return consumeNameSuffix(Name, NodeName) && 
Name.empty()52.8k
;
578
166k
  });
579
165k
}
580
581
188k
bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const {
582
188k
  PatternSet Patterns(Names);
583
188k
  llvm::SmallString<128> Scratch;
584
585
  // This function is copied and adapted from NamedDecl::printQualifiedName()
586
  // By matching each part individually we optimize in a couple of ways:
587
  //  - We can exit early on the first failure.
588
  //  - We can skip inline/anonymous namespaces without another pass.
589
  //  - We print one name at a time, reducing the chance of overflowing the
590
  //    inlined space of the SmallString.
591
592
  // First, match the name.
593
188k
  if (!Patterns.consumeNameSuffix(getNodeName(Node, Scratch),
594
188k
                                  /*CanSkip=*/false))
595
126k
    return false;
596
597
  // Try to match each declaration context.
598
  // We are allowed to skip anonymous and inline namespaces if they don't match.
599
62.1k
  const DeclContext *Ctx = Node.getDeclContext();
600
601
62.1k
  if (Ctx->isFunctionOrMethod())
602
5.29k
    return Patterns.foundMatch(/*AllowFullyQualified=*/false);
603
604
64.2k
  
for (; 56.8k
Ctx;
Ctx = Ctx->getParent()7.37k
) {
605
    // Linkage Spec can just be ignored
606
    // FIXME: Any other DeclContext kinds that can be safely disregarded
607
64.2k
    if (isa<LinkageSpecDecl>(Ctx))
608
336
      continue;
609
63.9k
    if (!isa<NamedDecl>(Ctx))
610
39.8k
      break;
611
24.0k
    if (Patterns.foundMatch(/*AllowFullyQualified=*/false))
612
14.1k
      return true;
613
614
9.94k
    if (const auto *ND = dyn_cast<NamespaceDecl>(Ctx)) {
615
      // If it matches (or we can skip it), continue.
616
7.36k
      if (Patterns.consumeNameSuffix(getNodeName(*ND, Scratch),
617
7.36k
                                     /*CanSkip=*/ND->isAnonymousNamespace() ||
618
7.36k
                                         
ND->isInline()7.20k
))
619
5.82k
        continue;
620
1.54k
      return false;
621
7.36k
    }
622
2.58k
    if (const auto *RD = dyn_cast<RecordDecl>(Ctx)) {
623
2.46k
      if (!isa<ClassTemplateSpecializationDecl>(Ctx)) {
624
2.14k
        if (Patterns.consumeNameSuffix(getNodeName(*RD, Scratch),
625
2.14k
                                       /*CanSkip=*/false))
626
1.21k
          continue;
627
628
926
        return false;
629
2.14k
      }
630
2.46k
    }
631
632
    // We don't know how to deal with this DeclContext.
633
    // Fallback to the slow version of the code.
634
440
    return matchesNodeFullSlow(Node);
635
2.58k
  }
636
637
39.8k
  return Patterns.foundMatch(/*AllowFullyQualified=*/true);
638
56.8k
}
639
640
94.7k
bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
641
94.7k
  const bool SkipUnwrittenCases[] = {false, true};
642
159k
  for (bool SkipUnwritten : SkipUnwrittenCases) {
643
159k
    llvm::SmallString<128> NodeName = StringRef("::");
644
159k
    llvm::raw_svector_ostream OS(NodeName);
645
646
159k
    PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
647
159k
    Policy.SuppressUnwrittenScope = SkipUnwritten;
648
159k
    Policy.SuppressInlineNamespace = SkipUnwritten;
649
159k
    Node.printQualifiedName(OS, Policy);
650
651
159k
    const StringRef FullName = OS.str();
652
653
164k
    for (const StringRef Pattern : Names) {
654
164k
      if (Pattern.startswith("::")) {
655
6.45k
        if (FullName == Pattern)
656
954
          return true;
657
158k
      } else if (FullName.endswith(Pattern) &&
658
158k
                 
FullName.drop_back(Pattern.size()).endswith("::")29.2k
) {
659
28.8k
        return true;
660
28.8k
      }
661
164k
    }
662
159k
  }
663
664
64.9k
  return false;
665
94.7k
}
666
667
94.3k
bool HasNameMatcher::matchesNode(const NamedDecl &Node) const {
668
94.3k
  assert(matchesNodeFullFast(Node) == matchesNodeFullSlow(Node));
669
94.3k
  if (UseUnqualifiedMatch) {
670
82.9k
    assert(matchesNodeUnqualified(Node) == matchesNodeFullFast(Node));
671
0
    return matchesNodeUnqualified(Node);
672
82.9k
  }
673
11.4k
  return matchesNodeFullFast(Node);
674
94.3k
}
675
676
// Checks whether \p Loc points to a token with source text of \p TokenText.
677
static bool isTokenAtLoc(const SourceManager &SM, const LangOptions &LangOpts,
678
1.11k
                         StringRef Text, SourceLocation Loc) {
679
1.11k
  llvm::SmallString<16> Buffer;
680
1.11k
  bool Invalid = false;
681
  // Since `Loc` may point into an expansion buffer, which has no corresponding
682
  // source, we need to look at the spelling location to read the actual source.
683
1.11k
  StringRef TokenText = Lexer::getSpelling(SM.getSpellingLoc(Loc), Buffer, SM,
684
1.11k
                                           LangOpts, &Invalid);
685
1.11k
  return !Invalid && Text == TokenText;
686
1.11k
}
687
688
llvm::Optional<SourceLocation>
689
getExpansionLocOfMacro(StringRef MacroName, SourceLocation Loc,
690
1.02k
                       const ASTContext &Context) {
691
1.02k
  auto &SM = Context.getSourceManager();
692
1.02k
  const LangOptions &LangOpts = Context.getLangOpts();
693
1.49k
  while (Loc.isMacroID()) {
694
1.25k
    SrcMgr::ExpansionInfo Expansion =
695
1.25k
        SM.getSLocEntry(SM.getFileID(Loc)).getExpansion();
696
1.25k
    if (Expansion.isMacroArgExpansion())
697
      // Check macro argument for an expansion of the given macro. For example,
698
      // `F(G(3))`, where `MacroName` is `G`.
699
278
      if (llvm::Optional<SourceLocation> ArgLoc = getExpansionLocOfMacro(
700
278
              MacroName, Expansion.getSpellingLoc(), Context))
701
144
        return ArgLoc;
702
1.11k
    Loc = Expansion.getExpansionLocStart();
703
1.11k
    if (isTokenAtLoc(SM, LangOpts, MacroName, Loc))
704
648
      return Loc;
705
1.11k
  }
706
232
  return llvm::None;
707
1.02k
}
708
709
std::shared_ptr<llvm::Regex> createAndVerifyRegex(StringRef Regex,
710
                                                  llvm::Regex::RegexFlags Flags,
711
381
                                                  StringRef MatcherID) {
712
381
  assert(!Regex.empty() && "Empty regex string");
713
0
  auto SharedRegex = std::make_shared<llvm::Regex>(Regex, Flags);
714
381
  std::string Error;
715
381
  if (!SharedRegex->isValid(Error)) {
716
1
    llvm::WithColor::error()
717
1
        << "building matcher '" << MatcherID << "': " << Error << "\n";
718
1
    llvm::WithColor::note() << " input was '" << Regex << "'\n";
719
1
  }
720
381
  return SharedRegex;
721
381
}
722
} // end namespace internal
723
724
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAutoreleasePoolStmt>
725
    autoreleasePoolStmt;
726
const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl>
727
    translationUnitDecl;
728
const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl;
729
const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
730
    typedefNameDecl;
731
const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl;
732
const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl>
733
    typeAliasTemplateDecl;
734
const internal::VariadicAllOfMatcher<Decl> decl;
735
const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl> decompositionDecl;
736
const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl> bindingDecl;
737
const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
738
    linkageSpecDecl;
739
const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl;
740
const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl;
741
const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl;
742
const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
743
    namespaceAliasDecl;
744
const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl;
745
const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl;
746
const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl>
747
    classTemplateDecl;
748
const internal::VariadicDynCastAllOfMatcher<Decl,
749
                                            ClassTemplateSpecializationDecl>
750
    classTemplateSpecializationDecl;
751
const internal::VariadicDynCastAllOfMatcher<
752
    Decl, ClassTemplatePartialSpecializationDecl>
753
    classTemplatePartialSpecializationDecl;
754
const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl>
755
    declaratorDecl;
756
const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl;
757
const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl>
758
    accessSpecDecl;
759
const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier;
760
const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer;
761
const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument;
762
const internal::VariadicAllOfMatcher<TemplateArgumentLoc> templateArgumentLoc;
763
const internal::VariadicAllOfMatcher<TemplateName> templateName;
764
const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl>
765
    nonTypeTemplateParmDecl;
766
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
767
    templateTypeParmDecl;
768
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl>
769
    templateTemplateParmDecl;
770
771
const internal::VariadicAllOfMatcher<LambdaCapture> lambdaCapture;
772
const internal::VariadicAllOfMatcher<QualType> qualType;
773
const internal::VariadicAllOfMatcher<Type> type;
774
const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
775
776
const internal::VariadicDynCastAllOfMatcher<TypeLoc, QualifiedTypeLoc>
777
    qualifiedTypeLoc;
778
const internal::VariadicDynCastAllOfMatcher<TypeLoc, PointerTypeLoc>
779
    pointerTypeLoc;
780
const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc>
781
    referenceTypeLoc;
782
const internal::VariadicDynCastAllOfMatcher<TypeLoc,
783
                                            TemplateSpecializationTypeLoc>
784
    templateSpecializationTypeLoc;
785
const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
786
    elaboratedTypeLoc;
787
788
const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr>
789
    unaryExprOrTypeTraitExpr;
790
const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
791
const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl>
792
    cxxConstructorDecl;
793
const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl>
794
    cxxDestructorDecl;
795
const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl;
796
const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl>
797
    enumConstantDecl;
798
const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl;
799
const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl;
800
const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
801
    cxxConversionDecl;
802
const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl;
803
const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl;
804
const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl>
805
    indirectFieldDecl;
806
const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl;
807
const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl>
808
    functionTemplateDecl;
809
const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl;
810
const internal::VariadicAllOfMatcher<Stmt> stmt;
811
const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt;
812
const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr;
813
const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr>
814
    unresolvedMemberExpr;
815
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDependentScopeMemberExpr>
816
    cxxDependentScopeMemberExpr;
817
const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr;
818
const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr;
819
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr>
820
    cxxMemberCallExpr;
821
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
822
    objcMessageExpr;
823
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl>
824
    objcInterfaceDecl;
825
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl>
826
    objcImplementationDecl;
827
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl>
828
    objcProtocolDecl;
829
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl>
830
    objcCategoryDecl;
831
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl>
832
    objcCategoryImplDecl;
833
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl>
834
    objcMethodDecl;
835
const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl>
836
    blockDecl;
837
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl;
838
const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl>
839
    objcPropertyDecl;
840
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt>
841
    objcThrowStmt;
842
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt;
843
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt>
844
    objcCatchStmt;
845
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt>
846
    objcFinallyStmt;
847
const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
848
    exprWithCleanups;
849
const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr;
850
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr>
851
    cxxStdInitializerListExpr;
852
const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr>
853
    implicitValueInitExpr;
854
const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr;
855
const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr>
856
    substNonTypeTemplateParmExpr;
857
const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl;
858
const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl> usingEnumDecl;
859
const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
860
    usingDirectiveDecl;
861
const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
862
    unresolvedLookupExpr;
863
const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl>
864
    unresolvedUsingValueDecl;
865
const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl>
866
    unresolvedUsingTypenameDecl;
867
const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> constantExpr;
868
const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr;
869
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr>
870
    cxxConstructExpr;
871
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr>
872
    cxxUnresolvedConstructExpr;
873
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr;
874
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr>
875
    cxxBindTemporaryExpr;
876
const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr>
877
    materializeTemporaryExpr;
878
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
879
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr;
880
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
881
    cxxNoexceptExpr;
882
const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
883
    arraySubscriptExpr;
884
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
885
    cxxDefaultArgExpr;
886
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
887
    cxxOperatorCallExpr;
888
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXRewrittenBinaryOperator>
889
    cxxRewrittenBinaryOperator;
890
const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr;
891
const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr;
892
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr;
893
const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
894
const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt;
895
const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt;
896
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
897
    cxxForRangeStmt;
898
const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt;
899
const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt;
900
const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt;
901
const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt;
902
const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt> coreturnStmt;
903
const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt;
904
const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt;
905
const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt;
906
const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr;
907
const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt;
908
const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase;
909
const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt;
910
const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt;
911
const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt;
912
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt;
913
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
914
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr;
915
const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
916
const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
917
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
918
    cxxBoolLiteral;
919
const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral;
920
const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
921
    characterLiteral;
922
const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
923
    integerLiteral;
924
const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral;
925
const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral;
926
const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
927
    fixedPointLiteral;
928
const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
929
    userDefinedLiteral;
930
const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>
931
    compoundLiteralExpr;
932
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
933
    cxxNullPtrLiteralExpr;
934
const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr;
935
const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr>
936
    coawaitExpr;
937
const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr>
938
    dependentCoawaitExpr;
939
const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr>
940
    coyieldExpr;
941
const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr;
942
const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
943
    genericSelectionExpr;
944
const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr;
945
const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr;
946
const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
947
    binaryOperator;
948
const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr,
949
                                CXXRewrittenBinaryOperator>
950
    binaryOperation;
951
const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation;
952
const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator;
953
const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator>
954
    conditionalOperator;
955
const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator>
956
    binaryConditionalOperator;
957
const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr>
958
    opaqueValueExpr;
959
const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl>
960
    staticAssertDecl;
961
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr>
962
    cxxReinterpretCastExpr;
963
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr>
964
    cxxStaticCastExpr;
965
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
966
    cxxDynamicCastExpr;
967
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
968
    cxxConstCastExpr;
969
const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
970
    cStyleCastExpr;
971
const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>
972
    explicitCastExpr;
973
const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr>
974
    implicitCastExpr;
975
const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr;
976
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr>
977
    cxxFunctionalCastExpr;
978
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr>
979
    cxxTemporaryObjectExpr;
980
const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr>
981
    predefinedExpr;
982
const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
983
    designatedInitExpr;
984
const internal::VariadicOperatorMatcherFunc<
985
    2, std::numeric_limits<unsigned>::max()>
986
    eachOf = {internal::DynTypedMatcher::VO_EachOf};
987
const internal::VariadicOperatorMatcherFunc<
988
    2, std::numeric_limits<unsigned>::max()>
989
    anyOf = {internal::DynTypedMatcher::VO_AnyOf};
990
const internal::VariadicOperatorMatcherFunc<
991
    2, std::numeric_limits<unsigned>::max()>
992
    allOf = {internal::DynTypedMatcher::VO_AllOf};
993
const internal::VariadicOperatorMatcherFunc<1, 1> optionally = {
994
    internal::DynTypedMatcher::VO_Optionally};
995
const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
996
                                 internal::hasAnyNameFunc>
997
    hasAnyName = {};
998
999
const internal::VariadicFunction<internal::HasOpNameMatcher, StringRef,
1000
                                 internal::hasAnyOperatorNameFunc>
1001
    hasAnyOperatorName = {};
1002
const internal::VariadicFunction<internal::HasOverloadOpNameMatcher, StringRef,
1003
                                 internal::hasAnyOverloadedOperatorNameFunc>
1004
    hasAnyOverloadedOperatorName = {};
1005
const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, StringRef,
1006
                                 internal::hasAnySelectorFunc>
1007
    hasAnySelector = {};
1008
const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {};
1009
const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher>
1010
    hasDescendant = {};
1011
const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach =
1012
    {};
1013
const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher>
1014
    forEachDescendant = {};
1015
const internal::ArgumentAdaptingMatcherFunc<
1016
    internal::HasParentMatcher,
1017
    internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
1018
    internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
1019
    hasParent = {};
1020
const internal::ArgumentAdaptingMatcherFunc<
1021
    internal::HasAncestorMatcher,
1022
    internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
1023
    internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
1024
    hasAncestor = {};
1025
const internal::VariadicOperatorMatcherFunc<1, 1> unless = {
1026
    internal::DynTypedMatcher::VO_UnaryNot};
1027
const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier;
1028
const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc>
1029
    nestedNameSpecifierLoc;
1030
const internal::VariadicAllOfMatcher<Attr> attr;
1031
const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
1032
    cudaKernelCallExpr;
1033
const AstTypeMatcher<BuiltinType> builtinType;
1034
const AstTypeMatcher<ArrayType> arrayType;
1035
const AstTypeMatcher<ComplexType> complexType;
1036
const AstTypeMatcher<ConstantArrayType> constantArrayType;
1037
const AstTypeMatcher<DeducedTemplateSpecializationType>
1038
    deducedTemplateSpecializationType;
1039
const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType;
1040
const AstTypeMatcher<IncompleteArrayType> incompleteArrayType;
1041
const AstTypeMatcher<VariableArrayType> variableArrayType;
1042
const AstTypeMatcher<AtomicType> atomicType;
1043
const AstTypeMatcher<AutoType> autoType;
1044
const AstTypeMatcher<DecltypeType> decltypeType;
1045
const AstTypeMatcher<FunctionType> functionType;
1046
const AstTypeMatcher<FunctionProtoType> functionProtoType;
1047
const AstTypeMatcher<ParenType> parenType;
1048
const AstTypeMatcher<BlockPointerType> blockPointerType;
1049
const AstTypeMatcher<MemberPointerType> memberPointerType;
1050
const AstTypeMatcher<PointerType> pointerType;
1051
const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType;
1052
const AstTypeMatcher<ReferenceType> referenceType;
1053
const AstTypeMatcher<LValueReferenceType> lValueReferenceType;
1054
const AstTypeMatcher<RValueReferenceType> rValueReferenceType;
1055
const AstTypeMatcher<TypedefType> typedefType;
1056
const AstTypeMatcher<EnumType> enumType;
1057
const AstTypeMatcher<TemplateSpecializationType> templateSpecializationType;
1058
const AstTypeMatcher<UnaryTransformType> unaryTransformType;
1059
const AstTypeMatcher<RecordType> recordType;
1060
const AstTypeMatcher<TagType> tagType;
1061
const AstTypeMatcher<ElaboratedType> elaboratedType;
1062
const AstTypeMatcher<UsingType> usingType;
1063
const AstTypeMatcher<SubstTemplateTypeParmType> substTemplateTypeParmType;
1064
const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType;
1065
const AstTypeMatcher<InjectedClassNameType> injectedClassNameType;
1066
const AstTypeMatcher<DecayedType> decayedType;
1067
AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType,
1068
                                 AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,
1069
                                                                 ComplexType));
1070
AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasValueType,
1071
                                 AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType));
1072
AST_TYPELOC_TRAVERSE_MATCHER_DEF(
1073
    pointee,
1074
    AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,
1075
                                    PointerType, ReferenceType));
1076
1077
const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
1078
    ompExecutableDirective;
1079
const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause>
1080
    ompDefaultClause;
1081
const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
1082
    cxxDeductionGuideDecl;
1083
1084
} // end namespace ast_matchers
1085
} // end namespace clang