Coverage Report

Created: 2020-02-25 14:32

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