Bug Summary

File:clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
Warning:line 198, column 34
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name DurationFactoryScaleCheck.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/clang/tools/extra/clang-tidy/abseil -I /build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang-tools-extra/clang-tidy/abseil -I tools/clang/tools/extra/clang-tidy -I /build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang/include -I tools/clang/include -I include -I /build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-01-19-134126-35450-1 -x c++ /build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp

/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp

1//===--- DurationFactoryScaleCheck.cpp - clang-tidy -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DurationFactoryScaleCheck.h"
10#include "DurationRewriter.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/Tooling/FixIt.h"
14
15using namespace clang::ast_matchers;
16
17namespace clang {
18namespace tidy {
19namespace abseil {
20
21// Given the name of a duration factory function, return the appropriate
22// `DurationScale` for that factory. If no factory can be found for
23// `FactoryName`, return `None`.
24static llvm::Optional<DurationScale>
25getScaleForFactory(llvm::StringRef FactoryName) {
26 return llvm::StringSwitch<llvm::Optional<DurationScale>>(FactoryName)
27 .Case("Nanoseconds", DurationScale::Nanoseconds)
28 .Case("Microseconds", DurationScale::Microseconds)
29 .Case("Milliseconds", DurationScale::Milliseconds)
30 .Case("Seconds", DurationScale::Seconds)
31 .Case("Minutes", DurationScale::Minutes)
32 .Case("Hours", DurationScale::Hours)
33 .Default(llvm::None);
34}
35
36// Given either an integer or float literal, return its value.
37// One and only one of `IntLit` and `FloatLit` should be provided.
38static double getValue(const IntegerLiteral *IntLit,
39 const FloatingLiteral *FloatLit) {
40 if (IntLit)
41 return IntLit->getValue().getLimitedValue();
42
43 assert(FloatLit != nullptr && "Neither IntLit nor FloatLit set")(static_cast <bool> (FloatLit != nullptr && "Neither IntLit nor FloatLit set"
) ? void (0) : __assert_fail ("FloatLit != nullptr && \"Neither IntLit nor FloatLit set\""
, "clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp"
, 43, __extension__ __PRETTY_FUNCTION__))
;
44 return FloatLit->getValueAsApproximateDouble();
45}
46
47// Given the scale of a duration and a `Multiplier`, determine if `Multiplier`
48// would produce a new scale. If so, return a tuple containing the new scale
49// and a suitable Multiplier for that scale, otherwise `None`.
50static llvm::Optional<std::tuple<DurationScale, double>>
51getNewScaleSingleStep(DurationScale OldScale, double Multiplier) {
52 switch (OldScale) {
53 case DurationScale::Hours:
54 if (Multiplier <= 1.0 / 60.0)
55 return std::make_tuple(DurationScale::Minutes, Multiplier * 60.0);
56 break;
57
58 case DurationScale::Minutes:
59 if (Multiplier >= 60.0)
60 return std::make_tuple(DurationScale::Hours, Multiplier / 60.0);
61 if (Multiplier <= 1.0 / 60.0)
62 return std::make_tuple(DurationScale::Seconds, Multiplier * 60.0);
63 break;
64
65 case DurationScale::Seconds:
66 if (Multiplier >= 60.0)
67 return std::make_tuple(DurationScale::Minutes, Multiplier / 60.0);
68 if (Multiplier <= 1e-3)
69 return std::make_tuple(DurationScale::Milliseconds, Multiplier * 1e3);
70 break;
71
72 case DurationScale::Milliseconds:
73 if (Multiplier >= 1e3)
74 return std::make_tuple(DurationScale::Seconds, Multiplier / 1e3);
75 if (Multiplier <= 1e-3)
76 return std::make_tuple(DurationScale::Microseconds, Multiplier * 1e3);
77 break;
78
79 case DurationScale::Microseconds:
80 if (Multiplier >= 1e3)
81 return std::make_tuple(DurationScale::Milliseconds, Multiplier / 1e3);
82 if (Multiplier <= 1e-3)
83 return std::make_tuple(DurationScale::Nanoseconds, Multiplier * 1e-3);
84 break;
85
86 case DurationScale::Nanoseconds:
87 if (Multiplier >= 1e3)
88 return std::make_tuple(DurationScale::Microseconds, Multiplier / 1e3);
89 break;
90 }
91
92 return llvm::None;
93}
94
95// Given the scale of a duration and a `Multiplier`, determine if `Multiplier`
96// would produce a new scale. If so, return it, otherwise `None`.
97static llvm::Optional<DurationScale> getNewScale(DurationScale OldScale,
98 double Multiplier) {
99 while (Multiplier != 1.0) {
100 llvm::Optional<std::tuple<DurationScale, double>> Result =
101 getNewScaleSingleStep(OldScale, Multiplier);
102 if (!Result)
103 break;
104 if (std::get<1>(*Result) == 1.0)
105 return std::get<0>(*Result);
106 Multiplier = std::get<1>(*Result);
107 OldScale = std::get<0>(*Result);
108 }
109
110 return llvm::None;
111}
112
113void DurationFactoryScaleCheck::registerMatchers(MatchFinder *Finder) {
114 Finder->addMatcher(
115 callExpr(
116 callee(functionDecl(DurationFactoryFunction()).bind("call_decl")),
117 hasArgument(
118 0,
119 ignoringImpCasts(anyOf(
120 cxxFunctionalCastExpr(
121 hasDestinationType(
122 anyOf(isInteger(), realFloatingPointType())),
123 hasSourceExpression(initListExpr())),
124 integerLiteral(equals(0)), floatLiteral(equals(0.0)),
125 binaryOperator(hasOperatorName("*"),
126 hasEitherOperand(ignoringImpCasts(
127 anyOf(integerLiteral(), floatLiteral()))))
128 .bind("mult_binop"),
129 binaryOperator(hasOperatorName("/"), hasRHS(floatLiteral()))
130 .bind("div_binop")))))
131 .bind("call"),
132 this);
133}
134
135void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
136 const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call");
137
138 // Don't try to replace things inside of macro definitions.
139 if (Call->getExprLoc().isMacroID())
1
Calling 'SourceLocation::isMacroID'
4
Returning from 'SourceLocation::isMacroID'
5
Taking false branch
140 return;
141
142 const Expr *Arg = Call->getArg(0)->IgnoreParenImpCasts();
143 // Arguments which are macros are ignored.
144 if (Arg->getBeginLoc().isMacroID())
6
Calling 'SourceLocation::isMacroID'
9
Returning from 'SourceLocation::isMacroID'
10
Taking false branch
145 return;
146
147 // We first handle the cases of literal zero (both float and integer).
148 if (isLiteralZero(Result, *Arg)) {
11
Assuming the condition is false
12
Taking false branch
149 diag(Call->getBeginLoc(),
150 "use ZeroDuration() for zero-length time intervals")
151 << FixItHint::CreateReplacement(Call->getSourceRange(),
152 "absl::ZeroDuration()");
153 return;
154 }
155
156 const auto *CallDecl = Result.Nodes.getNodeAs<FunctionDecl>("call_decl");
157 llvm::Optional<DurationScale> MaybeScale =
158 getScaleForFactory(CallDecl->getName());
159 if (!MaybeScale)
13
Calling 'Optional::operator bool'
21
Returning from 'Optional::operator bool'
22
Taking false branch
160 return;
161
162 DurationScale Scale = *MaybeScale;
163 const Expr *Remainder;
164 llvm::Optional<DurationScale> NewScale;
165
166 // We next handle the cases of multiplication and division.
167 if (const auto *MultBinOp
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
33.1
'MultBinOp' is null
=
34
Taking false branch
168 Result.Nodes.getNodeAs<BinaryOperator>("mult_binop")) {
23
Calling 'BoundNodes::getNodeAs'
33
Returning from 'BoundNodes::getNodeAs'
169 // For multiplication, we need to look at both operands, and consider the
170 // cases where a user is multiplying by something such as 1e-3.
171
172 // First check the LHS
173 const auto *IntLit = llvm::dyn_cast<IntegerLiteral>(MultBinOp->getLHS());
174 const auto *FloatLit = llvm::dyn_cast<FloatingLiteral>(MultBinOp->getLHS());
175 if (IntLit || FloatLit) {
176 NewScale = getNewScale(Scale, getValue(IntLit, FloatLit));
177 if (NewScale)
178 Remainder = MultBinOp->getRHS();
179 }
180
181 // If we weren't able to scale based on the LHS, check the RHS
182 if (!NewScale) {
183 IntLit = llvm::dyn_cast<IntegerLiteral>(MultBinOp->getRHS());
184 FloatLit = llvm::dyn_cast<FloatingLiteral>(MultBinOp->getRHS());
185 if (IntLit || FloatLit) {
186 NewScale = getNewScale(Scale, getValue(IntLit, FloatLit));
187 if (NewScale)
188 Remainder = MultBinOp->getLHS();
189 }
190 }
191 } else if (const auto *DivBinOp
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
53.1
'DivBinOp' is non-null
=
54
Taking true branch
192 Result.Nodes.getNodeAs<BinaryOperator>("div_binop")) {
35
Calling 'BoundNodes::getNodeAs'
53
Returning from 'BoundNodes::getNodeAs'
193 // We next handle division.
194 // For division, we only check the RHS.
195 const auto *FloatLit = llvm::dyn_cast<FloatingLiteral>(DivBinOp->getRHS());
55
Assuming the object is not a 'FloatingLiteral'
56
'FloatLit' initialized to a null pointer value
196
197 llvm::Optional<DurationScale> NewScale =
198 getNewScale(Scale, 1.0 / FloatLit->getValueAsApproximateDouble());
57
Called C++ object pointer is null
199 if (NewScale) {
200 const Expr *Remainder = DivBinOp->getLHS();
201
202 // We've found an appropriate scaling factor and the new scale, so output
203 // the relevant fix.
204 diag(Call->getBeginLoc(), "internal duration scaling can be removed")
205 << FixItHint::CreateReplacement(
206 Call->getSourceRange(),
207 (llvm::Twine(getDurationFactoryForScale(*NewScale)) + "(" +
208 tooling::fixit::getText(*Remainder, *Result.Context) + ")")
209 .str());
210 }
211 }
212
213 if (NewScale) {
214 assert(Remainder && "No remainder found")(static_cast <bool> (Remainder && "No remainder found"
) ? void (0) : __assert_fail ("Remainder && \"No remainder found\""
, "clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp"
, 214, __extension__ __PRETTY_FUNCTION__))
;
215 // We've found an appropriate scaling factor and the new scale, so output
216 // the relevant fix.
217 diag(Call->getBeginLoc(), "internal duration scaling can be removed")
218 << FixItHint::CreateReplacement(
219 Call->getSourceRange(),
220 (llvm::Twine(getDurationFactoryForScale(*NewScale)) + "(" +
221 tooling::fixit::getText(*Remainder, *Result.Context) + ")")
222 .str());
223 }
224}
225
226} // namespace abseil
227} // namespace tidy
228} // namespace clang

/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang/include/clang/Basic/SourceLocation.h

1//===- SourceLocation.h - Compact identifier for Source Files ---*- C++ -*-===//
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/// \file
10/// Defines the clang::SourceLocation class and associated facilities.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_BASIC_SOURCELOCATION_H
15#define LLVM_CLANG_BASIC_SOURCELOCATION_H
16
17#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/StringRef.h"
19#include <cassert>
20#include <cstdint>
21#include <string>
22#include <utility>
23
24namespace llvm {
25
26class FoldingSetNodeID;
27template <typename T> struct FoldingSetTrait;
28
29} // namespace llvm
30
31namespace clang {
32
33class SourceManager;
34
35/// An opaque identifier used by SourceManager which refers to a
36/// source file (MemoryBuffer) along with its \#include path and \#line data.
37///
38class FileID {
39 /// A mostly-opaque identifier, where 0 is "invalid", >0 is
40 /// this module, and <-1 is something loaded from another module.
41 int ID = 0;
42
43public:
44 bool isValid() const { return ID != 0; }
45 bool isInvalid() const { return ID == 0; }
46
47 bool operator==(const FileID &RHS) const { return ID == RHS.ID; }
48 bool operator<(const FileID &RHS) const { return ID < RHS.ID; }
49 bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; }
50 bool operator!=(const FileID &RHS) const { return !(*this == RHS); }
51 bool operator>(const FileID &RHS) const { return RHS < *this; }
52 bool operator>=(const FileID &RHS) const { return RHS <= *this; }
53
54 static FileID getSentinel() { return get(-1); }
55 unsigned getHashValue() const { return static_cast<unsigned>(ID); }
56
57private:
58 friend class ASTWriter;
59 friend class ASTReader;
60 friend class SourceManager;
61
62 static FileID get(int V) {
63 FileID F;
64 F.ID = V;
65 return F;
66 }
67
68 int getOpaqueValue() const { return ID; }
69};
70
71/// Encodes a location in the source. The SourceManager can decode this
72/// to get at the full include stack, line and column information.
73///
74/// Technically, a source location is simply an offset into the manager's view
75/// of the input source, which is all input buffers (including macro
76/// expansions) concatenated in an effectively arbitrary order. The manager
77/// actually maintains two blocks of input buffers. One, starting at offset
78/// 0 and growing upwards, contains all buffers from this module. The other,
79/// starting at the highest possible offset and growing downwards, contains
80/// buffers of loaded modules.
81///
82/// In addition, one bit of SourceLocation is used for quick access to the
83/// information whether the location is in a file or a macro expansion.
84///
85/// It is important that this type remains small. It is currently 32 bits wide.
86class SourceLocation {
87 friend class ASTReader;
88 friend class ASTWriter;
89 friend class SourceManager;
90 friend struct llvm::FoldingSetTrait<SourceLocation>;
91
92public:
93 using UIntTy = uint32_t;
94 using IntTy = int32_t;
95
96private:
97 UIntTy ID = 0;
98
99 enum : UIntTy { MacroIDBit = 1ULL << (8 * sizeof(UIntTy) - 1) };
100
101public:
102 bool isFileID() const { return (ID & MacroIDBit) == 0; }
103 bool isMacroID() const { return (ID & MacroIDBit) != 0; }
2
Assuming the condition is false
3
Returning zero, which participates in a condition later
7
Assuming the condition is false
8
Returning zero, which participates in a condition later
104
105 /// Return true if this is a valid SourceLocation object.
106 ///
107 /// Invalid SourceLocations are often used when events have no corresponding
108 /// location in the source (e.g. a diagnostic is required for a command line
109 /// option).
110 bool isValid() const { return ID != 0; }
111 bool isInvalid() const { return ID == 0; }
112
113private:
114 /// Return the offset into the manager's global input view.
115 UIntTy getOffset() const { return ID & ~MacroIDBit; }
116
117 static SourceLocation getFileLoc(UIntTy ID) {
118 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!")(static_cast <bool> ((ID & MacroIDBit) == 0 &&
"Ran out of source locations!") ? void (0) : __assert_fail (
"(ID & MacroIDBit) == 0 && \"Ran out of source locations!\""
, "clang/include/clang/Basic/SourceLocation.h", 118, __extension__
__PRETTY_FUNCTION__))
;
119 SourceLocation L;
120 L.ID = ID;
121 return L;
122 }
123
124 static SourceLocation getMacroLoc(UIntTy ID) {
125 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!")(static_cast <bool> ((ID & MacroIDBit) == 0 &&
"Ran out of source locations!") ? void (0) : __assert_fail (
"(ID & MacroIDBit) == 0 && \"Ran out of source locations!\""
, "clang/include/clang/Basic/SourceLocation.h", 125, __extension__
__PRETTY_FUNCTION__))
;
126 SourceLocation L;
127 L.ID = MacroIDBit | ID;
128 return L;
129 }
130
131public:
132 /// Return a source location with the specified offset from this
133 /// SourceLocation.
134 SourceLocation getLocWithOffset(IntTy Offset) const {
135 assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow")(static_cast <bool> (((getOffset()+Offset) & MacroIDBit
) == 0 && "offset overflow") ? void (0) : __assert_fail
("((getOffset()+Offset) & MacroIDBit) == 0 && \"offset overflow\""
, "clang/include/clang/Basic/SourceLocation.h", 135, __extension__
__PRETTY_FUNCTION__))
;
136 SourceLocation L;
137 L.ID = ID+Offset;
138 return L;
139 }
140
141 /// When a SourceLocation itself cannot be used, this returns
142 /// an (opaque) 32-bit integer encoding for it.
143 ///
144 /// This should only be passed to SourceLocation::getFromRawEncoding, it
145 /// should not be inspected directly.
146 UIntTy getRawEncoding() const { return ID; }
147
148 /// Turn a raw encoding of a SourceLocation object into
149 /// a real SourceLocation.
150 ///
151 /// \see getRawEncoding.
152 static SourceLocation getFromRawEncoding(UIntTy Encoding) {
153 SourceLocation X;
154 X.ID = Encoding;
155 return X;
156 }
157
158 /// When a SourceLocation itself cannot be used, this returns
159 /// an (opaque) pointer encoding for it.
160 ///
161 /// This should only be passed to SourceLocation::getFromPtrEncoding, it
162 /// should not be inspected directly.
163 void* getPtrEncoding() const {
164 // Double cast to avoid a warning "cast to pointer from integer of different
165 // size".
166 return (void*)(uintptr_t)getRawEncoding();
167 }
168
169 /// Turn a pointer encoding of a SourceLocation object back
170 /// into a real SourceLocation.
171 static SourceLocation getFromPtrEncoding(const void *Encoding) {
172 return getFromRawEncoding((SourceLocation::UIntTy)(uintptr_t)Encoding);
173 }
174
175 static bool isPairOfFileLocations(SourceLocation Start, SourceLocation End) {
176 return Start.isValid() && Start.isFileID() && End.isValid() &&
177 End.isFileID();
178 }
179
180 unsigned getHashValue() const;
181 void print(raw_ostream &OS, const SourceManager &SM) const;
182 std::string printToString(const SourceManager &SM) const;
183 void dump(const SourceManager &SM) const;
184};
185
186inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
187 return LHS.getRawEncoding() == RHS.getRawEncoding();
188}
189
190inline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) {
191 return !(LHS == RHS);
192}
193
194// Ordering is meaningful only if LHS and RHS have the same FileID!
195// Otherwise use SourceManager::isBeforeInTranslationUnit().
196inline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) {
197 return LHS.getRawEncoding() < RHS.getRawEncoding();
198}
199inline bool operator>(const SourceLocation &LHS, const SourceLocation &RHS) {
200 return LHS.getRawEncoding() > RHS.getRawEncoding();
201}
202inline bool operator<=(const SourceLocation &LHS, const SourceLocation &RHS) {
203 return LHS.getRawEncoding() <= RHS.getRawEncoding();
204}
205inline bool operator>=(const SourceLocation &LHS, const SourceLocation &RHS) {
206 return LHS.getRawEncoding() >= RHS.getRawEncoding();
207}
208
209/// A trivial tuple used to represent a source range.
210class SourceRange {
211 SourceLocation B;
212 SourceLocation E;
213
214public:
215 SourceRange() = default;
216 SourceRange(SourceLocation loc) : B(loc), E(loc) {}
217 SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
218
219 SourceLocation getBegin() const { return B; }
220 SourceLocation getEnd() const { return E; }
221
222 void setBegin(SourceLocation b) { B = b; }
223 void setEnd(SourceLocation e) { E = e; }
224
225 bool isValid() const { return B.isValid() && E.isValid(); }
226 bool isInvalid() const { return !isValid(); }
227
228 bool operator==(const SourceRange &X) const {
229 return B == X.B && E == X.E;
230 }
231
232 bool operator!=(const SourceRange &X) const {
233 return B != X.B || E != X.E;
234 }
235
236 // Returns true iff other is wholly contained within this range.
237 bool fullyContains(const SourceRange &other) const {
238 return B <= other.B && E >= other.E;
239 }
240
241 void print(raw_ostream &OS, const SourceManager &SM) const;
242 std::string printToString(const SourceManager &SM) const;
243 void dump(const SourceManager &SM) const;
244};
245
246/// Represents a character-granular source range.
247///
248/// The underlying SourceRange can either specify the starting/ending character
249/// of the range, or it can specify the start of the range and the start of the
250/// last token of the range (a "token range"). In the token range case, the
251/// size of the last token must be measured to determine the actual end of the
252/// range.
253class CharSourceRange {
254 SourceRange Range;
255 bool IsTokenRange = false;
256
257public:
258 CharSourceRange() = default;
259 CharSourceRange(SourceRange R, bool ITR) : Range(R), IsTokenRange(ITR) {}
260
261 static CharSourceRange getTokenRange(SourceRange R) {
262 return CharSourceRange(R, true);
263 }
264
265 static CharSourceRange getCharRange(SourceRange R) {
266 return CharSourceRange(R, false);
267 }
268
269 static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
270 return getTokenRange(SourceRange(B, E));
271 }
272
273 static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
274 return getCharRange(SourceRange(B, E));
275 }
276
277 /// Return true if the end of this range specifies the start of
278 /// the last token. Return false if the end of this range specifies the last
279 /// character in the range.
280 bool isTokenRange() const { return IsTokenRange; }
281 bool isCharRange() const { return !IsTokenRange; }
282
283 SourceLocation getBegin() const { return Range.getBegin(); }
284 SourceLocation getEnd() const { return Range.getEnd(); }
285 SourceRange getAsRange() const { return Range; }
286
287 void setBegin(SourceLocation b) { Range.setBegin(b); }
288 void setEnd(SourceLocation e) { Range.setEnd(e); }
289 void setTokenRange(bool TR) { IsTokenRange = TR; }
290
291 bool isValid() const { return Range.isValid(); }
292 bool isInvalid() const { return !isValid(); }
293};
294
295/// Represents an unpacked "presumed" location which can be presented
296/// to the user.
297///
298/// A 'presumed' location can be modified by \#line and GNU line marker
299/// directives and is always the expansion point of a normal location.
300///
301/// You can get a PresumedLoc from a SourceLocation with SourceManager.
302class PresumedLoc {
303 const char *Filename = nullptr;
304 FileID ID;
305 unsigned Line, Col;
306 SourceLocation IncludeLoc;
307
308public:
309 PresumedLoc() = default;
310 PresumedLoc(const char *FN, FileID FID, unsigned Ln, unsigned Co,
311 SourceLocation IL)
312 : Filename(FN), ID(FID), Line(Ln), Col(Co), IncludeLoc(IL) {}
313
314 /// Return true if this object is invalid or uninitialized.
315 ///
316 /// This occurs when created with invalid source locations or when walking
317 /// off the top of a \#include stack.
318 bool isInvalid() const { return Filename == nullptr; }
319 bool isValid() const { return Filename != nullptr; }
320
321 /// Return the presumed filename of this location.
322 ///
323 /// This can be affected by \#line etc.
324 const char *getFilename() const {
325 assert(isValid())(static_cast <bool> (isValid()) ? void (0) : __assert_fail
("isValid()", "clang/include/clang/Basic/SourceLocation.h", 325
, __extension__ __PRETTY_FUNCTION__))
;
326 return Filename;
327 }
328
329 FileID getFileID() const {
330 assert(isValid())(static_cast <bool> (isValid()) ? void (0) : __assert_fail
("isValid()", "clang/include/clang/Basic/SourceLocation.h", 330
, __extension__ __PRETTY_FUNCTION__))
;
331 return ID;
332 }
333
334 /// Return the presumed line number of this location.
335 ///
336 /// This can be affected by \#line etc.
337 unsigned getLine() const {
338 assert(isValid())(static_cast <bool> (isValid()) ? void (0) : __assert_fail
("isValid()", "clang/include/clang/Basic/SourceLocation.h", 338
, __extension__ __PRETTY_FUNCTION__))
;
339 return Line;
340 }
341
342 /// Return the presumed column number of this location.
343 ///
344 /// This cannot be affected by \#line, but is packaged here for convenience.
345 unsigned getColumn() const {
346 assert(isValid())(static_cast <bool> (isValid()) ? void (0) : __assert_fail
("isValid()", "clang/include/clang/Basic/SourceLocation.h", 346
, __extension__ __PRETTY_FUNCTION__))
;
347 return Col;
348 }
349
350 /// Return the presumed include location of this location.
351 ///
352 /// This can be affected by GNU linemarker directives.
353 SourceLocation getIncludeLoc() const {
354 assert(isValid())(static_cast <bool> (isValid()) ? void (0) : __assert_fail
("isValid()", "clang/include/clang/Basic/SourceLocation.h", 354
, __extension__ __PRETTY_FUNCTION__))
;
355 return IncludeLoc;
356 }
357};
358
359class FileEntry;
360
361/// A SourceLocation and its associated SourceManager.
362///
363/// This is useful for argument passing to functions that expect both objects.
364///
365/// This class does not guarantee the presence of either the SourceManager or
366/// a valid SourceLocation. Clients should use `isValid()` and `hasManager()`
367/// before calling the member functions.
368class FullSourceLoc : public SourceLocation {
369 const SourceManager *SrcMgr = nullptr;
370
371public:
372 /// Creates a FullSourceLoc where isValid() returns \c false.
373 FullSourceLoc() = default;
374
375 explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
376 : SourceLocation(Loc), SrcMgr(&SM) {}
377
378 /// Checks whether the SourceManager is present.
379 bool hasManager() const { return SrcMgr != nullptr; }
380
381 /// \pre hasManager()
382 const SourceManager &getManager() const {
383 assert(SrcMgr && "SourceManager is NULL.")(static_cast <bool> (SrcMgr && "SourceManager is NULL."
) ? void (0) : __assert_fail ("SrcMgr && \"SourceManager is NULL.\""
, "clang/include/clang/Basic/SourceLocation.h", 383, __extension__
__PRETTY_FUNCTION__))
;
384 return *SrcMgr;
385 }
386
387 FileID getFileID() const;
388
389 FullSourceLoc getExpansionLoc() const;
390 FullSourceLoc getSpellingLoc() const;
391 FullSourceLoc getFileLoc() const;
392 PresumedLoc getPresumedLoc(bool UseLineDirectives = true) const;
393 bool isMacroArgExpansion(FullSourceLoc *StartLoc = nullptr) const;
394 FullSourceLoc getImmediateMacroCallerLoc() const;
395 std::pair<FullSourceLoc, StringRef> getModuleImportLoc() const;
396 unsigned getFileOffset() const;
397
398 unsigned getExpansionLineNumber(bool *Invalid = nullptr) const;
399 unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const;
400
401 unsigned getSpellingLineNumber(bool *Invalid = nullptr) const;
402 unsigned getSpellingColumnNumber(bool *Invalid = nullptr) const;
403
404 const char *getCharacterData(bool *Invalid = nullptr) const;
405
406 unsigned getLineNumber(bool *Invalid = nullptr) const;
407 unsigned getColumnNumber(bool *Invalid = nullptr) const;
408
409 const FileEntry *getFileEntry() const;
410
411 /// Return a StringRef to the source buffer data for the
412 /// specified FileID.
413 StringRef getBufferData(bool *Invalid = nullptr) const;
414
415 /// Decompose the specified location into a raw FileID + Offset pair.
416 ///
417 /// The first element is the FileID, the second is the offset from the
418 /// start of the buffer of the location.
419 std::pair<FileID, unsigned> getDecomposedLoc() const;
420
421 bool isInSystemHeader() const;
422
423 /// Determines the order of 2 source locations in the translation unit.
424 ///
425 /// \returns true if this source location comes before 'Loc', false otherwise.
426 bool isBeforeInTranslationUnitThan(SourceLocation Loc) const;
427
428 /// Determines the order of 2 source locations in the translation unit.
429 ///
430 /// \returns true if this source location comes before 'Loc', false otherwise.
431 bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const {
432 assert(Loc.isValid())(static_cast <bool> (Loc.isValid()) ? void (0) : __assert_fail
("Loc.isValid()", "clang/include/clang/Basic/SourceLocation.h"
, 432, __extension__ __PRETTY_FUNCTION__))
;
433 assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!")(static_cast <bool> (SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!"
) ? void (0) : __assert_fail ("SrcMgr == Loc.SrcMgr && \"Loc comes from another SourceManager!\""
, "clang/include/clang/Basic/SourceLocation.h", 433, __extension__
__PRETTY_FUNCTION__))
;
434 return isBeforeInTranslationUnitThan((SourceLocation)Loc);
435 }
436
437 /// Comparison function class, useful for sorting FullSourceLocs.
438 struct BeforeThanCompare {
439 bool operator()(const FullSourceLoc& lhs, const FullSourceLoc& rhs) const {
440 return lhs.isBeforeInTranslationUnitThan(rhs);
441 }
442 };
443
444 /// Prints information about this FullSourceLoc to stderr.
445 ///
446 /// This is useful for debugging.
447 void dump() const;
448
449 friend bool
450 operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
451 return LHS.getRawEncoding() == RHS.getRawEncoding() &&
452 LHS.SrcMgr == RHS.SrcMgr;
453 }
454
455 friend bool
456 operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
457 return !(LHS == RHS);
458 }
459};
460
461} // namespace clang
462
463namespace llvm {
464
465 /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
466 /// DenseSets.
467 template <>
468 struct DenseMapInfo<clang::FileID, void> {
469 static clang::FileID getEmptyKey() {
470 return {};
471 }
472
473 static clang::FileID getTombstoneKey() {
474 return clang::FileID::getSentinel();
475 }
476
477 static unsigned getHashValue(clang::FileID S) {
478 return S.getHashValue();
479 }
480
481 static bool isEqual(clang::FileID LHS, clang::FileID RHS) {
482 return LHS == RHS;
483 }
484 };
485
486 /// Define DenseMapInfo so that SourceLocation's can be used as keys in
487 /// DenseMap and DenseSet. This trait class is eqivalent to
488 /// DenseMapInfo<unsigned> which uses SourceLocation::ID is used as a key.
489 template <> struct DenseMapInfo<clang::SourceLocation, void> {
490 static clang::SourceLocation getEmptyKey() {
491 constexpr clang::SourceLocation::UIntTy Zero = 0;
492 return clang::SourceLocation::getFromRawEncoding(~Zero);
493 }
494
495 static clang::SourceLocation getTombstoneKey() {
496 constexpr clang::SourceLocation::UIntTy Zero = 0;
497 return clang::SourceLocation::getFromRawEncoding(~Zero - 1);
498 }
499
500 static unsigned getHashValue(clang::SourceLocation Loc) {
501 return Loc.getHashValue();
502 }
503
504 static bool isEqual(clang::SourceLocation LHS, clang::SourceLocation RHS) {
505 return LHS == RHS;
506 }
507 };
508
509 // Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
510 template <> struct FoldingSetTrait<clang::SourceLocation> {
511 static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
512 };
513
514} // namespace llvm
515
516#endif // LLVM_CLANG_BASIC_SOURCELOCATION_H

/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/llvm/include/llvm/ADT/Optional.h

1//===- Optional.h - Simple variant for passing optional values --*- C++ -*-===//
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// This file provides Optional, a template class modeled in the spirit of
10// OCaml's 'opt' variant. The idea is to strongly type whether or not
11// a value can be optional.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ADT_OPTIONAL_H
16#define LLVM_ADT_OPTIONAL_H
17
18#include "llvm/ADT/Hashing.h"
19#include "llvm/ADT/None.h"
20#include "llvm/ADT/STLForwardCompat.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/Support/type_traits.h"
23#include <cassert>
24#include <memory>
25#include <new>
26#include <utility>
27
28namespace llvm {
29
30class raw_ostream;
31
32namespace optional_detail {
33
34/// Storage for any type.
35//
36// The specialization condition intentionally uses
37// llvm::is_trivially_{copy/move}_constructible instead of
38// std::is_trivially_{copy/move}_constructible. GCC versions prior to 7.4 may
39// instantiate the copy/move constructor of `T` when
40// std::is_trivially_{copy/move}_constructible is instantiated. This causes
41// compilation to fail if we query the trivially copy/move constructible
42// property of a class which is not copy/move constructible.
43//
44// The current implementation of OptionalStorage insists that in order to use
45// the trivial specialization, the value_type must be trivially copy
46// constructible and trivially copy assignable due to =default implementations
47// of the copy/move constructor/assignment. It does not follow that this is
48// necessarily the case std::is_trivially_copyable is true (hence the expanded
49// specialization condition).
50//
51// The move constructible / assignable conditions emulate the remaining behavior
52// of std::is_trivially_copyable.
53template <typename T,
54 bool = (llvm::is_trivially_copy_constructible<T>::value &&
55 std::is_trivially_copy_assignable<T>::value &&
56 (llvm::is_trivially_move_constructible<T>::value ||
57 !std::is_move_constructible<T>::value) &&
58 (std::is_trivially_move_assignable<T>::value ||
59 !std::is_move_assignable<T>::value))>
60class OptionalStorage {
61 union {
62 char empty;
63 T value;
64 };
65 bool hasVal;
66
67public:
68 ~OptionalStorage() { reset(); }
69
70 constexpr OptionalStorage() noexcept : empty(), hasVal(false) {}
71
72 constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() {
73 if (other.hasValue()) {
74 emplace(other.value);
75 }
76 }
77 constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() {
78 if (other.hasValue()) {
79 emplace(std::move(other.value));
80 }
81 }
82
83 template <class... Args>
84 constexpr explicit OptionalStorage(in_place_t, Args &&... args)
85 : value(std::forward<Args>(args)...), hasVal(true) {}
86
87 void reset() noexcept {
88 if (hasVal) {
89 value.~T();
90 hasVal = false;
91 }
92 }
93
94 constexpr bool hasValue() const noexcept { return hasVal; }
95
96 T &getValue() LLVM_LVALUE_FUNCTION& noexcept {
97 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 97, __extension__
__PRETTY_FUNCTION__))
;
98 return value;
99 }
100 constexpr T const &getValue() const LLVM_LVALUE_FUNCTION& noexcept {
101 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 101, __extension__
__PRETTY_FUNCTION__))
;
102 return value;
103 }
104#if LLVM_HAS_RVALUE_REFERENCE_THIS1
105 T &&getValue() && noexcept {
106 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 106, __extension__
__PRETTY_FUNCTION__))
;
107 return std::move(value);
108 }
109#endif
110
111 template <class... Args> void emplace(Args &&... args) {
112 reset();
113 ::new ((void *)std::addressof(value)) T(std::forward<Args>(args)...);
114 hasVal = true;
115 }
116
117 OptionalStorage &operator=(T const &y) {
118 if (hasValue()) {
119 value = y;
120 } else {
121 ::new ((void *)std::addressof(value)) T(y);
122 hasVal = true;
123 }
124 return *this;
125 }
126 OptionalStorage &operator=(T &&y) {
127 if (hasValue()) {
128 value = std::move(y);
129 } else {
130 ::new ((void *)std::addressof(value)) T(std::move(y));
131 hasVal = true;
132 }
133 return *this;
134 }
135
136 OptionalStorage &operator=(OptionalStorage const &other) {
137 if (other.hasValue()) {
138 if (hasValue()) {
139 value = other.value;
140 } else {
141 ::new ((void *)std::addressof(value)) T(other.value);
142 hasVal = true;
143 }
144 } else {
145 reset();
146 }
147 return *this;
148 }
149
150 OptionalStorage &operator=(OptionalStorage &&other) {
151 if (other.hasValue()) {
152 if (hasValue()) {
153 value = std::move(other.value);
154 } else {
155 ::new ((void *)std::addressof(value)) T(std::move(other.value));
156 hasVal = true;
157 }
158 } else {
159 reset();
160 }
161 return *this;
162 }
163};
164
165template <typename T> class OptionalStorage<T, true> {
166 union {
167 char empty;
168 T value;
169 };
170 bool hasVal = false;
171
172public:
173 ~OptionalStorage() = default;
174
175 constexpr OptionalStorage() noexcept : empty{} {}
176
177 constexpr OptionalStorage(OptionalStorage const &other) = default;
178 constexpr OptionalStorage(OptionalStorage &&other) = default;
179
180 OptionalStorage &operator=(OptionalStorage const &other) = default;
181 OptionalStorage &operator=(OptionalStorage &&other) = default;
182
183 template <class... Args>
184 constexpr explicit OptionalStorage(in_place_t, Args &&... args)
185 : value(std::forward<Args>(args)...), hasVal(true) {}
186
187 void reset() noexcept {
188 if (hasVal) {
189 value.~T();
190 hasVal = false;
191 }
192 }
193
194 constexpr bool hasValue() const noexcept { return hasVal; }
16
Returning the value 1, which participates in a condition later
195
196 T &getValue() LLVM_LVALUE_FUNCTION& noexcept {
197 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 197, __extension__
__PRETTY_FUNCTION__))
;
198 return value;
199 }
200 constexpr T const &getValue() const LLVM_LVALUE_FUNCTION& noexcept {
201 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 201, __extension__
__PRETTY_FUNCTION__))
;
202 return value;
203 }
204#if LLVM_HAS_RVALUE_REFERENCE_THIS1
205 T &&getValue() && noexcept {
206 assert(hasVal)(static_cast <bool> (hasVal) ? void (0) : __assert_fail
("hasVal", "llvm/include/llvm/ADT/Optional.h", 206, __extension__
__PRETTY_FUNCTION__))
;
207 return std::move(value);
208 }
209#endif
210
211 template <class... Args> void emplace(Args &&... args) {
212 reset();
213 ::new ((void *)std::addressof(value)) T(std::forward<Args>(args)...);
214 hasVal = true;
215 }
216
217 OptionalStorage &operator=(T const &y) {
218 if (hasValue()) {
219 value = y;
220 } else {
221 ::new ((void *)std::addressof(value)) T(y);
222 hasVal = true;
223 }
224 return *this;
225 }
226 OptionalStorage &operator=(T &&y) {
227 if (hasValue()) {
228 value = std::move(y);
229 } else {
230 ::new ((void *)std::addressof(value)) T(std::move(y));
231 hasVal = true;
232 }
233 return *this;
234 }
235};
236
237} // namespace optional_detail
238
239template <typename T> class Optional {
240 optional_detail::OptionalStorage<T> Storage;
241
242public:
243 using value_type = T;
244
245 constexpr Optional() {}
246 constexpr Optional(NoneType) {}
247
248 constexpr Optional(const T &y) : Storage(in_place, y) {}
249 constexpr Optional(const Optional &O) = default;
250
251 constexpr Optional(T &&y) : Storage(in_place, std::move(y)) {}
252 constexpr Optional(Optional &&O) = default;
253
254 template <typename... ArgTypes>
255 constexpr Optional(in_place_t, ArgTypes &&...Args)
256 : Storage(in_place, std::forward<ArgTypes>(Args)...) {}
257
258 Optional &operator=(T &&y) {
259 Storage = std::move(y);
260 return *this;
261 }
262 Optional &operator=(Optional &&O) = default;
263
264 /// Create a new object by constructing it in place with the given arguments.
265 template <typename... ArgTypes> void emplace(ArgTypes &&... Args) {
266 Storage.emplace(std::forward<ArgTypes>(Args)...);
267 }
268
269 static constexpr Optional create(const T *y) {
270 return y ? Optional(*y) : Optional();
271 }
272
273 Optional &operator=(const T &y) {
274 Storage = y;
275 return *this;
276 }
277 Optional &operator=(const Optional &O) = default;
278
279 void reset() { Storage.reset(); }
280
281 constexpr const T *getPointer() const { return &Storage.getValue(); }
282 T *getPointer() { return &Storage.getValue(); }
283 constexpr const T &getValue() const LLVM_LVALUE_FUNCTION& {
284 return Storage.getValue();
285 }
286 T &getValue() LLVM_LVALUE_FUNCTION& { return Storage.getValue(); }
287
288 constexpr explicit operator bool() const { return hasValue(); }
14
Calling 'Optional::hasValue'
19
Returning from 'Optional::hasValue'
20
Returning the value 1, which participates in a condition later
289 constexpr bool hasValue() const { return Storage.hasValue(); }
15
Calling 'OptionalStorage::hasValue'
17
Returning from 'OptionalStorage::hasValue'
18
Returning the value 1, which participates in a condition later
290 constexpr const T *operator->() const { return getPointer(); }
291 T *operator->() { return getPointer(); }
292 constexpr const T &operator*() const LLVM_LVALUE_FUNCTION& {
293 return getValue();
294 }
295 T &operator*() LLVM_LVALUE_FUNCTION& { return getValue(); }
296
297 template <typename U>
298 constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION& {
299 return hasValue() ? getValue() : std::forward<U>(value);
300 }
301
302 /// Apply a function to the value if present; otherwise return None.
303 template <class Function>
304 auto map(const Function &F) const LLVM_LVALUE_FUNCTION&
305 -> Optional<decltype(F(getValue()))> {
306 if (*this) return F(getValue());
307 return None;
308 }
309
310#if LLVM_HAS_RVALUE_REFERENCE_THIS1
311 T &&getValue() && { return std::move(Storage.getValue()); }
312 T &&operator*() && { return std::move(Storage.getValue()); }
313
314 template <typename U>
315 T getValueOr(U &&value) && {
316 return hasValue() ? std::move(getValue()) : std::forward<U>(value);
317 }
318
319 /// Apply a function to the value if present; otherwise return None.
320 template <class Function>
321 auto map(const Function &F) &&
322 -> Optional<decltype(F(std::move(*this).getValue()))> {
323 if (*this) return F(std::move(*this).getValue());
324 return None;
325 }
326#endif
327};
328
329template <class T> llvm::hash_code hash_value(const Optional<T> &O) {
330 return O ? hash_combine(true, *O) : hash_value(false);
331}
332
333template <typename T, typename U>
334constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) {
335 if (X && Y)
336 return *X == *Y;
337 return X.hasValue() == Y.hasValue();
338}
339
340template <typename T, typename U>
341constexpr bool operator!=(const Optional<T> &X, const Optional<U> &Y) {
342 return !(X == Y);
343}
344
345template <typename T, typename U>
346constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) {
347 if (X && Y)
348 return *X < *Y;
349 return X.hasValue() < Y.hasValue();
350}
351
352template <typename T, typename U>
353constexpr bool operator<=(const Optional<T> &X, const Optional<U> &Y) {
354 return !(Y < X);
355}
356
357template <typename T, typename U>
358constexpr bool operator>(const Optional<T> &X, const Optional<U> &Y) {
359 return Y < X;
360}
361
362template <typename T, typename U>
363constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) {
364 return !(X < Y);
365}
366
367template <typename T>
368constexpr bool operator==(const Optional<T> &X, NoneType) {
369 return !X;
370}
371
372template <typename T>
373constexpr bool operator==(NoneType, const Optional<T> &X) {
374 return X == None;
375}
376
377template <typename T>
378constexpr bool operator!=(const Optional<T> &X, NoneType) {
379 return !(X == None);
380}
381
382template <typename T>
383constexpr bool operator!=(NoneType, const Optional<T> &X) {
384 return X != None;
385}
386
387template <typename T> constexpr bool operator<(const Optional<T> &, NoneType) {
388 return false;
389}
390
391template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) {
392 return X.hasValue();
393}
394
395template <typename T>
396constexpr bool operator<=(const Optional<T> &X, NoneType) {
397 return !(None < X);
398}
399
400template <typename T>
401constexpr bool operator<=(NoneType, const Optional<T> &X) {
402 return !(X < None);
403}
404
405template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) {
406 return None < X;
407}
408
409template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) {
410 return X < None;
411}
412
413template <typename T>
414constexpr bool operator>=(const Optional<T> &X, NoneType) {
415 return None <= X;
416}
417
418template <typename T>
419constexpr bool operator>=(NoneType, const Optional<T> &X) {
420 return X <= None;
421}
422
423template <typename T>
424constexpr bool operator==(const Optional<T> &X, const T &Y) {
425 return X && *X == Y;
426}
427
428template <typename T>
429constexpr bool operator==(const T &X, const Optional<T> &Y) {
430 return Y && X == *Y;
431}
432
433template <typename T>
434constexpr bool operator!=(const Optional<T> &X, const T &Y) {
435 return !(X == Y);
436}
437
438template <typename T>
439constexpr bool operator!=(const T &X, const Optional<T> &Y) {
440 return !(X == Y);
441}
442
443template <typename T>
444constexpr bool operator<(const Optional<T> &X, const T &Y) {
445 return !X || *X < Y;
446}
447
448template <typename T>
449constexpr bool operator<(const T &X, const Optional<T> &Y) {
450 return Y && X < *Y;
451}
452
453template <typename T>
454constexpr bool operator<=(const Optional<T> &X, const T &Y) {
455 return !(Y < X);
456}
457
458template <typename T>
459constexpr bool operator<=(const T &X, const Optional<T> &Y) {
460 return !(Y < X);
461}
462
463template <typename T>
464constexpr bool operator>(const Optional<T> &X, const T &Y) {
465 return Y < X;
466}
467
468template <typename T>
469constexpr bool operator>(const T &X, const Optional<T> &Y) {
470 return Y < X;
471}
472
473template <typename T>
474constexpr bool operator>=(const Optional<T> &X, const T &Y) {
475 return !(X < Y);
476}
477
478template <typename T>
479constexpr bool operator>=(const T &X, const Optional<T> &Y) {
480 return !(X < Y);
481}
482
483raw_ostream &operator<<(raw_ostream &OS, NoneType);
484
485template <typename T, typename = decltype(std::declval<raw_ostream &>()
486 << std::declval<const T &>())>
487raw_ostream &operator<<(raw_ostream &OS, const Optional<T> &O) {
488 if (O)
489 OS << *O;
490 else
491 OS << None;
492 return OS;
493}
494
495} // end namespace llvm
496
497#endif // LLVM_ADT_OPTIONAL_H

/build/llvm-toolchain-snapshot-14~++20220119111520+da61cb019eb2/clang/include/clang/ASTMatchers/ASTMatchers.h

1//===- ASTMatchers.h - Structural query framework ---------------*- C++ -*-===//
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// This file implements matchers to be used together with the MatchFinder to
10// match AST nodes.
11//
12// Matchers are created by generator functions, which can be combined in
13// a functional in-language DSL to express queries over the C++ AST.
14//
15// For example, to match a class with a certain name, one would call:
16// cxxRecordDecl(hasName("MyClass"))
17// which returns a matcher that can be used to find all AST nodes that declare
18// a class named 'MyClass'.
19//
20// For more complicated match expressions we're often interested in accessing
21// multiple parts of the matched AST nodes once a match is found. In that case,
22// call `.bind("name")` on match expressions that match the nodes you want to
23// access.
24//
25// For example, when we're interested in child classes of a certain class, we
26// would write:
27// cxxRecordDecl(hasName("MyClass"), has(recordDecl().bind("child")))
28// When the match is found via the MatchFinder, a user provided callback will
29// be called with a BoundNodes instance that contains a mapping from the
30// strings that we provided for the `.bind()` calls to the nodes that were
31// matched.
32// In the given example, each time our matcher finds a match we get a callback
33// where "child" is bound to the RecordDecl node of the matching child
34// class declaration.
35//
36// See ASTMatchersInternal.h for a more in-depth explanation of the
37// implementation details of the matcher framework.
38//
39// See ASTMatchFinder.h for how to use the generated matchers to run over
40// an AST.
41//
42//===----------------------------------------------------------------------===//
43
44#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
45#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
46
47#include "clang/AST/ASTContext.h"
48#include "clang/AST/ASTTypeTraits.h"
49#include "clang/AST/Attr.h"
50#include "clang/AST/CXXInheritance.h"
51#include "clang/AST/Decl.h"
52#include "clang/AST/DeclCXX.h"
53#include "clang/AST/DeclFriend.h"
54#include "clang/AST/DeclObjC.h"
55#include "clang/AST/DeclTemplate.h"
56#include "clang/AST/Expr.h"
57#include "clang/AST/ExprCXX.h"
58#include "clang/AST/ExprObjC.h"
59#include "clang/AST/LambdaCapture.h"
60#include "clang/AST/NestedNameSpecifier.h"
61#include "clang/AST/OpenMPClause.h"
62#include "clang/AST/OperationKinds.h"
63#include "clang/AST/ParentMapContext.h"
64#include "clang/AST/Stmt.h"
65#include "clang/AST/StmtCXX.h"
66#include "clang/AST/StmtObjC.h"
67#include "clang/AST/StmtOpenMP.h"
68#include "clang/AST/TemplateBase.h"
69#include "clang/AST/TemplateName.h"
70#include "clang/AST/Type.h"
71#include "clang/AST/TypeLoc.h"
72#include "clang/ASTMatchers/ASTMatchersInternal.h"
73#include "clang/ASTMatchers/ASTMatchersMacros.h"
74#include "clang/Basic/AttrKinds.h"
75#include "clang/Basic/ExceptionSpecificationType.h"
76#include "clang/Basic/FileManager.h"
77#include "clang/Basic/IdentifierTable.h"
78#include "clang/Basic/LLVM.h"
79#include "clang/Basic/SourceManager.h"
80#include "clang/Basic/Specifiers.h"
81#include "clang/Basic/TypeTraits.h"
82#include "llvm/ADT/ArrayRef.h"
83#include "llvm/ADT/SmallVector.h"
84#include "llvm/ADT/StringRef.h"
85#include "llvm/Support/Casting.h"
86#include "llvm/Support/Compiler.h"
87#include "llvm/Support/ErrorHandling.h"
88#include "llvm/Support/Regex.h"
89#include <cassert>
90#include <cstddef>
91#include <iterator>
92#include <limits>
93#include <string>
94#include <utility>
95#include <vector>
96
97namespace clang {
98namespace ast_matchers {
99
100/// Maps string IDs to AST nodes matched by parts of a matcher.
101///
102/// The bound nodes are generated by calling \c bind("id") on the node matchers
103/// of the nodes we want to access later.
104///
105/// The instances of BoundNodes are created by \c MatchFinder when the user's
106/// callbacks are executed every time a match is found.
107class BoundNodes {
108public:
109 /// Returns the AST node bound to \c ID.
110 ///
111 /// Returns NULL if there was no node bound to \c ID or if there is a node but
112 /// it cannot be converted to the specified type.
113 template <typename T>
114 const T *getNodeAs(StringRef ID) const {
115 return MyBoundNodes.getNodeAs<T>(ID);
24
Calling 'BoundNodesMap::getNodeAs'
31
Returning from 'BoundNodesMap::getNodeAs'
32
Returning null pointer, which participates in a condition later
36
Calling 'BoundNodesMap::getNodeAs'
51
Returning from 'BoundNodesMap::getNodeAs'
52
Returning pointer, which participates in a condition later
116 }
117
118 /// Type of mapping from binding identifiers to bound nodes. This type
119 /// is an associative container with a key type of \c std::string and a value
120 /// type of \c clang::DynTypedNode
121 using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap;
122
123 /// Retrieve mapping from binding identifiers to bound nodes.
124 const IDToNodeMap &getMap() const {
125 return MyBoundNodes.getMap();
126 }
127
128private:
129 friend class internal::BoundNodesTreeBuilder;
130
131 /// Create BoundNodes from a pre-filled map of bindings.
132 BoundNodes(internal::BoundNodesMap &MyBoundNodes)
133 : MyBoundNodes(MyBoundNodes) {}
134
135 internal::BoundNodesMap MyBoundNodes;
136};
137
138/// Types of matchers for the top-level classes in the AST class
139/// hierarchy.
140/// @{
141using DeclarationMatcher = internal::Matcher<Decl>;
142using StatementMatcher = internal::Matcher<Stmt>;
143using TypeMatcher = internal::Matcher<QualType>;
144using TypeLocMatcher = internal::Matcher<TypeLoc>;
145using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>;
146using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>;
147using CXXBaseSpecifierMatcher = internal::Matcher<CXXBaseSpecifier>;
148using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>;
149using TemplateArgumentMatcher = internal::Matcher<TemplateArgument>;
150using TemplateArgumentLocMatcher = internal::Matcher<TemplateArgumentLoc>;
151using LambdaCaptureMatcher = internal::Matcher<LambdaCapture>;
152using AttrMatcher = internal::Matcher<Attr>;
153/// @}
154
155/// Matches any node.
156///
157/// Useful when another matcher requires a child matcher, but there's no
158/// additional constraint. This will often be used with an explicit conversion
159/// to an \c internal::Matcher<> type such as \c TypeMatcher.
160///
161/// Example: \c DeclarationMatcher(anything()) matches all declarations, e.g.,
162/// \code
163/// "int* p" and "void f()" in
164/// int* p;
165/// void f();
166/// \endcode
167///
168/// Usable as: Any Matcher
169inline internal::TrueMatcher anything() { return internal::TrueMatcher(); }
170
171/// Matches the top declaration context.
172///
173/// Given
174/// \code
175/// int X;
176/// namespace NS {
177/// int Y;
178/// } // namespace NS
179/// \endcode
180/// decl(hasDeclContext(translationUnitDecl()))
181/// matches "int X", but not "int Y".
182extern const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl>
183 translationUnitDecl;
184
185/// Matches typedef declarations.
186///
187/// Given
188/// \code
189/// typedef int X;
190/// using Y = int;
191/// \endcode
192/// typedefDecl()
193/// matches "typedef int X", but not "using Y = int"
194extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl>
195 typedefDecl;
196
197/// Matches typedef name declarations.
198///
199/// Given
200/// \code
201/// typedef int X;
202/// using Y = int;
203/// \endcode
204/// typedefNameDecl()
205/// matches "typedef int X" and "using Y = int"
206extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
207 typedefNameDecl;
208
209/// Matches type alias declarations.
210///
211/// Given
212/// \code
213/// typedef int X;
214/// using Y = int;
215/// \endcode
216/// typeAliasDecl()
217/// matches "using Y = int", but not "typedef int X"
218extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
219 typeAliasDecl;
220
221/// Matches type alias template declarations.
222///
223/// typeAliasTemplateDecl() matches
224/// \code
225/// template <typename T>
226/// using Y = X<T>;
227/// \endcode
228extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl>
229 typeAliasTemplateDecl;
230
231/// Matches AST nodes that were expanded within the main-file.
232///
233/// Example matches X but not Y
234/// (matcher = cxxRecordDecl(isExpansionInMainFile())
235/// \code
236/// #include <Y.h>
237/// class X {};
238/// \endcode
239/// Y.h:
240/// \code
241/// class Y {};
242/// \endcode
243///
244/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
245AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,namespace internal { template <typename NodeType> class
matcher_isExpansionInMainFileMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInMainFile() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInMainFileMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
246 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc))namespace internal { template <typename NodeType> class
matcher_isExpansionInMainFileMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInMainFile() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInMainFileMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
247 auto &SourceManager = Finder->getASTContext().getSourceManager();
248 return SourceManager.isInMainFile(
249 SourceManager.getExpansionLoc(Node.getBeginLoc()));
250}
251
252/// Matches AST nodes that were expanded within system-header-files.
253///
254/// Example matches Y but not X
255/// (matcher = cxxRecordDecl(isExpansionInSystemHeader())
256/// \code
257/// #include <SystemHeader.h>
258/// class X {};
259/// \endcode
260/// SystemHeader.h:
261/// \code
262/// class Y {};
263/// \endcode
264///
265/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
266AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,namespace internal { template <typename NodeType> class
matcher_isExpansionInSystemHeaderMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInSystemHeader() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInSystemHeaderMatcher<NodeType
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
267 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc))namespace internal { template <typename NodeType> class
matcher_isExpansionInSystemHeaderMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInSystemHeader() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInSystemHeaderMatcher<NodeType
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
268 auto &SourceManager = Finder->getASTContext().getSourceManager();
269 auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
270 if (ExpansionLoc.isInvalid()) {
271 return false;
272 }
273 return SourceManager.isInSystemHeader(ExpansionLoc);
274}
275
276/// Matches AST nodes that were expanded within files whose name is
277/// partially matching a given regex.
278///
279/// Example matches Y but not X
280/// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
281/// \code
282/// #include "ASTMatcher.h"
283/// class X {};
284/// \endcode
285/// ASTMatcher.h:
286/// \code
287/// class Y {};
288/// \endcode
289///
290/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
291AST_POLYMORPHIC_MATCHER_REGEX(isExpansionInFileMatching,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
292 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
293 TypeLoc),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
294 RegExp)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
295 auto &SourceManager = Finder->getASTContext().getSourceManager();
296 auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
297 if (ExpansionLoc.isInvalid()) {
298 return false;
299 }
300 auto FileEntry =
301 SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc));
302 if (!FileEntry) {
303 return false;
304 }
305
306 auto Filename = FileEntry->getName();
307 return RegExp->match(Filename);
308}
309
310/// Matches statements that are (transitively) expanded from the named macro.
311/// Does not match if only part of the statement is expanded from that macro or
312/// if different parts of the statement are expanded from different
313/// appearances of the macro.
314AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
315 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
316 std::string, MacroName)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
317 // Verifies that the statement' beginning and ending are both expanded from
318 // the same instance of the given macro.
319 auto& Context = Finder->getASTContext();
320 llvm::Optional<SourceLocation> B =
321 internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context);
322 if (!B) return false;
323 llvm::Optional<SourceLocation> E =
324 internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context);
325 if (!E) return false;
326 return *B == *E;
327}
328
329/// Matches declarations.
330///
331/// Examples matches \c X, \c C, and the friend declaration inside \c C;
332/// \code
333/// void X();
334/// class C {
335/// friend X;
336/// };
337/// \endcode
338extern const internal::VariadicAllOfMatcher<Decl> decl;
339
340/// Matches decomposition-declarations.
341///
342/// Examples matches the declaration node with \c foo and \c bar, but not
343/// \c number.
344/// (matcher = declStmt(has(decompositionDecl())))
345///
346/// \code
347/// int number = 42;
348/// auto [foo, bar] = std::make_pair{42, 42};
349/// \endcode
350extern const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl>
351 decompositionDecl;
352
353/// Matches binding declarations
354/// Example matches \c foo and \c bar
355/// (matcher = bindingDecl()
356///
357/// \code
358/// auto [foo, bar] = std::make_pair{42, 42};
359/// \endcode
360extern const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl>
361 bindingDecl;
362
363/// Matches a declaration of a linkage specification.
364///
365/// Given
366/// \code
367/// extern "C" {}
368/// \endcode
369/// linkageSpecDecl()
370/// matches "extern "C" {}"
371extern const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
372 linkageSpecDecl;
373
374/// Matches a declaration of anything that could have a name.
375///
376/// Example matches \c X, \c S, the anonymous union type, \c i, and \c U;
377/// \code
378/// typedef int X;
379/// struct S {
380/// union {
381/// int i;
382/// } U;
383/// };
384/// \endcode
385extern const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl;
386
387/// Matches a declaration of label.
388///
389/// Given
390/// \code
391/// goto FOO;
392/// FOO: bar();
393/// \endcode
394/// labelDecl()
395/// matches 'FOO:'
396extern const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl;
397
398/// Matches a declaration of a namespace.
399///
400/// Given
401/// \code
402/// namespace {}
403/// namespace test {}
404/// \endcode
405/// namespaceDecl()
406/// matches "namespace {}" and "namespace test {}"
407extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl>
408 namespaceDecl;
409
410/// Matches a declaration of a namespace alias.
411///
412/// Given
413/// \code
414/// namespace test {}
415/// namespace alias = ::test;
416/// \endcode
417/// namespaceAliasDecl()
418/// matches "namespace alias" but not "namespace test"
419extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
420 namespaceAliasDecl;
421
422/// Matches class, struct, and union declarations.
423///
424/// Example matches \c X, \c Z, \c U, and \c S
425/// \code
426/// class X;
427/// template<class T> class Z {};
428/// struct S {};
429/// union U {};
430/// \endcode
431extern const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl;
432
433/// Matches C++ class declarations.
434///
435/// Example matches \c X, \c Z
436/// \code
437/// class X;
438/// template<class T> class Z {};
439/// \endcode
440extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl>
441 cxxRecordDecl;
442
443/// Matches C++ class template declarations.
444///
445/// Example matches \c Z
446/// \code
447/// template<class T> class Z {};
448/// \endcode
449extern const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl>
450 classTemplateDecl;
451
452/// Matches C++ class template specializations.
453///
454/// Given
455/// \code
456/// template<typename T> class A {};
457/// template<> class A<double> {};
458/// A<int> a;
459/// \endcode
460/// classTemplateSpecializationDecl()
461/// matches the specializations \c A<int> and \c A<double>
462extern const internal::VariadicDynCastAllOfMatcher<
463 Decl, ClassTemplateSpecializationDecl>
464 classTemplateSpecializationDecl;
465
466/// Matches C++ class template partial specializations.
467///
468/// Given
469/// \code
470/// template<class T1, class T2, int I>
471/// class A {};
472///
473/// template<class T, int I>
474/// class A<T, T*, I> {};
475///
476/// template<>
477/// class A<int, int, 1> {};
478/// \endcode
479/// classTemplatePartialSpecializationDecl()
480/// matches the specialization \c A<T,T*,I> but not \c A<int,int,1>
481extern const internal::VariadicDynCastAllOfMatcher<
482 Decl, ClassTemplatePartialSpecializationDecl>
483 classTemplatePartialSpecializationDecl;
484
485/// Matches declarator declarations (field, variable, function
486/// and non-type template parameter declarations).
487///
488/// Given
489/// \code
490/// class X { int y; };
491/// \endcode
492/// declaratorDecl()
493/// matches \c int y.
494extern const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl>
495 declaratorDecl;
496
497/// Matches parameter variable declarations.
498///
499/// Given
500/// \code
501/// void f(int x);
502/// \endcode
503/// parmVarDecl()
504/// matches \c int x.
505extern const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl>
506 parmVarDecl;
507
508/// Matches C++ access specifier declarations.
509///
510/// Given
511/// \code
512/// class C {
513/// public:
514/// int a;
515/// };
516/// \endcode
517/// accessSpecDecl()
518/// matches 'public:'
519extern const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl>
520 accessSpecDecl;
521
522/// Matches class bases.
523///
524/// Examples matches \c public virtual B.
525/// \code
526/// class B {};
527/// class C : public virtual B {};
528/// \endcode
529extern const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier;
530
531/// Matches constructor initializers.
532///
533/// Examples matches \c i(42).
534/// \code
535/// class C {
536/// C() : i(42) {}
537/// int i;
538/// };
539/// \endcode
540extern const internal::VariadicAllOfMatcher<CXXCtorInitializer>
541 cxxCtorInitializer;
542
543/// Matches template arguments.
544///
545/// Given
546/// \code
547/// template <typename T> struct C {};
548/// C<int> c;
549/// \endcode
550/// templateArgument()
551/// matches 'int' in C<int>.
552extern const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument;
553
554/// Matches template arguments (with location info).
555///
556/// Given
557/// \code
558/// template <typename T> struct C {};
559/// C<int> c;
560/// \endcode
561/// templateArgumentLoc()
562/// matches 'int' in C<int>.
563extern const internal::VariadicAllOfMatcher<TemplateArgumentLoc>
564 templateArgumentLoc;
565
566/// Matches template name.
567///
568/// Given
569/// \code
570/// template <typename T> class X { };
571/// X<int> xi;
572/// \endcode
573/// templateName()
574/// matches 'X' in X<int>.
575extern const internal::VariadicAllOfMatcher<TemplateName> templateName;
576
577/// Matches non-type template parameter declarations.
578///
579/// Given
580/// \code
581/// template <typename T, int N> struct C {};
582/// \endcode
583/// nonTypeTemplateParmDecl()
584/// matches 'N', but not 'T'.
585extern const internal::VariadicDynCastAllOfMatcher<Decl,
586 NonTypeTemplateParmDecl>
587 nonTypeTemplateParmDecl;
588
589/// Matches template type parameter declarations.
590///
591/// Given
592/// \code
593/// template <typename T, int N> struct C {};
594/// \endcode
595/// templateTypeParmDecl()
596/// matches 'T', but not 'N'.
597extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
598 templateTypeParmDecl;
599
600/// Matches template template parameter declarations.
601///
602/// Given
603/// \code
604/// template <template <typename> class Z, int N> struct C {};
605/// \endcode
606/// templateTypeParmDecl()
607/// matches 'Z', but not 'N'.
608extern const internal::VariadicDynCastAllOfMatcher<Decl,
609 TemplateTemplateParmDecl>
610 templateTemplateParmDecl;
611
612/// Matches public C++ declarations and C++ base specifers that specify public
613/// inheritance.
614///
615/// Examples:
616/// \code
617/// class C {
618/// public: int a; // fieldDecl(isPublic()) matches 'a'
619/// protected: int b;
620/// private: int c;
621/// };
622/// \endcode
623///
624/// \code
625/// class Base {};
626/// class Derived1 : public Base {}; // matches 'Base'
627/// struct Derived2 : Base {}; // matches 'Base'
628/// \endcode
629AST_POLYMORPHIC_MATCHER(isPublic,namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
630 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
631 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
632 return getAccessSpecifier(Node) == AS_public;
633}
634
635/// Matches protected C++ declarations and C++ base specifers that specify
636/// protected inheritance.
637///
638/// Examples:
639/// \code
640/// class C {
641/// public: int a;
642/// protected: int b; // fieldDecl(isProtected()) matches 'b'
643/// private: int c;
644/// };
645/// \endcode
646///
647/// \code
648/// class Base {};
649/// class Derived : protected Base {}; // matches 'Base'
650/// \endcode
651AST_POLYMORPHIC_MATCHER(isProtected,namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
652 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
653 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
654 return getAccessSpecifier(Node) == AS_protected;
655}
656
657/// Matches private C++ declarations and C++ base specifers that specify private
658/// inheritance.
659///
660/// Examples:
661/// \code
662/// class C {
663/// public: int a;
664/// protected: int b;
665/// private: int c; // fieldDecl(isPrivate()) matches 'c'
666/// };
667/// \endcode
668///
669/// \code
670/// struct Base {};
671/// struct Derived1 : private Base {}; // matches 'Base'
672/// class Derived2 : Base {}; // matches 'Base'
673/// \endcode
674AST_POLYMORPHIC_MATCHER(isPrivate,namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
675 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
676 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
677 return getAccessSpecifier(Node) == AS_private;
678}
679
680/// Matches non-static data members that are bit-fields.
681///
682/// Given
683/// \code
684/// class C {
685/// int a : 2;
686/// int b;
687/// };
688/// \endcode
689/// fieldDecl(isBitField())
690/// matches 'int a;' but not 'int b;'.
691AST_MATCHER(FieldDecl, isBitField)namespace internal { class matcher_isBitFieldMatcher : public
::clang::ast_matchers::internal::MatcherInterface<FieldDecl
> { public: explicit matcher_isBitFieldMatcher() = default
; bool matches(const FieldDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FieldDecl> isBitField
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isBitFieldMatcher()); } inline bool internal
::matcher_isBitFieldMatcher::matches( const FieldDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
692 return Node.isBitField();
693}
694
695/// Matches non-static data members that are bit-fields of the specified
696/// bit width.
697///
698/// Given
699/// \code
700/// class C {
701/// int a : 2;
702/// int b : 4;
703/// int c : 2;
704/// };
705/// \endcode
706/// fieldDecl(hasBitWidth(2))
707/// matches 'int a;' and 'int c;' but not 'int b;'.
708AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width)namespace internal { class matcher_hasBitWidth0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<FieldDecl
> { public: explicit matcher_hasBitWidth0Matcher( unsigned
const &AWidth) : Width(AWidth) {} bool matches(const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned Width; }; } inline
::clang::ast_matchers::internal::Matcher<FieldDecl> hasBitWidth
( unsigned const &Width) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasBitWidth0Matcher
(Width)); } typedef ::clang::ast_matchers::internal::Matcher<
FieldDecl> ( &hasBitWidth_Type0)(unsigned const &Width
); inline bool internal::matcher_hasBitWidth0Matcher::matches
( const FieldDecl &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
709 return Node.isBitField() &&
710 Node.getBitWidthValue(Finder->getASTContext()) == Width;
711}
712
713/// Matches non-static data members that have an in-class initializer.
714///
715/// Given
716/// \code
717/// class C {
718/// int a = 2;
719/// int b = 3;
720/// int c;
721/// };
722/// \endcode
723/// fieldDecl(hasInClassInitializer(integerLiteral(equals(2))))
724/// matches 'int a;' but not 'int b;'.
725/// fieldDecl(hasInClassInitializer(anything()))
726/// matches 'int a;' and 'int b;' but not 'int c;'.
727AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>,namespace internal { class matcher_hasInClassInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FieldDecl> { public: explicit matcher_hasInClassInitializer0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FieldDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FieldDecl
> hasInClassInitializer( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasInClassInitializer0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FieldDecl> ( &hasInClassInitializer_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasInClassInitializer0Matcher::matches( const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
728 InnerMatcher)namespace internal { class matcher_hasInClassInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FieldDecl> { public: explicit matcher_hasInClassInitializer0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FieldDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FieldDecl
> hasInClassInitializer( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasInClassInitializer0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FieldDecl> ( &hasInClassInitializer_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasInClassInitializer0Matcher::matches( const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
729 const Expr *Initializer = Node.getInClassInitializer();
730 return (Initializer != nullptr &&
731 InnerMatcher.matches(*Initializer, Finder, Builder));
732}
733
734/// Determines whether the function is "main", which is the entry point
735/// into an executable program.
736AST_MATCHER(FunctionDecl, isMain)namespace internal { class matcher_isMainMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<FunctionDecl>
{ public: explicit matcher_isMainMatcher() = default; bool matches
(const FunctionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<FunctionDecl> isMain() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isMainMatcher
()); } inline bool internal::matcher_isMainMatcher::matches( const
FunctionDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
737 return Node.isMain();
738}
739
740/// Matches the specialized template of a specialization declaration.
741///
742/// Given
743/// \code
744/// template<typename T> class A {}; #1
745/// template<> class A<int> {}; #2
746/// \endcode
747/// classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl()))
748/// matches '#2' with classTemplateDecl() matching the class template
749/// declaration of 'A' at #1.
750AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate,namespace internal { class matcher_hasSpecializedTemplate0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ClassTemplateSpecializationDecl> { public: explicit matcher_hasSpecializedTemplate0Matcher
( internal::Matcher<ClassTemplateDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ClassTemplateDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ClassTemplateSpecializationDecl> hasSpecializedTemplate
( internal::Matcher<ClassTemplateDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSpecializedTemplate0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ClassTemplateSpecializationDecl
> ( &hasSpecializedTemplate_Type0)(internal::Matcher<
ClassTemplateDecl> const &InnerMatcher); inline bool internal
::matcher_hasSpecializedTemplate0Matcher::matches( const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
751 internal::Matcher<ClassTemplateDecl>, InnerMatcher)namespace internal { class matcher_hasSpecializedTemplate0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ClassTemplateSpecializationDecl> { public: explicit matcher_hasSpecializedTemplate0Matcher
( internal::Matcher<ClassTemplateDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ClassTemplateDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ClassTemplateSpecializationDecl> hasSpecializedTemplate
( internal::Matcher<ClassTemplateDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSpecializedTemplate0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ClassTemplateSpecializationDecl
> ( &hasSpecializedTemplate_Type0)(internal::Matcher<
ClassTemplateDecl> const &InnerMatcher); inline bool internal
::matcher_hasSpecializedTemplate0Matcher::matches( const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
752 const ClassTemplateDecl* Decl = Node.getSpecializedTemplate();
753 return (Decl != nullptr &&
754 InnerMatcher.matches(*Decl, Finder, Builder));
755}
756
757/// Matches an entity that has been implicitly added by the compiler (e.g.
758/// implicit default/copy constructors).
759AST_POLYMORPHIC_MATCHER(isImplicit,namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
760 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Attr,namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
761 LambdaCapture))namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
762 return Node.isImplicit();
763}
764
765/// Matches classTemplateSpecializations, templateSpecializationType and
766/// functionDecl that have at least one TemplateArgument matching the given
767/// InnerMatcher.
768///
769/// Given
770/// \code
771/// template<typename T> class A {};
772/// template<> class A<double> {};
773/// A<int> a;
774///
775/// template<typename T> f() {};
776/// void func() { f<int>(); };
777/// \endcode
778///
779/// \endcode
780/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
781/// refersToType(asString("int"))))
782/// matches the specialization \c A<int>
783///
784/// functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))
785/// matches the specialization \c f<int>
786AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
787 hasAnyTemplateArgument,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
788 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
789 TemplateSpecializationType,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
790 FunctionDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
791 internal::Matcher<TemplateArgument>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
792 ArrayRef<TemplateArgument> List =
793 internal::getTemplateSpecializationArgs(Node);
794 return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder,
795 Builder) != List.end();
796}
797
798/// Causes all nested matchers to be matched with the specified traversal kind.
799///
800/// Given
801/// \code
802/// void foo()
803/// {
804/// int i = 3.0;
805/// }
806/// \endcode
807/// The matcher
808/// \code
809/// traverse(TK_IgnoreUnlessSpelledInSource,
810/// varDecl(hasInitializer(floatLiteral().bind("init")))
811/// )
812/// \endcode
813/// matches the variable declaration with "init" bound to the "3.0".
814template <typename T>
815internal::Matcher<T> traverse(TraversalKind TK,
816 const internal::Matcher<T> &InnerMatcher) {
817 return internal::DynTypedMatcher::constructRestrictedWrapper(
818 new internal::TraversalMatcher<T>(TK, InnerMatcher),
819 InnerMatcher.getID().first)
820 .template unconditionalConvertTo<T>();
821}
822
823template <typename T>
824internal::BindableMatcher<T>
825traverse(TraversalKind TK, const internal::BindableMatcher<T> &InnerMatcher) {
826 return internal::BindableMatcher<T>(
827 internal::DynTypedMatcher::constructRestrictedWrapper(
828 new internal::TraversalMatcher<T>(TK, InnerMatcher),
829 InnerMatcher.getID().first)
830 .template unconditionalConvertTo<T>());
831}
832
833template <typename... T>
834internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>>
835traverse(TraversalKind TK,
836 const internal::VariadicOperatorMatcher<T...> &InnerMatcher) {
837 return internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>>(
838 TK, InnerMatcher);
839}
840
841template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
842 typename T, typename ToTypes>
843internal::TraversalWrapper<
844 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>>
845traverse(TraversalKind TK, const internal::ArgumentAdaptingMatcherFuncAdaptor<
846 ArgumentAdapterT, T, ToTypes> &InnerMatcher) {
847 return internal::TraversalWrapper<
848 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T,
849 ToTypes>>(TK, InnerMatcher);
850}
851
852template <template <typename T, typename... P> class MatcherT, typename... P,
853 typename ReturnTypesF>
854internal::TraversalWrapper<
855 internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>
856traverse(TraversalKind TK,
857 const internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>
858 &InnerMatcher) {
859 return internal::TraversalWrapper<
860 internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>(TK,
861 InnerMatcher);
862}
863
864template <typename... T>
865internal::Matcher<typename internal::GetClade<T...>::Type>
866traverse(TraversalKind TK, const internal::MapAnyOfHelper<T...> &InnerMatcher) {
867 return traverse(TK, InnerMatcher.with());
868}
869
870/// Matches expressions that match InnerMatcher after any implicit AST
871/// nodes are stripped off.
872///
873/// Parentheses and explicit casts are not discarded.
874/// Given
875/// \code
876/// class C {};
877/// C a = C();
878/// C b;
879/// C c = b;
880/// \endcode
881/// The matchers
882/// \code
883/// varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr())))
884/// \endcode
885/// would match the declarations for a, b, and c.
886/// While
887/// \code
888/// varDecl(hasInitializer(cxxConstructExpr()))
889/// \endcode
890/// only match the declarations for b and c.
891AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>,namespace internal { class matcher_ignoringImplicit0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImplicit0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImplicit
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImplicit0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImplicit_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImplicit0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
892 InnerMatcher)namespace internal { class matcher_ignoringImplicit0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImplicit0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImplicit
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImplicit0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImplicit_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImplicit0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
893 return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
894}
895
896/// Matches expressions that match InnerMatcher after any implicit casts
897/// are stripped off.
898///
899/// Parentheses and explicit casts are not discarded.
900/// Given
901/// \code
902/// int arr[5];
903/// int a = 0;
904/// char b = 0;
905/// const int c = a;
906/// int *d = arr;
907/// long e = (long) 0l;
908/// \endcode
909/// The matchers
910/// \code
911/// varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
912/// varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
913/// \endcode
914/// would match the declarations for a, b, c, and d, but not e.
915/// While
916/// \code
917/// varDecl(hasInitializer(integerLiteral()))
918/// varDecl(hasInitializer(declRefExpr()))
919/// \endcode
920/// only match the declarations for a.
921AST_MATCHER_P(Expr, ignoringImpCasts,namespace internal { class matcher_ignoringImpCasts0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImpCasts0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImpCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImpCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImpCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
922 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringImpCasts0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImpCasts0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImpCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImpCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImpCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
923 return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
924}
925
926/// Matches expressions that match InnerMatcher after parentheses and
927/// casts are stripped off.
928///
929/// Implicit and non-C Style casts are also discarded.
930/// Given
931/// \code
932/// int a = 0;
933/// char b = (0);
934/// void* c = reinterpret_cast<char*>(0);
935/// char d = char(0);
936/// \endcode
937/// The matcher
938/// varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
939/// would match the declarations for a, b, c, and d.
940/// while
941/// varDecl(hasInitializer(integerLiteral()))
942/// only match the declaration for a.
943AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringParenCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringParenCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParenCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
944 return InnerMatcher.matches(*Node.IgnoreParenCasts(), Finder, Builder);
945}
946
947/// Matches expressions that match InnerMatcher after implicit casts and
948/// parentheses are stripped off.
949///
950/// Explicit casts are not discarded.
951/// Given
952/// \code
953/// int arr[5];
954/// int a = 0;
955/// char b = (0);
956/// const int c = a;
957/// int *d = (arr);
958/// long e = ((long) 0l);
959/// \endcode
960/// The matchers
961/// varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
962/// varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
963/// would match the declarations for a, b, c, and d, but not e.
964/// while
965/// varDecl(hasInitializer(integerLiteral()))
966/// varDecl(hasInitializer(declRefExpr()))
967/// would only match the declaration for a.
968AST_MATCHER_P(Expr, ignoringParenImpCasts,namespace internal { class matcher_ignoringParenImpCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenImpCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenImpCasts0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<Expr> ( &
ignoringParenImpCasts_Type0)(internal::Matcher<Expr> const
&InnerMatcher); inline bool internal::matcher_ignoringParenImpCasts0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
969 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringParenImpCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenImpCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenImpCasts0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<Expr> ( &
ignoringParenImpCasts_Type0)(internal::Matcher<Expr> const
&InnerMatcher); inline bool internal::matcher_ignoringParenImpCasts0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
970 return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder);
971}
972
973/// Matches types that match InnerMatcher after any parens are stripped.
974///
975/// Given
976/// \code
977/// void (*fp)(void);
978/// \endcode
979/// The matcher
980/// \code
981/// varDecl(hasType(pointerType(pointee(ignoringParens(functionType())))))
982/// \endcode
983/// would match the declaration for fp.
984AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher<QualType>,namespace internal { class matcher_ignoringParens0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_ignoringParens0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> ignoringParens
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_ignoringParens0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<QualType> ( &
ignoringParens_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_ignoringParens0Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
985 InnerMatcher, 0)namespace internal { class matcher_ignoringParens0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_ignoringParens0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> ignoringParens
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_ignoringParens0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<QualType> ( &
ignoringParens_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_ignoringParens0Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
986 return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder);
987}
988
989/// Overload \c ignoringParens for \c Expr.
990///
991/// Given
992/// \code
993/// const char* str = ("my-string");
994/// \endcode
995/// The matcher
996/// \code
997/// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral())))
998/// \endcode
999/// would match the implicit cast resulting from the assignment.
1000AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher<Expr>,namespace internal { class matcher_ignoringParens1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_ignoringParens1Matcher( internal::
Matcher<Expr> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const Expr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParens(
internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParens1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Expr> ( &ignoringParens_Type1
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParens1Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1001 InnerMatcher, 1)namespace internal { class matcher_ignoringParens1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_ignoringParens1Matcher( internal::
Matcher<Expr> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const Expr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParens(
internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParens1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Expr> ( &ignoringParens_Type1
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParens1Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1002 const Expr *E = Node.IgnoreParens();
1003 return InnerMatcher.matches(*E, Finder, Builder);
1004}
1005
1006/// Matches expressions that are instantiation-dependent even if it is
1007/// neither type- nor value-dependent.
1008///
1009/// In the following example, the expression sizeof(sizeof(T() + T()))
1010/// is instantiation-dependent (since it involves a template parameter T),
1011/// but is neither type- nor value-dependent, since the type of the inner
1012/// sizeof is known (std::size_t) and therefore the size of the outer
1013/// sizeof is known.
1014/// \code
1015/// template<typename T>
1016/// void f(T x, T y) { sizeof(sizeof(T() + T()); }
1017/// \endcode
1018/// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())
1019AST_MATCHER(Expr, isInstantiationDependent)namespace internal { class matcher_isInstantiationDependentMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_isInstantiationDependentMatcher
() = default; bool matches(const Expr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<Expr> isInstantiationDependent
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isInstantiationDependentMatcher()); } inline
bool internal::matcher_isInstantiationDependentMatcher::matches
( const Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1020 return Node.isInstantiationDependent();
1021}
1022
1023/// Matches expressions that are type-dependent because the template type
1024/// is not yet instantiated.
1025///
1026/// For example, the expressions "x" and "x + y" are type-dependent in
1027/// the following code, but "y" is not type-dependent:
1028/// \code
1029/// template<typename T>
1030/// void add(T x, int y) {
1031/// x + y;
1032/// }
1033/// \endcode
1034/// expr(isTypeDependent()) matches x + y
1035AST_MATCHER(Expr, isTypeDependent)namespace internal { class matcher_isTypeDependentMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_isTypeDependentMatcher() = default
; bool matches(const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Expr> isTypeDependent() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isTypeDependentMatcher
()); } inline bool internal::matcher_isTypeDependentMatcher::
matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isTypeDependent(); }
1036
1037/// Matches expression that are value-dependent because they contain a
1038/// non-type template parameter.
1039///
1040/// For example, the array bound of "Chars" in the following example is
1041/// value-dependent.
1042/// \code
1043/// template<int Size> int f() { return Size; }
1044/// \endcode
1045/// expr(isValueDependent()) matches return Size
1046AST_MATCHER(Expr, isValueDependent)namespace internal { class matcher_isValueDependentMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_isValueDependentMatcher() = default
; bool matches(const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Expr> isValueDependent() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isValueDependentMatcher
()); } inline bool internal::matcher_isValueDependentMatcher::
matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isValueDependent(); }
1047
1048/// Matches classTemplateSpecializations, templateSpecializationType and
1049/// functionDecl where the n'th TemplateArgument matches the given InnerMatcher.
1050///
1051/// Given
1052/// \code
1053/// template<typename T, typename U> class A {};
1054/// A<bool, int> b;
1055/// A<int, bool> c;
1056///
1057/// template<typename T> void f() {}
1058/// void func() { f<int>(); };
1059/// \endcode
1060/// classTemplateSpecializationDecl(hasTemplateArgument(
1061/// 1, refersToType(asString("int"))))
1062/// matches the specialization \c A<bool, int>
1063///
1064/// functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))
1065/// matches the specialization \c f<int>
1066AST_POLYMORPHIC_MATCHER_P2(namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1067 hasTemplateArgument,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1068 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1069 TemplateSpecializationType,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1070 FunctionDecl),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1071 unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
1072 ArrayRef<TemplateArgument> List =
1073 internal::getTemplateSpecializationArgs(Node);
1074 if (List.size() <= N)
1075 return false;
1076 return InnerMatcher.matches(List[N], Finder, Builder);
1077}
1078
1079/// Matches if the number of template arguments equals \p N.
1080///
1081/// Given
1082/// \code
1083/// template<typename T> struct C {};
1084/// C<int> c;
1085/// \endcode
1086/// classTemplateSpecializationDecl(templateArgumentCountIs(1))
1087/// matches C<int>.
1088AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1089 templateArgumentCountIs,namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1090 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1091 TemplateSpecializationType),namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1092 unsigned, N)namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
1093 return internal::getTemplateSpecializationArgs(Node).size() == N;
1094}
1095
1096/// Matches a TemplateArgument that refers to a certain type.
1097///
1098/// Given
1099/// \code
1100/// struct X {};
1101/// template<typename T> struct A {};
1102/// A<X> a;
1103/// \endcode
1104/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
1105/// refersToType(class(hasName("X")))))
1106/// matches the specialization \c A<X>
1107AST_MATCHER_P(TemplateArgument, refersToType,namespace internal { class matcher_refersToType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_refersToType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_refersToType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateArgument
> ( &refersToType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_refersToType0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1108 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_refersToType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_refersToType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_refersToType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateArgument
> ( &refersToType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_refersToType0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1109 if (Node.getKind() != TemplateArgument::Type)
1110 return false;
1111 return InnerMatcher.matches(Node.getAsType(), Finder, Builder);
1112}
1113
1114/// Matches a TemplateArgument that refers to a certain template.
1115///
1116/// Given
1117/// \code
1118/// template<template <typename> class S> class X {};
1119/// template<typename T> class Y {};
1120/// X<Y> xi;
1121/// \endcode
1122/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
1123/// refersToTemplate(templateName())))
1124/// matches the specialization \c X<Y>
1125AST_MATCHER_P(TemplateArgument, refersToTemplate,namespace internal { class matcher_refersToTemplate0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToTemplate0Matcher
( internal::Matcher<TemplateName> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateName
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToTemplate( internal::
Matcher<TemplateName> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_refersToTemplate0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<TemplateArgument>
( &refersToTemplate_Type0)(internal::Matcher<TemplateName
> const &InnerMatcher); inline bool internal::matcher_refersToTemplate0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1126 internal::Matcher<TemplateName>, InnerMatcher)namespace internal { class matcher_refersToTemplate0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToTemplate0Matcher
( internal::Matcher<TemplateName> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateName
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToTemplate( internal::
Matcher<TemplateName> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_refersToTemplate0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<TemplateArgument>
( &refersToTemplate_Type0)(internal::Matcher<TemplateName
> const &InnerMatcher); inline bool internal::matcher_refersToTemplate0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1127 if (Node.getKind() != TemplateArgument::Template)
1128 return false;
1129 return InnerMatcher.matches(Node.getAsTemplate(), Finder, Builder);
1130}
1131
1132/// Matches a canonical TemplateArgument that refers to a certain
1133/// declaration.
1134///
1135/// Given
1136/// \code
1137/// struct B { int next; };
1138/// template<int(B::*next_ptr)> struct A {};
1139/// A<&B::next> a;
1140/// \endcode
1141/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
1142/// refersToDeclaration(fieldDecl(hasName("next")))))
1143/// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching
1144/// \c B::next
1145AST_MATCHER_P(TemplateArgument, refersToDeclaration,namespace internal { class matcher_refersToDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToDeclaration( internal::Matcher<Decl> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_refersToDeclaration0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToDeclaration_Type0)(internal
::Matcher<Decl> const &InnerMatcher); inline bool internal
::matcher_refersToDeclaration0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1146 internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_refersToDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToDeclaration( internal::Matcher<Decl> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_refersToDeclaration0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToDeclaration_Type0)(internal
::Matcher<Decl> const &InnerMatcher); inline bool internal
::matcher_refersToDeclaration0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1147 if (Node.getKind() == TemplateArgument::Declaration)
1148 return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder);
1149 return false;
1150}
1151
1152/// Matches a sugar TemplateArgument that refers to a certain expression.
1153///
1154/// Given
1155/// \code
1156/// struct B { int next; };
1157/// template<int(B::*next_ptr)> struct A {};
1158/// A<&B::next> a;
1159/// \endcode
1160/// templateSpecializationType(hasAnyTemplateArgument(
1161/// isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))
1162/// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching
1163/// \c B::next
1164AST_MATCHER_P(TemplateArgument, isExpr, internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_isExpr0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_isExpr0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const TemplateArgument &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<TemplateArgument> isExpr
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isExpr0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<TemplateArgument> ( &isExpr_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_isExpr0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1165 if (Node.getKind() == TemplateArgument::Expression)
1166 return InnerMatcher.matches(*Node.getAsExpr(), Finder, Builder);
1167 return false;
1168}
1169
1170/// Matches a TemplateArgument that is an integral value.
1171///
1172/// Given
1173/// \code
1174/// template<int T> struct C {};
1175/// C<42> c;
1176/// \endcode
1177/// classTemplateSpecializationDecl(
1178/// hasAnyTemplateArgument(isIntegral()))
1179/// matches the implicit instantiation of C in C<42>
1180/// with isIntegral() matching 42.
1181AST_MATCHER(TemplateArgument, isIntegral)namespace internal { class matcher_isIntegralMatcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_isIntegralMatcher() = default
; bool matches(const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> isIntegral() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isIntegralMatcher()); } inline bool internal
::matcher_isIntegralMatcher::matches( const TemplateArgument &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
1182 return Node.getKind() == TemplateArgument::Integral;
1183}
1184
1185/// Matches a TemplateArgument that refers to an integral type.
1186///
1187/// Given
1188/// \code
1189/// template<int T> struct C {};
1190/// C<42> c;
1191/// \endcode
1192/// classTemplateSpecializationDecl(
1193/// hasAnyTemplateArgument(refersToIntegralType(asString("int"))))
1194/// matches the implicit instantiation of C in C<42>.
1195AST_MATCHER_P(TemplateArgument, refersToIntegralType,namespace internal { class matcher_refersToIntegralType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToIntegralType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToIntegralType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_refersToIntegralType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToIntegralType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_refersToIntegralType0Matcher::matches( const
TemplateArgument &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1196 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_refersToIntegralType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToIntegralType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToIntegralType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_refersToIntegralType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToIntegralType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_refersToIntegralType0Matcher::matches( const
TemplateArgument &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1197 if (Node.getKind() != TemplateArgument::Integral)
1198 return false;
1199 return InnerMatcher.matches(Node.getIntegralType(), Finder, Builder);
1200}
1201
1202/// Matches a TemplateArgument of integral type with a given value.
1203///
1204/// Note that 'Value' is a string as the template argument's value is
1205/// an arbitrary precision integer. 'Value' must be euqal to the canonical
1206/// representation of that integral value in base 10.
1207///
1208/// Given
1209/// \code
1210/// template<int T> struct C {};
1211/// C<42> c;
1212/// \endcode
1213/// classTemplateSpecializationDecl(
1214/// hasAnyTemplateArgument(equalsIntegralValue("42")))
1215/// matches the implicit instantiation of C in C<42>.
1216AST_MATCHER_P(TemplateArgument, equalsIntegralValue,namespace internal { class matcher_equalsIntegralValue0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_equalsIntegralValue0Matcher
( std::string const &AValue) : Value(AValue) {} bool matches
(const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Value; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> equalsIntegralValue( std::string const &Value) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_equalsIntegralValue0Matcher(Value)); } typedef ::clang
::ast_matchers::internal::Matcher<TemplateArgument> ( &
equalsIntegralValue_Type0)(std::string const &Value); inline
bool internal::matcher_equalsIntegralValue0Matcher::matches(
const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1217 std::string, Value)namespace internal { class matcher_equalsIntegralValue0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_equalsIntegralValue0Matcher
( std::string const &AValue) : Value(AValue) {} bool matches
(const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Value; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> equalsIntegralValue( std::string const &Value) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_equalsIntegralValue0Matcher(Value)); } typedef ::clang
::ast_matchers::internal::Matcher<TemplateArgument> ( &
equalsIntegralValue_Type0)(std::string const &Value); inline
bool internal::matcher_equalsIntegralValue0Matcher::matches(
const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1218 if (Node.getKind() != TemplateArgument::Integral)
1219 return false;
1220 return toString(Node.getAsIntegral(), 10) == Value;
1221}
1222
1223/// Matches an Objective-C autorelease pool statement.
1224///
1225/// Given
1226/// \code
1227/// @autoreleasepool {
1228/// int x = 0;
1229/// }
1230/// \endcode
1231/// autoreleasePoolStmt(stmt()) matches the declaration of "x"
1232/// inside the autorelease pool.
1233extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1234 ObjCAutoreleasePoolStmt> autoreleasePoolStmt;
1235
1236/// Matches any value declaration.
1237///
1238/// Example matches A, B, C and F
1239/// \code
1240/// enum X { A, B, C };
1241/// void F();
1242/// \endcode
1243extern const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
1244
1245/// Matches C++ constructor declarations.
1246///
1247/// Example matches Foo::Foo() and Foo::Foo(int)
1248/// \code
1249/// class Foo {
1250/// public:
1251/// Foo();
1252/// Foo(int);
1253/// int DoSomething();
1254/// };
1255/// \endcode
1256extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl>
1257 cxxConstructorDecl;
1258
1259/// Matches explicit C++ destructor declarations.
1260///
1261/// Example matches Foo::~Foo()
1262/// \code
1263/// class Foo {
1264/// public:
1265/// virtual ~Foo();
1266/// };
1267/// \endcode
1268extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl>
1269 cxxDestructorDecl;
1270
1271/// Matches enum declarations.
1272///
1273/// Example matches X
1274/// \code
1275/// enum X {
1276/// A, B, C
1277/// };
1278/// \endcode
1279extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl;
1280
1281/// Matches enum constants.
1282///
1283/// Example matches A, B, C
1284/// \code
1285/// enum X {
1286/// A, B, C
1287/// };
1288/// \endcode
1289extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl>
1290 enumConstantDecl;
1291
1292/// Matches tag declarations.
1293///
1294/// Example matches X, Z, U, S, E
1295/// \code
1296/// class X;
1297/// template<class T> class Z {};
1298/// struct S {};
1299/// union U {};
1300/// enum E {
1301/// A, B, C
1302/// };
1303/// \endcode
1304extern const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl;
1305
1306/// Matches method declarations.
1307///
1308/// Example matches y
1309/// \code
1310/// class X { void y(); };
1311/// \endcode
1312extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl>
1313 cxxMethodDecl;
1314
1315/// Matches conversion operator declarations.
1316///
1317/// Example matches the operator.
1318/// \code
1319/// class X { operator int() const; };
1320/// \endcode
1321extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
1322 cxxConversionDecl;
1323
1324/// Matches user-defined and implicitly generated deduction guide.
1325///
1326/// Example matches the deduction guide.
1327/// \code
1328/// template<typename T>
1329/// class X { X(int) };
1330/// X(int) -> X<int>;
1331/// \endcode
1332extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
1333 cxxDeductionGuideDecl;
1334
1335/// Matches variable declarations.
1336///
1337/// Note: this does not match declarations of member variables, which are
1338/// "field" declarations in Clang parlance.
1339///
1340/// Example matches a
1341/// \code
1342/// int a;
1343/// \endcode
1344extern const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl;
1345
1346/// Matches field declarations.
1347///
1348/// Given
1349/// \code
1350/// class X { int m; };
1351/// \endcode
1352/// fieldDecl()
1353/// matches 'm'.
1354extern const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl;
1355
1356/// Matches indirect field declarations.
1357///
1358/// Given
1359/// \code
1360/// struct X { struct { int a; }; };
1361/// \endcode
1362/// indirectFieldDecl()
1363/// matches 'a'.
1364extern const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl>
1365 indirectFieldDecl;
1366
1367/// Matches function declarations.
1368///
1369/// Example matches f
1370/// \code
1371/// void f();
1372/// \endcode
1373extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl>
1374 functionDecl;
1375
1376/// Matches C++ function template declarations.
1377///
1378/// Example matches f
1379/// \code
1380/// template<class T> void f(T t) {}
1381/// \endcode
1382extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl>
1383 functionTemplateDecl;
1384
1385/// Matches friend declarations.
1386///
1387/// Given
1388/// \code
1389/// class X { friend void foo(); };
1390/// \endcode
1391/// friendDecl()
1392/// matches 'friend void foo()'.
1393extern const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl;
1394
1395/// Matches statements.
1396///
1397/// Given
1398/// \code
1399/// { ++a; }
1400/// \endcode
1401/// stmt()
1402/// matches both the compound statement '{ ++a; }' and '++a'.
1403extern const internal::VariadicAllOfMatcher<Stmt> stmt;
1404
1405/// Matches declaration statements.
1406///
1407/// Given
1408/// \code
1409/// int a;
1410/// \endcode
1411/// declStmt()
1412/// matches 'int a'.
1413extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt;
1414
1415/// Matches member expressions.
1416///
1417/// Given
1418/// \code
1419/// class Y {
1420/// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
1421/// int a; static int b;
1422/// };
1423/// \endcode
1424/// memberExpr()
1425/// matches this->x, x, y.x, a, this->b
1426extern const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr;
1427
1428/// Matches unresolved member expressions.
1429///
1430/// Given
1431/// \code
1432/// struct X {
1433/// template <class T> void f();
1434/// void g();
1435/// };
1436/// template <class T> void h() { X x; x.f<T>(); x.g(); }
1437/// \endcode
1438/// unresolvedMemberExpr()
1439/// matches x.f<T>
1440extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr>
1441 unresolvedMemberExpr;
1442
1443/// Matches member expressions where the actual member referenced could not be
1444/// resolved because the base expression or the member name was dependent.
1445///
1446/// Given
1447/// \code
1448/// template <class T> void f() { T t; t.g(); }
1449/// \endcode
1450/// cxxDependentScopeMemberExpr()
1451/// matches t.g
1452extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1453 CXXDependentScopeMemberExpr>
1454 cxxDependentScopeMemberExpr;
1455
1456/// Matches call expressions.
1457///
1458/// Example matches x.y() and y()
1459/// \code
1460/// X x;
1461/// x.y();
1462/// y();
1463/// \endcode
1464extern const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr;
1465
1466/// Matches call expressions which were resolved using ADL.
1467///
1468/// Example matches y(x) but not y(42) or NS::y(x).
1469/// \code
1470/// namespace NS {
1471/// struct X {};
1472/// void y(X);
1473/// }
1474///
1475/// void y(...);
1476///
1477/// void test() {
1478/// NS::X x;
1479/// y(x); // Matches
1480/// NS::y(x); // Doesn't match
1481/// y(42); // Doesn't match
1482/// using NS::y;
1483/// y(x); // Found by both unqualified lookup and ADL, doesn't match
1484// }
1485/// \endcode
1486AST_MATCHER(CallExpr, usesADL)namespace internal { class matcher_usesADLMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CallExpr>
{ public: explicit matcher_usesADLMatcher() = default; bool matches
(const CallExpr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<CallExpr> usesADL() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_usesADLMatcher
()); } inline bool internal::matcher_usesADLMatcher::matches(
const CallExpr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.usesADL(); }
1487
1488/// Matches lambda expressions.
1489///
1490/// Example matches [&](){return 5;}
1491/// \code
1492/// [&](){return 5;}
1493/// \endcode
1494extern const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr;
1495
1496/// Matches member call expressions.
1497///
1498/// Example matches x.y()
1499/// \code
1500/// X x;
1501/// x.y();
1502/// \endcode
1503extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr>
1504 cxxMemberCallExpr;
1505
1506/// Matches ObjectiveC Message invocation expressions.
1507///
1508/// The innermost message send invokes the "alloc" class method on the
1509/// NSString class, while the outermost message send invokes the
1510/// "initWithString" instance method on the object returned from
1511/// NSString's "alloc". This matcher should match both message sends.
1512/// \code
1513/// [[NSString alloc] initWithString:@"Hello"]
1514/// \endcode
1515extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
1516 objcMessageExpr;
1517
1518/// Matches Objective-C interface declarations.
1519///
1520/// Example matches Foo
1521/// \code
1522/// @interface Foo
1523/// @end
1524/// \endcode
1525extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl>
1526 objcInterfaceDecl;
1527
1528/// Matches Objective-C implementation declarations.
1529///
1530/// Example matches Foo
1531/// \code
1532/// @implementation Foo
1533/// @end
1534/// \endcode
1535extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl>
1536 objcImplementationDecl;
1537
1538/// Matches Objective-C protocol declarations.
1539///
1540/// Example matches FooDelegate
1541/// \code
1542/// @protocol FooDelegate
1543/// @end
1544/// \endcode
1545extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl>
1546 objcProtocolDecl;
1547
1548/// Matches Objective-C category declarations.
1549///
1550/// Example matches Foo (Additions)
1551/// \code
1552/// @interface Foo (Additions)
1553/// @end
1554/// \endcode
1555extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl>
1556 objcCategoryDecl;
1557
1558/// Matches Objective-C category definitions.
1559///
1560/// Example matches Foo (Additions)
1561/// \code
1562/// @implementation Foo (Additions)
1563/// @end
1564/// \endcode
1565extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl>
1566 objcCategoryImplDecl;
1567
1568/// Matches Objective-C method declarations.
1569///
1570/// Example matches both declaration and definition of -[Foo method]
1571/// \code
1572/// @interface Foo
1573/// - (void)method;
1574/// @end
1575///
1576/// @implementation Foo
1577/// - (void)method {}
1578/// @end
1579/// \endcode
1580extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl>
1581 objcMethodDecl;
1582
1583/// Matches block declarations.
1584///
1585/// Example matches the declaration of the nameless block printing an input
1586/// integer.
1587///
1588/// \code
1589/// myFunc(^(int p) {
1590/// printf("%d", p);
1591/// })
1592/// \endcode
1593extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl>
1594 blockDecl;
1595
1596/// Matches Objective-C instance variable declarations.
1597///
1598/// Example matches _enabled
1599/// \code
1600/// @implementation Foo {
1601/// BOOL _enabled;
1602/// }
1603/// @end
1604/// \endcode
1605extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl>
1606 objcIvarDecl;
1607
1608/// Matches Objective-C property declarations.
1609///
1610/// Example matches enabled
1611/// \code
1612/// @interface Foo
1613/// @property BOOL enabled;
1614/// @end
1615/// \endcode
1616extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl>
1617 objcPropertyDecl;
1618
1619/// Matches Objective-C \@throw statements.
1620///
1621/// Example matches \@throw
1622/// \code
1623/// @throw obj;
1624/// \endcode
1625extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt>
1626 objcThrowStmt;
1627
1628/// Matches Objective-C @try statements.
1629///
1630/// Example matches @try
1631/// \code
1632/// @try {}
1633/// @catch (...) {}
1634/// \endcode
1635extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt>
1636 objcTryStmt;
1637
1638/// Matches Objective-C @catch statements.
1639///
1640/// Example matches @catch
1641/// \code
1642/// @try {}
1643/// @catch (...) {}
1644/// \endcode
1645extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt>
1646 objcCatchStmt;
1647
1648/// Matches Objective-C @finally statements.
1649///
1650/// Example matches @finally
1651/// \code
1652/// @try {}
1653/// @finally {}
1654/// \endcode
1655extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt>
1656 objcFinallyStmt;
1657
1658/// Matches expressions that introduce cleanups to be run at the end
1659/// of the sub-expression's evaluation.
1660///
1661/// Example matches std::string()
1662/// \code
1663/// const std::string str = std::string();
1664/// \endcode
1665extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
1666 exprWithCleanups;
1667
1668/// Matches init list expressions.
1669///
1670/// Given
1671/// \code
1672/// int a[] = { 1, 2 };
1673/// struct B { int x, y; };
1674/// B b = { 5, 6 };
1675/// \endcode
1676/// initListExpr()
1677/// matches "{ 1, 2 }" and "{ 5, 6 }"
1678extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr>
1679 initListExpr;
1680
1681/// Matches the syntactic form of init list expressions
1682/// (if expression have it).
1683AST_MATCHER_P(InitListExpr, hasSyntacticForm,namespace internal { class matcher_hasSyntacticForm0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
InitListExpr> { public: explicit matcher_hasSyntacticForm0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const InitListExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<InitListExpr
> hasSyntacticForm( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasSyntacticForm0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<InitListExpr
> ( &hasSyntacticForm_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasSyntacticForm0Matcher
::matches( const InitListExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1684 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasSyntacticForm0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
InitListExpr> { public: explicit matcher_hasSyntacticForm0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const InitListExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<InitListExpr
> hasSyntacticForm( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasSyntacticForm0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<InitListExpr
> ( &hasSyntacticForm_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasSyntacticForm0Matcher
::matches( const InitListExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1685 const Expr *SyntForm = Node.getSyntacticForm();
1686 return (SyntForm != nullptr &&
1687 InnerMatcher.matches(*SyntForm, Finder, Builder));
1688}
1689
1690/// Matches C++ initializer list expressions.
1691///
1692/// Given
1693/// \code
1694/// std::vector<int> a({ 1, 2, 3 });
1695/// std::vector<int> b = { 4, 5 };
1696/// int c[] = { 6, 7 };
1697/// std::pair<int, int> d = { 8, 9 };
1698/// \endcode
1699/// cxxStdInitializerListExpr()
1700/// matches "{ 1, 2, 3 }" and "{ 4, 5 }"
1701extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1702 CXXStdInitializerListExpr>
1703 cxxStdInitializerListExpr;
1704
1705/// Matches implicit initializers of init list expressions.
1706///
1707/// Given
1708/// \code
1709/// point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
1710/// \endcode
1711/// implicitValueInitExpr()
1712/// matches "[0].y" (implicitly)
1713extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr>
1714 implicitValueInitExpr;
1715
1716/// Matches paren list expressions.
1717/// ParenListExprs don't have a predefined type and are used for late parsing.
1718/// In the final AST, they can be met in template declarations.
1719///
1720/// Given
1721/// \code
1722/// template<typename T> class X {
1723/// void f() {
1724/// X x(*this);
1725/// int a = 0, b = 1; int i = (a, b);
1726/// }
1727/// };
1728/// \endcode
1729/// parenListExpr() matches "*this" but NOT matches (a, b) because (a, b)
1730/// has a predefined type and is a ParenExpr, not a ParenListExpr.
1731extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr>
1732 parenListExpr;
1733
1734/// Matches substitutions of non-type template parameters.
1735///
1736/// Given
1737/// \code
1738/// template <int N>
1739/// struct A { static const int n = N; };
1740/// struct B : public A<42> {};
1741/// \endcode
1742/// substNonTypeTemplateParmExpr()
1743/// matches "N" in the right-hand side of "static const int n = N;"
1744extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1745 SubstNonTypeTemplateParmExpr>
1746 substNonTypeTemplateParmExpr;
1747
1748/// Matches using declarations.
1749///
1750/// Given
1751/// \code
1752/// namespace X { int x; }
1753/// using X::x;
1754/// \endcode
1755/// usingDecl()
1756/// matches \code using X::x \endcode
1757extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl;
1758
1759/// Matches using-enum declarations.
1760///
1761/// Given
1762/// \code
1763/// namespace X { enum x {...}; }
1764/// using enum X::x;
1765/// \endcode
1766/// usingEnumDecl()
1767/// matches \code using enum X::x \endcode
1768extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl>
1769 usingEnumDecl;
1770
1771/// Matches using namespace declarations.
1772///
1773/// Given
1774/// \code
1775/// namespace X { int x; }
1776/// using namespace X;
1777/// \endcode
1778/// usingDirectiveDecl()
1779/// matches \code using namespace X \endcode
1780extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
1781 usingDirectiveDecl;
1782
1783/// Matches reference to a name that can be looked up during parsing
1784/// but could not be resolved to a specific declaration.
1785///
1786/// Given
1787/// \code
1788/// template<typename T>
1789/// T foo() { T a; return a; }
1790/// template<typename T>
1791/// void bar() {
1792/// foo<T>();
1793/// }
1794/// \endcode
1795/// unresolvedLookupExpr()
1796/// matches \code foo<T>() \endcode
1797extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
1798 unresolvedLookupExpr;
1799
1800/// Matches unresolved using value declarations.
1801///
1802/// Given
1803/// \code
1804/// template<typename X>
1805/// class C : private X {
1806/// using X::x;
1807/// };
1808/// \endcode
1809/// unresolvedUsingValueDecl()
1810/// matches \code using X::x \endcode
1811extern const internal::VariadicDynCastAllOfMatcher<Decl,
1812 UnresolvedUsingValueDecl>
1813 unresolvedUsingValueDecl;
1814
1815/// Matches unresolved using value declarations that involve the
1816/// typename.
1817///
1818/// Given
1819/// \code
1820/// template <typename T>
1821/// struct Base { typedef T Foo; };
1822///
1823/// template<typename T>
1824/// struct S : private Base<T> {
1825/// using typename Base<T>::Foo;
1826/// };
1827/// \endcode
1828/// unresolvedUsingTypenameDecl()
1829/// matches \code using Base<T>::Foo \endcode
1830extern const internal::VariadicDynCastAllOfMatcher<Decl,
1831 UnresolvedUsingTypenameDecl>
1832 unresolvedUsingTypenameDecl;
1833
1834/// Matches a constant expression wrapper.
1835///
1836/// Example matches the constant in the case statement:
1837/// (matcher = constantExpr())
1838/// \code
1839/// switch (a) {
1840/// case 37: break;
1841/// }
1842/// \endcode
1843extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr>
1844 constantExpr;
1845
1846/// Matches parentheses used in expressions.
1847///
1848/// Example matches (foo() + 1)
1849/// \code
1850/// int foo() { return 1; }
1851/// int a = (foo() + 1);
1852/// \endcode
1853extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr;
1854
1855/// Matches constructor call expressions (including implicit ones).
1856///
1857/// Example matches string(ptr, n) and ptr within arguments of f
1858/// (matcher = cxxConstructExpr())
1859/// \code
1860/// void f(const string &a, const string &b);
1861/// char *ptr;
1862/// int n;
1863/// f(string(ptr, n), ptr);
1864/// \endcode
1865extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr>
1866 cxxConstructExpr;
1867
1868/// Matches unresolved constructor call expressions.
1869///
1870/// Example matches T(t) in return statement of f
1871/// (matcher = cxxUnresolvedConstructExpr())
1872/// \code
1873/// template <typename T>
1874/// void f(const T& t) { return T(t); }
1875/// \endcode
1876extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1877 CXXUnresolvedConstructExpr>
1878 cxxUnresolvedConstructExpr;
1879
1880/// Matches implicit and explicit this expressions.
1881///
1882/// Example matches the implicit this expression in "return i".
1883/// (matcher = cxxThisExpr())
1884/// \code
1885/// struct foo {
1886/// int i;
1887/// int f() { return i; }
1888/// };
1889/// \endcode
1890extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr>
1891 cxxThisExpr;
1892
1893/// Matches nodes where temporaries are created.
1894///
1895/// Example matches FunctionTakesString(GetStringByValue())
1896/// (matcher = cxxBindTemporaryExpr())
1897/// \code
1898/// FunctionTakesString(GetStringByValue());
1899/// FunctionTakesStringByPointer(GetStringPointer());
1900/// \endcode
1901extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr>
1902 cxxBindTemporaryExpr;
1903
1904/// Matches nodes where temporaries are materialized.
1905///
1906/// Example: Given
1907/// \code
1908/// struct T {void func();};
1909/// T f();
1910/// void g(T);
1911/// \endcode
1912/// materializeTemporaryExpr() matches 'f()' in these statements
1913/// \code
1914/// T u(f());
1915/// g(f());
1916/// f().func();
1917/// \endcode
1918/// but does not match
1919/// \code
1920/// f();
1921/// \endcode
1922extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1923 MaterializeTemporaryExpr>
1924 materializeTemporaryExpr;
1925
1926/// Matches new expressions.
1927///
1928/// Given
1929/// \code
1930/// new X;
1931/// \endcode
1932/// cxxNewExpr()
1933/// matches 'new X'.
1934extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
1935
1936/// Matches delete expressions.
1937///
1938/// Given
1939/// \code
1940/// delete X;
1941/// \endcode
1942/// cxxDeleteExpr()
1943/// matches 'delete X'.
1944extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr>
1945 cxxDeleteExpr;
1946
1947/// Matches noexcept expressions.
1948///
1949/// Given
1950/// \code
1951/// bool a() noexcept;
1952/// bool b() noexcept(true);
1953/// bool c() noexcept(false);
1954/// bool d() noexcept(noexcept(a()));
1955/// bool e = noexcept(b()) || noexcept(c());
1956/// \endcode
1957/// cxxNoexceptExpr()
1958/// matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`.
1959/// doesn't match the noexcept specifier in the declarations a, b, c or d.
1960extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
1961 cxxNoexceptExpr;
1962
1963/// Matches array subscript expressions.
1964///
1965/// Given
1966/// \code
1967/// int i = a[1];
1968/// \endcode
1969/// arraySubscriptExpr()
1970/// matches "a[1]"
1971extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
1972 arraySubscriptExpr;
1973
1974/// Matches the value of a default argument at the call site.
1975///
1976/// Example matches the CXXDefaultArgExpr placeholder inserted for the
1977/// default value of the second parameter in the call expression f(42)
1978/// (matcher = cxxDefaultArgExpr())
1979/// \code
1980/// void f(int x, int y = 0);
1981/// f(42);
1982/// \endcode
1983extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
1984 cxxDefaultArgExpr;
1985
1986/// Matches overloaded operator calls.
1987///
1988/// Note that if an operator isn't overloaded, it won't match. Instead, use
1989/// binaryOperator matcher.
1990/// Currently it does not match operators such as new delete.
1991/// FIXME: figure out why these do not match?
1992///
1993/// Example matches both operator<<((o << b), c) and operator<<(o, b)
1994/// (matcher = cxxOperatorCallExpr())
1995/// \code
1996/// ostream &operator<< (ostream &out, int i) { };
1997/// ostream &o; int b = 1, c = 1;
1998/// o << b << c;
1999/// \endcode
2000/// See also the binaryOperation() matcher for more-general matching of binary
2001/// uses of this AST node.
2002extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
2003 cxxOperatorCallExpr;
2004
2005/// Matches rewritten binary operators
2006///
2007/// Example matches use of "<":
2008/// \code
2009/// #include <compare>
2010/// struct HasSpaceshipMem {
2011/// int a;
2012/// constexpr auto operator<=>(const HasSpaceshipMem&) const = default;
2013/// };
2014/// void compare() {
2015/// HasSpaceshipMem hs1, hs2;
2016/// if (hs1 < hs2)
2017/// return;
2018/// }
2019/// \endcode
2020/// See also the binaryOperation() matcher for more-general matching
2021/// of this AST node.
2022extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2023 CXXRewrittenBinaryOperator>
2024 cxxRewrittenBinaryOperator;
2025
2026/// Matches expressions.
2027///
2028/// Example matches x()
2029/// \code
2030/// void f() { x(); }
2031/// \endcode
2032extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr;
2033
2034/// Matches expressions that refer to declarations.
2035///
2036/// Example matches x in if (x)
2037/// \code
2038/// bool x;
2039/// if (x) {}
2040/// \endcode
2041extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr>
2042 declRefExpr;
2043
2044/// Matches a reference to an ObjCIvar.
2045///
2046/// Example: matches "a" in "init" method:
2047/// \code
2048/// @implementation A {
2049/// NSString *a;
2050/// }
2051/// - (void) init {
2052/// a = @"hello";
2053/// }
2054/// \endcode
2055extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr>
2056 objcIvarRefExpr;
2057
2058/// Matches a reference to a block.
2059///
2060/// Example: matches "^{}":
2061/// \code
2062/// void f() { ^{}(); }
2063/// \endcode
2064extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
2065
2066/// Matches if statements.
2067///
2068/// Example matches 'if (x) {}'
2069/// \code
2070/// if (x) {}
2071/// \endcode
2072extern const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt;
2073
2074/// Matches for statements.
2075///
2076/// Example matches 'for (;;) {}'
2077/// \code
2078/// for (;;) {}
2079/// int i[] = {1, 2, 3}; for (auto a : i);
2080/// \endcode
2081extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt;
2082
2083/// Matches the increment statement of a for loop.
2084///
2085/// Example:
2086/// forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
2087/// matches '++x' in
2088/// \code
2089/// for (x; x < N; ++x) { }
2090/// \endcode
2091AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>,namespace internal { class matcher_hasIncrement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasIncrement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasIncrement
( internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIncrement0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasIncrement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasIncrement0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
2092 InnerMatcher)namespace internal { class matcher_hasIncrement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasIncrement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasIncrement
( internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIncrement0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasIncrement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasIncrement0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2093 const Stmt *const Increment = Node.getInc();
2094 return (Increment != nullptr &&
2095 InnerMatcher.matches(*Increment, Finder, Builder));
2096}
2097
2098/// Matches the initialization statement of a for loop.
2099///
2100/// Example:
2101/// forStmt(hasLoopInit(declStmt()))
2102/// matches 'int x = 0' in
2103/// \code
2104/// for (int x = 0; x < N; ++x) { }
2105/// \endcode
2106AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>,namespace internal { class matcher_hasLoopInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasLoopInit0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasLoopInit(
internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasLoopInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasLoopInit_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasLoopInit0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
2107 InnerMatcher)namespace internal { class matcher_hasLoopInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasLoopInit0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasLoopInit(
internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasLoopInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasLoopInit_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasLoopInit0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2108 const Stmt *const Init = Node.getInit();
2109 return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder));
2110}
2111
2112/// Matches range-based for statements.
2113///
2114/// cxxForRangeStmt() matches 'for (auto a : i)'
2115/// \code
2116/// int i[] = {1, 2, 3}; for (auto a : i);
2117/// for(int j = 0; j < 5; ++j);
2118/// \endcode
2119extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
2120 cxxForRangeStmt;
2121
2122/// Matches the initialization statement of a for loop.
2123///
2124/// Example:
2125/// forStmt(hasLoopVariable(anything()))
2126/// matches 'int x' in
2127/// \code
2128/// for (int x : a) { }
2129/// \endcode
2130AST_MATCHER_P(CXXForRangeStmt, hasLoopVariable, internal::Matcher<VarDecl>,namespace internal { class matcher_hasLoopVariable0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasLoopVariable0Matcher( internal
::Matcher<VarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<VarDecl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasLoopVariable( internal::Matcher<VarDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasLoopVariable0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> ( &hasLoopVariable_Type0)(internal::Matcher<VarDecl
> const &InnerMatcher); inline bool internal::matcher_hasLoopVariable0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2131 InnerMatcher)namespace internal { class matcher_hasLoopVariable0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasLoopVariable0Matcher( internal
::Matcher<VarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<VarDecl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasLoopVariable( internal::Matcher<VarDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasLoopVariable0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> ( &hasLoopVariable_Type0)(internal::Matcher<VarDecl
> const &InnerMatcher); inline bool internal::matcher_hasLoopVariable0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2132 const VarDecl *const Var = Node.getLoopVariable();
2133 return (Var != nullptr && InnerMatcher.matches(*Var, Finder, Builder));
2134}
2135
2136/// Matches the range initialization statement of a for loop.
2137///
2138/// Example:
2139/// forStmt(hasRangeInit(anything()))
2140/// matches 'a' in
2141/// \code
2142/// for (int x : a) { }
2143/// \endcode
2144AST_MATCHER_P(CXXForRangeStmt, hasRangeInit, internal::Matcher<Expr>,namespace internal { class matcher_hasRangeInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasRangeInit0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasRangeInit( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasRangeInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CXXForRangeStmt> ( &
hasRangeInit_Type0)(internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasRangeInit0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2145 InnerMatcher)namespace internal { class matcher_hasRangeInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasRangeInit0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasRangeInit( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasRangeInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CXXForRangeStmt> ( &
hasRangeInit_Type0)(internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasRangeInit0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2146 const Expr *const Init = Node.getRangeInit();
2147 return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder));
2148}
2149
2150/// Matches while statements.
2151///
2152/// Given
2153/// \code
2154/// while (true) {}
2155/// \endcode
2156/// whileStmt()
2157/// matches 'while (true) {}'.
2158extern const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt;
2159
2160/// Matches do statements.
2161///
2162/// Given
2163/// \code
2164/// do {} while (true);
2165/// \endcode
2166/// doStmt()
2167/// matches 'do {} while(true)'
2168extern const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt;
2169
2170/// Matches break statements.
2171///
2172/// Given
2173/// \code
2174/// while (true) { break; }
2175/// \endcode
2176/// breakStmt()
2177/// matches 'break'
2178extern const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt;
2179
2180/// Matches continue statements.
2181///
2182/// Given
2183/// \code
2184/// while (true) { continue; }
2185/// \endcode
2186/// continueStmt()
2187/// matches 'continue'
2188extern const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt>
2189 continueStmt;
2190
2191/// Matches co_return statements.
2192///
2193/// Given
2194/// \code
2195/// while (true) { co_return; }
2196/// \endcode
2197/// coreturnStmt()
2198/// matches 'co_return'
2199extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt>
2200 coreturnStmt;
2201
2202/// Matches return statements.
2203///
2204/// Given
2205/// \code
2206/// return 1;
2207/// \endcode
2208/// returnStmt()
2209/// matches 'return 1'
2210extern const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt;
2211
2212/// Matches goto statements.
2213///
2214/// Given
2215/// \code
2216/// goto FOO;
2217/// FOO: bar();
2218/// \endcode
2219/// gotoStmt()
2220/// matches 'goto FOO'
2221extern const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt;
2222
2223/// Matches label statements.
2224///
2225/// Given
2226/// \code
2227/// goto FOO;
2228/// FOO: bar();
2229/// \endcode
2230/// labelStmt()
2231/// matches 'FOO:'
2232extern const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt;
2233
2234/// Matches address of label statements (GNU extension).
2235///
2236/// Given
2237/// \code
2238/// FOO: bar();
2239/// void *ptr = &&FOO;
2240/// goto *bar;
2241/// \endcode
2242/// addrLabelExpr()
2243/// matches '&&FOO'
2244extern const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr>
2245 addrLabelExpr;
2246
2247/// Matches switch statements.
2248///
2249/// Given
2250/// \code
2251/// switch(a) { case 42: break; default: break; }
2252/// \endcode
2253/// switchStmt()
2254/// matches 'switch(a)'.
2255extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt;
2256
2257/// Matches case and default statements inside switch statements.
2258///
2259/// Given
2260/// \code
2261/// switch(a) { case 42: break; default: break; }
2262/// \endcode
2263/// switchCase()
2264/// matches 'case 42:' and 'default:'.
2265extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase;
2266
2267/// Matches case statements inside switch statements.
2268///
2269/// Given
2270/// \code
2271/// switch(a) { case 42: break; default: break; }
2272/// \endcode
2273/// caseStmt()
2274/// matches 'case 42:'.
2275extern const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt;
2276
2277/// Matches default statements inside switch statements.
2278///
2279/// Given
2280/// \code
2281/// switch(a) { case 42: break; default: break; }
2282/// \endcode
2283/// defaultStmt()
2284/// matches 'default:'.
2285extern const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt>
2286 defaultStmt;
2287
2288/// Matches compound statements.
2289///
2290/// Example matches '{}' and '{{}}' in 'for (;;) {{}}'
2291/// \code
2292/// for (;;) {{}}
2293/// \endcode
2294extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt>
2295 compoundStmt;
2296
2297/// Matches catch statements.
2298///
2299/// \code
2300/// try {} catch(int i) {}
2301/// \endcode
2302/// cxxCatchStmt()
2303/// matches 'catch(int i)'
2304extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt>
2305 cxxCatchStmt;
2306
2307/// Matches try statements.
2308///
2309/// \code
2310/// try {} catch(int i) {}
2311/// \endcode
2312/// cxxTryStmt()
2313/// matches 'try {}'
2314extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
2315
2316/// Matches throw expressions.
2317///
2318/// \code
2319/// try { throw 5; } catch(int i) {}
2320/// \endcode
2321/// cxxThrowExpr()
2322/// matches 'throw 5'
2323extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr>
2324 cxxThrowExpr;
2325
2326/// Matches null statements.
2327///
2328/// \code
2329/// foo();;
2330/// \endcode
2331/// nullStmt()
2332/// matches the second ';'
2333extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
2334
2335/// Matches asm statements.
2336///
2337/// \code
2338/// int i = 100;
2339/// __asm("mov al, 2");
2340/// \endcode
2341/// asmStmt()
2342/// matches '__asm("mov al, 2")'
2343extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
2344
2345/// Matches bool literals.
2346///
2347/// Example matches true
2348/// \code
2349/// true
2350/// \endcode
2351extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
2352 cxxBoolLiteral;
2353
2354/// Matches string literals (also matches wide string literals).
2355///
2356/// Example matches "abcd", L"abcd"
2357/// \code
2358/// char *s = "abcd";
2359/// wchar_t *ws = L"abcd";
2360/// \endcode
2361extern const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral>
2362 stringLiteral;
2363
2364/// Matches character literals (also matches wchar_t).
2365///
2366/// Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
2367/// though.
2368///
2369/// Example matches 'a', L'a'
2370/// \code
2371/// char ch = 'a';
2372/// wchar_t chw = L'a';
2373/// \endcode
2374extern const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
2375 characterLiteral;
2376
2377/// Matches integer literals of all sizes / encodings, e.g.
2378/// 1, 1L, 0x1 and 1U.
2379///
2380/// Does not match character-encoded integers such as L'a'.
2381extern const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
2382 integerLiteral;
2383
2384/// Matches float literals of all sizes / encodings, e.g.
2385/// 1.0, 1.0f, 1.0L and 1e10.
2386///
2387/// Does not match implicit conversions such as
2388/// \code
2389/// float a = 10;
2390/// \endcode
2391extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral>
2392 floatLiteral;
2393
2394/// Matches imaginary literals, which are based on integer and floating
2395/// point literals e.g.: 1i, 1.0i
2396extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral>
2397 imaginaryLiteral;
2398
2399/// Matches fixed point literals
2400extern const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
2401 fixedPointLiteral;
2402
2403/// Matches user defined literal operator call.
2404///
2405/// Example match: "foo"_suffix
2406extern const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
2407 userDefinedLiteral;
2408
2409/// Matches compound (i.e. non-scalar) literals
2410///
2411/// Example match: {1}, (1, 2)
2412/// \code
2413/// int array[4] = {1};
2414/// vector int myvec = (vector int)(1, 2);
2415/// \endcode
2416extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>
2417 compoundLiteralExpr;
2418
2419/// Matches co_await expressions.
2420///
2421/// Given
2422/// \code
2423/// co_await 1;
2424/// \endcode
2425/// coawaitExpr()
2426/// matches 'co_await 1'
2427extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr>
2428 coawaitExpr;
2429/// Matches co_await expressions where the type of the promise is dependent
2430extern const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr>
2431 dependentCoawaitExpr;
2432/// Matches co_yield expressions.
2433///
2434/// Given
2435/// \code
2436/// co_yield 1;
2437/// \endcode
2438/// coyieldExpr()
2439/// matches 'co_yield 1'
2440extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr>
2441 coyieldExpr;
2442
2443/// Matches nullptr literal.
2444extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
2445 cxxNullPtrLiteralExpr;
2446
2447/// Matches GNU __builtin_choose_expr.
2448extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr>
2449 chooseExpr;
2450
2451/// Matches GNU __null expression.
2452extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr>
2453 gnuNullExpr;
2454
2455/// Matches C11 _Generic expression.
2456extern const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
2457 genericSelectionExpr;
2458
2459/// Matches atomic builtins.
2460/// Example matches __atomic_load_n(ptr, 1)
2461/// \code
2462/// void foo() { int *ptr; __atomic_load_n(ptr, 1); }
2463/// \endcode
2464extern const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr;
2465
2466/// Matches statement expression (GNU extension).
2467///
2468/// Example match: ({ int X = 4; X; })
2469/// \code
2470/// int C = ({ int X = 4; X; });
2471/// \endcode
2472extern const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr;
2473
2474/// Matches binary operator expressions.
2475///
2476/// Example matches a || b
2477/// \code
2478/// !(a || b)
2479/// \endcode
2480/// See also the binaryOperation() matcher for more-general matching.
2481extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
2482 binaryOperator;
2483
2484/// Matches unary operator expressions.
2485///
2486/// Example matches !a
2487/// \code
2488/// !a || b
2489/// \endcode
2490extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator>
2491 unaryOperator;
2492
2493/// Matches conditional operator expressions.
2494///
2495/// Example matches a ? b : c
2496/// \code
2497/// (a ? b : c) + 42
2498/// \endcode
2499extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator>
2500 conditionalOperator;
2501
2502/// Matches binary conditional operator expressions (GNU extension).
2503///
2504/// Example matches a ?: b
2505/// \code
2506/// (a ?: b) + 42;
2507/// \endcode
2508extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2509 BinaryConditionalOperator>
2510 binaryConditionalOperator;
2511
2512/// Matches opaque value expressions. They are used as helpers
2513/// to reference another expressions and can be met
2514/// in BinaryConditionalOperators, for example.
2515///
2516/// Example matches 'a'
2517/// \code
2518/// (a ?: c) + 42;
2519/// \endcode
2520extern const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr>
2521 opaqueValueExpr;
2522
2523/// Matches a C++ static_assert declaration.
2524///
2525/// Example:
2526/// staticAssertExpr()
2527/// matches
2528/// static_assert(sizeof(S) == sizeof(int))
2529/// in
2530/// \code
2531/// struct S {
2532/// int x;
2533/// };
2534/// static_assert(sizeof(S) == sizeof(int));
2535/// \endcode
2536extern const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl>
2537 staticAssertDecl;
2538
2539/// Matches a reinterpret_cast expression.
2540///
2541/// Either the source expression or the destination type can be matched
2542/// using has(), but hasDestinationType() is more specific and can be
2543/// more readable.
2544///
2545/// Example matches reinterpret_cast<char*>(&p) in
2546/// \code
2547/// void* p = reinterpret_cast<char*>(&p);
2548/// \endcode
2549extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr>
2550 cxxReinterpretCastExpr;
2551
2552/// Matches a C++ static_cast expression.
2553///
2554/// \see hasDestinationType
2555/// \see reinterpretCast
2556///
2557/// Example:
2558/// cxxStaticCastExpr()
2559/// matches
2560/// static_cast<long>(8)
2561/// in
2562/// \code
2563/// long eight(static_cast<long>(8));
2564/// \endcode
2565extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr>
2566 cxxStaticCastExpr;
2567
2568/// Matches a dynamic_cast expression.
2569///
2570/// Example:
2571/// cxxDynamicCastExpr()
2572/// matches
2573/// dynamic_cast<D*>(&b);
2574/// in
2575/// \code
2576/// struct B { virtual ~B() {} }; struct D : B {};
2577/// B b;
2578/// D* p = dynamic_cast<D*>(&b);
2579/// \endcode
2580extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
2581 cxxDynamicCastExpr;
2582
2583/// Matches a const_cast expression.
2584///
2585/// Example: Matches const_cast<int*>(&r) in
2586/// \code
2587/// int n = 42;
2588/// const int &r(n);
2589/// int* p = const_cast<int*>(&r);
2590/// \endcode
2591extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
2592 cxxConstCastExpr;
2593
2594/// Matches a C-style cast expression.
2595///
2596/// Example: Matches (int) 2.2f in
2597/// \code
2598/// int i = (int) 2.2f;
2599/// \endcode
2600extern const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
2601 cStyleCastExpr;
2602
2603/// Matches explicit cast expressions.
2604///
2605/// Matches any cast expression written in user code, whether it be a
2606/// C-style cast, a functional-style cast, or a keyword cast.
2607///
2608/// Does not match implicit conversions.
2609///
2610/// Note: the name "explicitCast" is chosen to match Clang's terminology, as
2611/// Clang uses the term "cast" to apply to implicit conversions as well as to
2612/// actual cast expressions.
2613///
2614/// \see hasDestinationType.
2615///
2616/// Example: matches all five of the casts in
2617/// \code
2618/// int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))
2619/// \endcode
2620/// but does not match the implicit conversion in
2621/// \code
2622/// long ell = 42;
2623/// \endcode
2624extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>
2625 explicitCastExpr;
2626
2627/// Matches the implicit cast nodes of Clang's AST.
2628///
2629/// This matches many different places, including function call return value
2630/// eliding, as well as any type conversions.
2631extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr>
2632 implicitCastExpr;
2633
2634/// Matches any cast nodes of Clang's AST.
2635///
2636/// Example: castExpr() matches each of the following:
2637/// \code
2638/// (int) 3;
2639/// const_cast<Expr *>(SubExpr);
2640/// char c = 0;
2641/// \endcode
2642/// but does not match
2643/// \code
2644/// int i = (0);
2645/// int k = 0;
2646/// \endcode
2647extern const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr;
2648
2649/// Matches functional cast expressions
2650///
2651/// Example: Matches Foo(bar);
2652/// \code
2653/// Foo f = bar;
2654/// Foo g = (Foo) bar;
2655/// Foo h = Foo(bar);
2656/// \endcode
2657extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr>
2658 cxxFunctionalCastExpr;
2659
2660/// Matches functional cast expressions having N != 1 arguments
2661///
2662/// Example: Matches Foo(bar, bar)
2663/// \code
2664/// Foo h = Foo(bar, bar);
2665/// \endcode
2666extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr>
2667 cxxTemporaryObjectExpr;
2668
2669/// Matches predefined identifier expressions [C99 6.4.2.2].
2670///
2671/// Example: Matches __func__
2672/// \code
2673/// printf("%s", __func__);
2674/// \endcode
2675extern const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr>
2676 predefinedExpr;
2677
2678/// Matches C99 designated initializer expressions [C99 6.7.8].
2679///
2680/// Example: Matches { [2].y = 1.0, [0].x = 1.0 }
2681/// \code
2682/// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
2683/// \endcode
2684extern const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
2685 designatedInitExpr;
2686
2687/// Matches designated initializer expressions that contain
2688/// a specific number of designators.
2689///
2690/// Example: Given
2691/// \code
2692/// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
2693/// point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 };
2694/// \endcode
2695/// designatorCountIs(2)
2696/// matches '{ [2].y = 1.0, [0].x = 1.0 }',
2697/// but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'.
2698AST_MATCHER_P(DesignatedInitExpr, designatorCountIs, unsigned, N)namespace internal { class matcher_designatorCountIs0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
DesignatedInitExpr> { public: explicit matcher_designatorCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const DesignatedInitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::Matcher<DesignatedInitExpr>
designatorCountIs( unsigned const &N) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_designatorCountIs0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<DesignatedInitExpr
> ( &designatorCountIs_Type0)(unsigned const &N); inline
bool internal::matcher_designatorCountIs0Matcher::matches( const
DesignatedInitExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2699 return Node.size() == N;
2700}
2701
2702/// Matches \c QualTypes in the clang AST.
2703extern const internal::VariadicAllOfMatcher<QualType> qualType;
2704
2705/// Matches \c Types in the clang AST.
2706extern const internal::VariadicAllOfMatcher<Type> type;
2707
2708/// Matches \c TypeLocs in the clang AST.
2709extern const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
2710
2711/// Matches if any of the given matchers matches.
2712///
2713/// Unlike \c anyOf, \c eachOf will generate a match result for each
2714/// matching submatcher.
2715///
2716/// For example, in:
2717/// \code
2718/// class A { int a; int b; };
2719/// \endcode
2720/// The matcher:
2721/// \code
2722/// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
2723/// has(fieldDecl(hasName("b")).bind("v"))))
2724/// \endcode
2725/// will generate two results binding "v", the first of which binds
2726/// the field declaration of \c a, the second the field declaration of
2727/// \c b.
2728///
2729/// Usable as: Any Matcher
2730extern const internal::VariadicOperatorMatcherFunc<
2731 2, std::numeric_limits<unsigned>::max()>
2732 eachOf;
2733
2734/// Matches if any of the given matchers matches.
2735///
2736/// Usable as: Any Matcher
2737extern const internal::VariadicOperatorMatcherFunc<
2738 2, std::numeric_limits<unsigned>::max()>
2739 anyOf;
2740
2741/// Matches if all given matchers match.
2742///
2743/// Usable as: Any Matcher
2744extern const internal::VariadicOperatorMatcherFunc<
2745 2, std::numeric_limits<unsigned>::max()>
2746 allOf;
2747
2748/// Matches any node regardless of the submatcher.
2749///
2750/// However, \c optionally will retain any bindings generated by the submatcher.
2751/// Useful when additional information which may or may not present about a main
2752/// matching node is desired.
2753///
2754/// For example, in:
2755/// \code
2756/// class Foo {
2757/// int bar;
2758/// }
2759/// \endcode
2760/// The matcher:
2761/// \code
2762/// cxxRecordDecl(
2763/// optionally(has(
2764/// fieldDecl(hasName("bar")).bind("var")
2765/// ))).bind("record")
2766/// \endcode
2767/// will produce a result binding for both "record" and "var".
2768/// The matcher will produce a "record" binding for even if there is no data
2769/// member named "bar" in that class.
2770///
2771/// Usable as: Any Matcher
2772extern const internal::VariadicOperatorMatcherFunc<1, 1> optionally;
2773
2774/// Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
2775///
2776/// Given
2777/// \code
2778/// Foo x = bar;
2779/// int y = sizeof(x) + alignof(x);
2780/// \endcode
2781/// unaryExprOrTypeTraitExpr()
2782/// matches \c sizeof(x) and \c alignof(x)
2783extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2784 UnaryExprOrTypeTraitExpr>
2785 unaryExprOrTypeTraitExpr;
2786
2787/// Matches any of the \p NodeMatchers with InnerMatchers nested within
2788///
2789/// Given
2790/// \code
2791/// if (true);
2792/// for (; true; );
2793/// \endcode
2794/// with the matcher
2795/// \code
2796/// mapAnyOf(ifStmt, forStmt).with(
2797/// hasCondition(cxxBoolLiteralExpr(equals(true)))
2798/// ).bind("trueCond")
2799/// \endcode
2800/// matches the \c if and the \c for. It is equivalent to:
2801/// \code
2802/// auto trueCond = hasCondition(cxxBoolLiteralExpr(equals(true)));
2803/// anyOf(
2804/// ifStmt(trueCond).bind("trueCond"),
2805/// forStmt(trueCond).bind("trueCond")
2806/// );
2807/// \endcode
2808///
2809/// The with() chain-call accepts zero or more matchers which are combined
2810/// as-if with allOf() in each of the node matchers.
2811/// Usable as: Any Matcher
2812template <typename T, typename... U>
2813auto mapAnyOf(internal::VariadicDynCastAllOfMatcher<T, U> const &...) {
2814 return internal::MapAnyOfHelper<U...>();
2815}
2816
2817/// Matches nodes which can be used with binary operators.
2818///
2819/// The code
2820/// \code
2821/// var1 != var2;
2822/// \endcode
2823/// might be represented in the clang AST as a binaryOperator, a
2824/// cxxOperatorCallExpr or a cxxRewrittenBinaryOperator, depending on
2825///
2826/// * whether the types of var1 and var2 are fundamental (binaryOperator) or at
2827/// least one is a class type (cxxOperatorCallExpr)
2828/// * whether the code appears in a template declaration, if at least one of the
2829/// vars is a dependent-type (binaryOperator)
2830/// * whether the code relies on a rewritten binary operator, such as a
2831/// spaceship operator or an inverted equality operator
2832/// (cxxRewrittenBinaryOperator)
2833///
2834/// This matcher elides details in places where the matchers for the nodes are
2835/// compatible.
2836///
2837/// Given
2838/// \code
2839/// binaryOperation(
2840/// hasOperatorName("!="),
2841/// hasLHS(expr().bind("lhs")),
2842/// hasRHS(expr().bind("rhs"))
2843/// )
2844/// \endcode
2845/// matches each use of "!=" in:
2846/// \code
2847/// struct S{
2848/// bool operator!=(const S&) const;
2849/// };
2850///
2851/// void foo()
2852/// {
2853/// 1 != 2;
2854/// S() != S();
2855/// }
2856///
2857/// template<typename T>
2858/// void templ()
2859/// {
2860/// 1 != 2;
2861/// T() != S();
2862/// }
2863/// struct HasOpEq
2864/// {
2865/// bool operator==(const HasOpEq &) const;
2866/// };
2867///
2868/// void inverse()
2869/// {
2870/// HasOpEq s1;
2871/// HasOpEq s2;
2872/// if (s1 != s2)
2873/// return;
2874/// }
2875///
2876/// struct HasSpaceship
2877/// {
2878/// bool operator<=>(const HasOpEq &) const;
2879/// };
2880///
2881/// void use_spaceship()
2882/// {
2883/// HasSpaceship s1;
2884/// HasSpaceship s2;
2885/// if (s1 != s2)
2886/// return;
2887/// }
2888/// \endcode
2889extern const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr,
2890 CXXRewrittenBinaryOperator>
2891 binaryOperation;
2892
2893/// Matches function calls and constructor calls
2894///
2895/// Because CallExpr and CXXConstructExpr do not share a common
2896/// base class with API accessing arguments etc, AST Matchers for code
2897/// which should match both are typically duplicated. This matcher
2898/// removes the need for duplication.
2899///
2900/// Given code
2901/// \code
2902/// struct ConstructorTakesInt
2903/// {
2904/// ConstructorTakesInt(int i) {}
2905/// };
2906///
2907/// void callTakesInt(int i)
2908/// {
2909/// }
2910///
2911/// void doCall()
2912/// {
2913/// callTakesInt(42);
2914/// }
2915///
2916/// void doConstruct()
2917/// {
2918/// ConstructorTakesInt cti(42);
2919/// }
2920/// \endcode
2921///
2922/// The matcher
2923/// \code
2924/// invocation(hasArgument(0, integerLiteral(equals(42))))
2925/// \endcode
2926/// matches the expression in both doCall and doConstruct
2927extern const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation;
2928
2929/// Matches unary expressions that have a specific type of argument.
2930///
2931/// Given
2932/// \code
2933/// int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
2934/// \endcode
2935/// unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
2936/// matches \c sizeof(a) and \c alignof(c)
2937AST_MATCHER_P(UnaryExprOrTypeTraitExpr, hasArgumentOfType,namespace internal { class matcher_hasArgumentOfType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
UnaryExprOrTypeTraitExpr> { public: explicit matcher_hasArgumentOfType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<UnaryExprOrTypeTraitExpr> hasArgumentOfType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasArgumentOfType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UnaryExprOrTypeTraitExpr> ( &hasArgumentOfType_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_hasArgumentOfType0Matcher::matches
( const UnaryExprOrTypeTraitExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2938 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_hasArgumentOfType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
UnaryExprOrTypeTraitExpr> { public: explicit matcher_hasArgumentOfType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<UnaryExprOrTypeTraitExpr> hasArgumentOfType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasArgumentOfType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UnaryExprOrTypeTraitExpr> ( &hasArgumentOfType_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_hasArgumentOfType0Matcher::matches
( const UnaryExprOrTypeTraitExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2939 const QualType ArgumentType = Node.getTypeOfArgument();
2940 return InnerMatcher.matches(ArgumentType, Finder, Builder);
2941}
2942
2943/// Matches unary expressions of a certain kind.
2944///
2945/// Given
2946/// \code
2947/// int x;
2948/// int s = sizeof(x) + alignof(x)
2949/// \endcode
2950/// unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
2951/// matches \c sizeof(x)
2952///
2953/// If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter
2954/// should be passed as a quoted string. e.g., ofKind("UETT_SizeOf").
2955AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind)namespace internal { class matcher_ofKind0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<UnaryExprOrTypeTraitExpr
> { public: explicit matcher_ofKind0Matcher( UnaryExprOrTypeTrait
const &AKind) : Kind(AKind) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: UnaryExprOrTypeTrait Kind
; }; } inline ::clang::ast_matchers::internal::Matcher<UnaryExprOrTypeTraitExpr
> ofKind( UnaryExprOrTypeTrait const &Kind) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_ofKind0Matcher
(Kind)); } typedef ::clang::ast_matchers::internal::Matcher<
UnaryExprOrTypeTraitExpr> ( &ofKind_Type0)(UnaryExprOrTypeTrait
const &Kind); inline bool internal::matcher_ofKind0Matcher
::matches( const UnaryExprOrTypeTraitExpr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
2956 return Node.getKind() == Kind;
2957}
2958
2959/// Same as unaryExprOrTypeTraitExpr, but only matching
2960/// alignof.
2961inline internal::BindableMatcher<Stmt> alignOfExpr(
2962 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
2963 return stmt(unaryExprOrTypeTraitExpr(
2964 allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)),
2965 InnerMatcher)));
2966}
2967
2968/// Same as unaryExprOrTypeTraitExpr, but only matching
2969/// sizeof.
2970inline internal::BindableMatcher<Stmt> sizeOfExpr(
2971 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
2972 return stmt(unaryExprOrTypeTraitExpr(
2973 allOf(ofKind(UETT_SizeOf), InnerMatcher)));
2974}
2975
2976/// Matches NamedDecl nodes that have the specified name.
2977///
2978/// Supports specifying enclosing namespaces or classes by prefixing the name
2979/// with '<enclosing>::'.
2980/// Does not match typedefs of an underlying type with the given name.
2981///
2982/// Example matches X (Name == "X")
2983/// \code
2984/// class X;
2985/// \endcode
2986///
2987/// Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
2988/// \code
2989/// namespace a { namespace b { class X; } }
2990/// \endcode
2991inline internal::Matcher<NamedDecl> hasName(StringRef Name) {
2992 return internal::Matcher<NamedDecl>(
2993 new internal::HasNameMatcher({std::string(Name)}));
2994}
2995
2996/// Matches NamedDecl nodes that have any of the specified names.
2997///
2998/// This matcher is only provided as a performance optimization of hasName.
2999/// \code
3000/// hasAnyName(a, b, c)
3001/// \endcode
3002/// is equivalent to, but faster than
3003/// \code
3004/// anyOf(hasName(a), hasName(b), hasName(c))
3005/// \endcode
3006extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
3007 internal::hasAnyNameFunc>
3008 hasAnyName;
3009
3010/// Matches NamedDecl nodes whose fully qualified names contain
3011/// a substring matched by the given RegExp.
3012///
3013/// Supports specifying enclosing namespaces or classes by
3014/// prefixing the name with '<enclosing>::'. Does not match typedefs
3015/// of an underlying type with the given name.
3016///
3017/// Example matches X (regexp == "::X")
3018/// \code
3019/// class X;
3020/// \endcode
3021///
3022/// Example matches X (regexp is one of "::X", "^foo::.*X", among others)
3023/// \code
3024/// namespace foo { namespace bar { class X; } }
3025/// \endcode
3026AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp)namespace internal { class matcher_matchesName0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NamedDecl
> { public: explicit matcher_matchesName0Matcher( std::shared_ptr
<llvm::Regex> RE) : RegExp(std::move(RE)) {} bool matches
(const NamedDecl &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::shared_ptr<llvm::
Regex> RegExp; }; } inline ::clang::ast_matchers::internal
::Matcher<NamedDecl> matchesName( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_matchesName0Matcher
( ::clang::ast_matchers::internal::createAndVerifyRegex( RegExp
, RegexFlags, "matchesName"))); } inline ::clang::ast_matchers
::internal::Matcher<NamedDecl> matchesName( llvm::StringRef
RegExp) { return matchesName(RegExp, llvm::Regex::NoFlags); }
typedef ::clang::ast_matchers::internal::Matcher<NamedDecl
> ( &matchesName_Type0Flags)(llvm::StringRef, llvm::Regex
::RegexFlags); typedef ::clang::ast_matchers::internal::Matcher
<NamedDecl> ( &matchesName_Type0)(llvm::StringRef);
inline bool internal::matcher_matchesName0Matcher::matches( const
NamedDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3027 std::string FullNameString = "::" + Node.getQualifiedNameAsString();
3028 return RegExp->match(FullNameString);
3029}
3030
3031/// Matches overloaded operator names.
3032///
3033/// Matches overloaded operator names specified in strings without the
3034/// "operator" prefix: e.g. "<<".
3035///
3036/// Given:
3037/// \code
3038/// class A { int operator*(); };
3039/// const A &operator<<(const A &a, const A &b);
3040/// A a;
3041/// a << a; // <-- This matches
3042/// \endcode
3043///
3044/// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
3045/// specified line and
3046/// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
3047/// matches the declaration of \c A.
3048///
3049/// Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
3050inline internal::PolymorphicMatcher<
3051 internal::HasOverloadedOperatorNameMatcher,
3052 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3053 std::vector<std::string>>
3054hasOverloadedOperatorName(StringRef Name) {
3055 return internal::PolymorphicMatcher<
3056 internal::HasOverloadedOperatorNameMatcher,
3057 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3058 std::vector<std::string>>({std::string(Name)});
3059}
3060
3061/// Matches overloaded operator names.
3062///
3063/// Matches overloaded operator names specified in strings without the
3064/// "operator" prefix: e.g. "<<".
3065///
3066/// hasAnyOverloadedOperatorName("+", "-")
3067/// Is equivalent to
3068/// anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-"))
3069extern const internal::VariadicFunction<
3070 internal::PolymorphicMatcher<internal::HasOverloadedOperatorNameMatcher,
3071 AST_POLYMORPHIC_SUPPORTED_TYPES(void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
3072 CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3073 std::vector<std::string>>,
3074 StringRef, internal::hasAnyOverloadedOperatorNameFunc>
3075 hasAnyOverloadedOperatorName;
3076
3077/// Matches template-dependent, but known, member names.
3078///
3079/// In template declarations, dependent members are not resolved and so can
3080/// not be matched to particular named declarations.
3081///
3082/// This matcher allows to match on the known name of members.
3083///
3084/// Given
3085/// \code
3086/// template <typename T>
3087/// struct S {
3088/// void mem();
3089/// };
3090/// template <typename T>
3091/// void x() {
3092/// S<T> s;
3093/// s.mem();
3094/// }
3095/// \endcode
3096/// \c cxxDependentScopeMemberExpr(hasMemberName("mem")) matches `s.mem()`
3097AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N)namespace internal { class matcher_hasMemberName0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXDependentScopeMemberExpr
> { public: explicit matcher_hasMemberName0Matcher( std::string
const &AN) : N(AN) {} bool matches(const CXXDependentScopeMemberExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string N; }; } inline
::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> hasMemberName( std::string const &N) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasMemberName0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &hasMemberName_Type0)(std::string const &N); inline
bool internal::matcher_hasMemberName0Matcher::matches( const
CXXDependentScopeMemberExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3098 return Node.getMember().getAsString() == N;
3099}
3100
3101/// Matches template-dependent, but known, member names against an already-bound
3102/// node
3103///
3104/// In template declarations, dependent members are not resolved and so can
3105/// not be matched to particular named declarations.
3106///
3107/// This matcher allows to match on the name of already-bound VarDecl, FieldDecl
3108/// and CXXMethodDecl nodes.
3109///
3110/// Given
3111/// \code
3112/// template <typename T>
3113/// struct S {
3114/// void mem();
3115/// };
3116/// template <typename T>
3117/// void x() {
3118/// S<T> s;
3119/// s.mem();
3120/// }
3121/// \endcode
3122/// The matcher
3123/// @code
3124/// \c cxxDependentScopeMemberExpr(
3125/// hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
3126/// hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has(
3127/// cxxMethodDecl(hasName("mem")).bind("templMem")
3128/// )))))
3129/// )))),
3130/// memberHasSameNameAsBoundNode("templMem")
3131/// )
3132/// @endcode
3133/// first matches and binds the @c mem member of the @c S template, then
3134/// compares its name to the usage in @c s.mem() in the @c x function template
3135AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode,namespace internal { class matcher_memberHasSameNameAsBoundNode0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXDependentScopeMemberExpr> { public: explicit matcher_memberHasSameNameAsBoundNode0Matcher
( std::string const &ABindingID) : BindingID(ABindingID) {
} bool matches(const CXXDependentScopeMemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: std::string BindingID; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> memberHasSameNameAsBoundNode( std::string const &BindingID
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_memberHasSameNameAsBoundNode0Matcher(BindingID)); }
typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &memberHasSameNameAsBoundNode_Type0)(std::string const
&BindingID); inline bool internal::matcher_memberHasSameNameAsBoundNode0Matcher
::matches( const CXXDependentScopeMemberExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
3136 std::string, BindingID)namespace internal { class matcher_memberHasSameNameAsBoundNode0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXDependentScopeMemberExpr> { public: explicit matcher_memberHasSameNameAsBoundNode0Matcher
( std::string const &ABindingID) : BindingID(ABindingID) {
} bool matches(const CXXDependentScopeMemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: std::string BindingID; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> memberHasSameNameAsBoundNode( std::string const &BindingID
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_memberHasSameNameAsBoundNode0Matcher(BindingID)); }
typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &memberHasSameNameAsBoundNode_Type0)(std::string const
&BindingID); inline bool internal::matcher_memberHasSameNameAsBoundNode0Matcher
::matches( const CXXDependentScopeMemberExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
3137 auto MemberName = Node.getMember().getAsString();
3138
3139 return Builder->removeBindings(
3140 [this, MemberName](const BoundNodesMap &Nodes) {
3141 const auto &BN = Nodes.getNode(this->BindingID);
3142 if (const auto *ND = BN.get<NamedDecl>()) {
3143 if (!isa<FieldDecl, CXXMethodDecl, VarDecl>(ND))
3144 return true;
3145 return ND->getName() != MemberName;
3146 }
3147 return true;
3148 });
3149}
3150
3151/// Matches C++ classes that are directly or indirectly derived from a class
3152/// matching \c Base, or Objective-C classes that directly or indirectly
3153/// subclass a class matching \c Base.
3154///
3155/// Note that a class is not considered to be derived from itself.
3156///
3157/// Example matches Y, Z, C (Base == hasName("X"))
3158/// \code
3159/// class X;
3160/// class Y : public X {}; // directly derived
3161/// class Z : public Y {}; // indirectly derived
3162/// typedef X A;
3163/// typedef A B;
3164/// class C : public B {}; // derived from a typedef of X
3165/// \endcode
3166///
3167/// In the following example, Bar matches isDerivedFrom(hasName("X")):
3168/// \code
3169/// class Foo;
3170/// typedef Foo X;
3171/// class Bar : public Foo {}; // derived from a type that X is a typedef of
3172/// \endcode
3173///
3174/// In the following example, Bar matches isDerivedFrom(hasName("NSObject"))
3175/// \code
3176/// @interface NSObject @end
3177/// @interface Bar : NSObject @end
3178/// \endcode
3179///
3180/// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl>
3181AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3182 isDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3183 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3184 internal::Matcher<NamedDecl>, Base)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3185 // Check if the node is a C++ struct/union/class.
3186 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3187 return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false);
3188
3189 // The node must be an Objective-C class.
3190 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3191 return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder,
3192 /*Directly=*/false);
3193}
3194
3195/// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)).
3196AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3197 isDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3198 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3199 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3200 if (BaseName.empty())
3201 return false;
3202
3203 const auto M = isDerivedFrom(hasName(BaseName));
3204
3205 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3206 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3207
3208 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3209 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3210}
3211
3212/// Matches C++ classes that have a direct or indirect base matching \p
3213/// BaseSpecMatcher.
3214///
3215/// Example:
3216/// matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))
3217/// \code
3218/// class Foo;
3219/// class Bar : Foo {};
3220/// class Baz : Bar {};
3221/// class SpecialBase;
3222/// class Proxy : SpecialBase {}; // matches Proxy
3223/// class IndirectlyDerived : Proxy {}; //matches IndirectlyDerived
3224/// \endcode
3225///
3226// FIXME: Refactor this and isDerivedFrom to reuse implementation.
3227AST_MATCHER_P(CXXRecordDecl, hasAnyBase, internal::Matcher<CXXBaseSpecifier>,namespace internal { class matcher_hasAnyBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasAnyBase0Matcher( internal::
Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher) :
BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasAnyBase( internal::Matcher<
CXXBaseSpecifier> const &BaseSpecMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyBase0Matcher
(BaseSpecMatcher)); } typedef ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> ( &hasAnyBase_Type0)(internal
::Matcher<CXXBaseSpecifier> const &BaseSpecMatcher)
; inline bool internal::matcher_hasAnyBase0Matcher::matches( const
CXXRecordDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3228 BaseSpecMatcher)namespace internal { class matcher_hasAnyBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasAnyBase0Matcher( internal::
Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher) :
BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasAnyBase( internal::Matcher<
CXXBaseSpecifier> const &BaseSpecMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyBase0Matcher
(BaseSpecMatcher)); } typedef ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> ( &hasAnyBase_Type0)(internal
::Matcher<CXXBaseSpecifier> const &BaseSpecMatcher)
; inline bool internal::matcher_hasAnyBase0Matcher::matches( const
CXXRecordDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3229 return internal::matchesAnyBase(Node, BaseSpecMatcher, Finder, Builder);
3230}
3231
3232/// Matches C++ classes that have a direct base matching \p BaseSpecMatcher.
3233///
3234/// Example:
3235/// matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))
3236/// \code
3237/// class Foo;
3238/// class Bar : Foo {};
3239/// class Baz : Bar {};
3240/// class SpecialBase;
3241/// class Proxy : SpecialBase {}; // matches Proxy
3242/// class IndirectlyDerived : Proxy {}; // doesn't match
3243/// \endcode
3244AST_MATCHER_P(CXXRecordDecl, hasDirectBase, internal::Matcher<CXXBaseSpecifier>,namespace internal { class matcher_hasDirectBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasDirectBase0Matcher( internal
::Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher
) : BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasDirectBase( internal::Matcher
<CXXBaseSpecifier> const &BaseSpecMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDirectBase0Matcher(BaseSpecMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<CXXRecordDecl> (
&hasDirectBase_Type0)(internal::Matcher<CXXBaseSpecifier
> const &BaseSpecMatcher); inline bool internal::matcher_hasDirectBase0Matcher
::matches( const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
3245 BaseSpecMatcher)namespace internal { class matcher_hasDirectBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasDirectBase0Matcher( internal
::Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher
) : BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasDirectBase( internal::Matcher
<CXXBaseSpecifier> const &BaseSpecMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDirectBase0Matcher(BaseSpecMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<CXXRecordDecl> (
&hasDirectBase_Type0)(internal::Matcher<CXXBaseSpecifier
> const &BaseSpecMatcher); inline bool internal::matcher_hasDirectBase0Matcher
::matches( const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3246 return Node.hasDefinition() &&
3247 llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &Base) {
3248 return BaseSpecMatcher.matches(Base, Finder, Builder);
3249 });
3250}
3251
3252/// Similar to \c isDerivedFrom(), but also matches classes that directly
3253/// match \c Base.
3254AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3255 isSameOrDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3256 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3257 internal::Matcher<NamedDecl>, Base, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3258 const auto M = anyOf(Base, isDerivedFrom(Base));
3259
3260 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3261 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3262
3263 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3264 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3265}
3266
3267/// Overloaded method as shortcut for
3268/// \c isSameOrDerivedFrom(hasName(...)).
3269AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3270 isSameOrDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3271 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3272 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3273 if (BaseName.empty())
3274 return false;
3275
3276 const auto M = isSameOrDerivedFrom(hasName(BaseName));
3277
3278 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3279 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3280
3281 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3282 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3283}
3284
3285/// Matches C++ or Objective-C classes that are directly derived from a class
3286/// matching \c Base.
3287///
3288/// Note that a class is not considered to be derived from itself.
3289///
3290/// Example matches Y, C (Base == hasName("X"))
3291/// \code
3292/// class X;
3293/// class Y : public X {}; // directly derived
3294/// class Z : public Y {}; // indirectly derived
3295/// typedef X A;
3296/// typedef A B;
3297/// class C : public B {}; // derived from a typedef of X
3298/// \endcode
3299///
3300/// In the following example, Bar matches isDerivedFrom(hasName("X")):
3301/// \code
3302/// class Foo;
3303/// typedef Foo X;
3304/// class Bar : public Foo {}; // derived from a type that X is a typedef of
3305/// \endcode
3306AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3307 isDirectlyDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3308 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3309 internal::Matcher<NamedDecl>, Base, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3310 // Check if the node is a C++ struct/union/class.
3311 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3312 return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true);
3313
3314 // The node must be an Objective-C class.
3315 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3316 return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder,
3317 /*Directly=*/true);
3318}
3319
3320/// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)).
3321AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3322 isDirectlyDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3323 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3324 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3325 if (BaseName.empty())
3326 return false;
3327 const auto M = isDirectlyDerivedFrom(hasName(BaseName));
3328
3329 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3330 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3331
3332 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3333 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3334}
3335/// Matches the first method of a class or struct that satisfies \c
3336/// InnerMatcher.
3337///
3338/// Given:
3339/// \code
3340/// class A { void func(); };
3341/// class B { void member(); };
3342/// \endcode
3343///
3344/// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of
3345/// \c A but not \c B.
3346AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>,namespace internal { class matcher_hasMethod0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasMethod0Matcher( internal::
Matcher<CXXMethodDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXRecordDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasMethod( internal::Matcher<
CXXMethodDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasMethod0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXRecordDecl> ( &hasMethod_Type0)(internal::Matcher
<CXXMethodDecl> const &InnerMatcher); inline bool internal
::matcher_hasMethod0Matcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
3347 InnerMatcher)namespace internal { class matcher_hasMethod0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasMethod0Matcher( internal::
Matcher<CXXMethodDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXRecordDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasMethod( internal::Matcher<
CXXMethodDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasMethod0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXRecordDecl> ( &hasMethod_Type0)(internal::Matcher
<CXXMethodDecl> const &InnerMatcher); inline bool internal
::matcher_hasMethod0Matcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
3348 BoundNodesTreeBuilder Result(*Builder);
3349 auto MatchIt = matchesFirstInPointerRange(InnerMatcher, Node.method_begin(),
3350 Node.method_end(), Finder, &Result);
3351 if (MatchIt == Node.method_end())
3352 return false;
3353
3354 if (Finder->isTraversalIgnoringImplicitNodes() && (*MatchIt)->isImplicit())
3355 return false;
3356 *Builder = std::move(Result);
3357 return true;
3358}
3359
3360/// Matches the generated class of lambda expressions.
3361///
3362/// Given:
3363/// \code
3364/// auto x = []{};
3365/// \endcode
3366///
3367/// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of
3368/// \c decltype(x)
3369AST_MATCHER(CXXRecordDecl, isLambda)namespace internal { class matcher_isLambdaMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_isLambdaMatcher() = default; bool
matches(const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXRecordDecl>
isLambda() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isLambdaMatcher()); } inline bool internal
::matcher_isLambdaMatcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
3370 return Node.isLambda();
3371}
3372
3373/// Matches AST nodes that have child AST nodes that match the
3374/// provided matcher.
3375///
3376/// Example matches X, Y
3377/// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))
3378/// \code
3379/// class X {}; // Matches X, because X::X is a class of name X inside X.
3380/// class Y { class X {}; };
3381/// class Z { class Y { class X {}; }; }; // Does not match Z.
3382/// \endcode
3383///
3384/// ChildT must be an AST base type.
3385///
3386/// Usable as: Any Matcher
3387/// Note that has is direct matcher, so it also matches things like implicit
3388/// casts and paren casts. If you are matching with expr then you should
3389/// probably consider using ignoringParenImpCasts like:
3390/// has(ignoringParenImpCasts(expr())).
3391extern const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has;
3392
3393/// Matches AST nodes that have descendant AST nodes that match the
3394/// provided matcher.
3395///
3396/// Example matches X, Y, Z
3397/// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))
3398/// \code
3399/// class X {}; // Matches X, because X::X is a class of name X inside X.
3400/// class Y { class X {}; };
3401/// class Z { class Y { class X {}; }; };
3402/// \endcode
3403///
3404/// DescendantT must be an AST base type.
3405///
3406/// Usable as: Any Matcher
3407extern const internal::ArgumentAdaptingMatcherFunc<
3408 internal::HasDescendantMatcher>
3409 hasDescendant;
3410
3411/// Matches AST nodes that have child AST nodes that match the
3412/// provided matcher.
3413///
3414/// Example matches X, Y, Y::X, Z::Y, Z::Y::X
3415/// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
3416/// \code
3417/// class X {};
3418/// class Y { class X {}; }; // Matches Y, because Y::X is a class of name X
3419/// // inside Y.
3420/// class Z { class Y { class X {}; }; }; // Does not match Z.
3421/// \endcode
3422///
3423/// ChildT must be an AST base type.
3424///
3425/// As opposed to 'has', 'forEach' will cause a match for each result that
3426/// matches instead of only on the first one.
3427///
3428/// Usable as: Any Matcher
3429extern const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher>
3430 forEach;
3431
3432/// Matches AST nodes that have descendant AST nodes that match the
3433/// provided matcher.
3434///
3435/// Example matches X, A, A::X, B, B::C, B::C::X
3436/// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))
3437/// \code
3438/// class X {};
3439/// class A { class X {}; }; // Matches A, because A::X is a class of name
3440/// // X inside A.
3441/// class B { class C { class X {}; }; };
3442/// \endcode
3443///
3444/// DescendantT must be an AST base type.
3445///
3446/// As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
3447/// each result that matches instead of only on the first one.
3448///
3449/// Note: Recursively combined ForEachDescendant can cause many matches:
3450/// cxxRecordDecl(forEachDescendant(cxxRecordDecl(
3451/// forEachDescendant(cxxRecordDecl())
3452/// )))
3453/// will match 10 times (plus injected class name matches) on:
3454/// \code
3455/// class A { class B { class C { class D { class E {}; }; }; }; };
3456/// \endcode
3457///
3458/// Usable as: Any Matcher
3459extern const internal::ArgumentAdaptingMatcherFunc<
3460 internal::ForEachDescendantMatcher>
3461 forEachDescendant;
3462
3463/// Matches if the node or any descendant matches.
3464///
3465/// Generates results for each match.
3466///
3467/// For example, in:
3468/// \code
3469/// class A { class B {}; class C {}; };
3470/// \endcode
3471/// The matcher:
3472/// \code
3473/// cxxRecordDecl(hasName("::A"),
3474/// findAll(cxxRecordDecl(isDefinition()).bind("m")))
3475/// \endcode
3476/// will generate results for \c A, \c B and \c C.
3477///
3478/// Usable as: Any Matcher
3479template <typename T>
3480internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) {
3481 return eachOf(Matcher, forEachDescendant(Matcher));
3482}
3483
3484/// Matches AST nodes that have a parent that matches the provided
3485/// matcher.
3486///
3487/// Given
3488/// \code
3489/// void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }
3490/// \endcode
3491/// \c compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
3492///
3493/// Usable as: Any Matcher
3494extern const internal::ArgumentAdaptingMatcherFunc<
3495 internal::HasParentMatcher,
3496 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3497 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3498 hasParent;
3499
3500/// Matches AST nodes that have an ancestor that matches the provided
3501/// matcher.
3502///
3503/// Given
3504/// \code
3505/// void f() { if (true) { int x = 42; } }
3506/// void g() { for (;;) { int x = 43; } }
3507/// \endcode
3508/// \c expr(integerLiteral(hasAncestor(ifStmt()))) matches \c 42, but not 43.
3509///
3510/// Usable as: Any Matcher
3511extern const internal::ArgumentAdaptingMatcherFunc<
3512 internal::HasAncestorMatcher,
3513 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3514 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3515 hasAncestor;
3516
3517/// Matches if the provided matcher does not match.
3518///
3519/// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
3520/// \code
3521/// class X {};
3522/// class Y {};
3523/// \endcode
3524///
3525/// Usable as: Any Matcher
3526extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
3527
3528/// Matches a node if the declaration associated with that node
3529/// matches the given matcher.
3530///
3531/// The associated declaration is:
3532/// - for type nodes, the declaration of the underlying type
3533/// - for CallExpr, the declaration of the callee
3534/// - for MemberExpr, the declaration of the referenced member
3535/// - for CXXConstructExpr, the declaration of the constructor
3536/// - for CXXNewExpr, the declaration of the operator new
3537/// - for ObjCIvarExpr, the declaration of the ivar
3538///
3539/// For type nodes, hasDeclaration will generally match the declaration of the
3540/// sugared type. Given
3541/// \code
3542/// class X {};
3543/// typedef X Y;
3544/// Y y;
3545/// \endcode
3546/// in varDecl(hasType(hasDeclaration(decl()))) the decl will match the
3547/// typedefDecl. A common use case is to match the underlying, desugared type.
3548/// This can be achieved by using the hasUnqualifiedDesugaredType matcher:
3549/// \code
3550/// varDecl(hasType(hasUnqualifiedDesugaredType(
3551/// recordType(hasDeclaration(decl())))))
3552/// \endcode
3553/// In this matcher, the decl will match the CXXRecordDecl of class X.
3554///
3555/// Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
3556/// Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
3557/// Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
3558/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
3559/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
3560/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
3561/// Matcher<UnresolvedUsingType>
3562inline internal::PolymorphicMatcher<
3563 internal::HasDeclarationMatcher,
3564 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
3565hasDeclaration(const internal::Matcher<Decl> &InnerMatcher) {
3566 return internal::PolymorphicMatcher<
3567 internal::HasDeclarationMatcher,
3568 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>(
3569 InnerMatcher);
3570}
3571
3572/// Matches a \c NamedDecl whose underlying declaration matches the given
3573/// matcher.
3574///
3575/// Given
3576/// \code
3577/// namespace N { template<class T> void f(T t); }
3578/// template <class T> void g() { using N::f; f(T()); }