Coverage Report

Created: 2021-01-19 06:58

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