Coverage Report

Created: 2020-09-19 12:23

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