blob: a371b3bfcf5788ab8e323fe5bd88b02af9a8d921 [file] [log] [blame]
Manuel Klimek1da79332012-08-20 20:54:03 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5<title>AST Matcher Reference</title>
6<link type="text/css" rel="stylesheet" href="../menu.css" />
7<link type="text/css" rel="stylesheet" href="../content.css" />
8<style type="text/css">
9td {
10 padding: .33em;
11}
12td.doc {
13 display: none;
14 border-bottom: 1px solid black;
15}
16td.name:hover {
17 color: blue;
18 cursor: pointer;
19}
20</style>
21<script type="text/javascript">
22function toggle(id) {
23 row = document.getElementById(id);
24 if (row.style.display != 'table-cell')
25 row.style.display = 'table-cell';
26 else
27 row.style.display = 'none';
28}
29</script>
30</head>
31<body>
32
33<!--#include virtual="../menu.html.incl"-->
34
35<div id="content">
36
37<h1>AST Matcher Reference</h1>
38
39<p>This document shows all currently implemented matchers. The matchers are grouped
40by category and node type they match. You can click on matcher names to show the
41matcher's source documentation.</p>
42
43<p>There are three different basic categories of matchers:
44<ul>
45<li><a href="#decl-matchers">Node Matchers:</a> Matchers that match a specific type of AST node.</li>
46<li><a href="#narrowing-matchers">Narrowing Matchers:</a> Matchers that match attributes on AST nodes.</li>
47<li><a href="#traversal-matchers">Traversal Matchers:</a> Matchers that allow traversal between AST nodes.</li>
48</ul>
49</p>
50
51<p>Within each category the matchers are ordered by node type they match on.
52Note that if a matcher can match multiple node types, it will it will appear
53multiple times. This means that by searching for Matcher&lt;Stmt&gt; you can
54find all matchers that can be used to match on Stmt nodes.</p>
55
56<p>The exception to that rule are matchers that can match on any node. Those
57are marked with a * and are listed in the beginning of each category.</p>
58
59<!-- ======================================================================= -->
60<h2 id="decl-matchers">Node Matchers</h2>
61<!-- ======================================================================= -->
62
63<p>Node matchers are at the core of matcher expressions - they specify the type
64of node that is expected. Every match expression starts with a node matcher,
65which can then be further refined with a narrowing or traversal matcher. All
66traversal matchers take node matchers as their arguments.</p>
67
68<p>For convenience, all node matchers take an arbitrary number of arguments
69and implicitly act as allOf matchers.</p>
70
71<p>Node matchers are the only matchers that support the bind("id") call to
72bind the matched node to the given string, to be later retrieved from the
73match callback.</p>
74
75<table>
76<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
77<!-- START_DECL_MATCHERS -->
78
79<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('classTemplate0')">classTemplate</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>&gt;...</td></tr>
80<tr><td colspan="4" class="doc" id="classTemplate0"><pre>Matches C++ class template declarations.
81
82Example matches Z
83 template&lt;class T&gt; class Z {};
84</pre></td></tr>
85
86
87<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('classTemplateSpecialization0')">classTemplateSpecialization</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;...</td></tr>
88<tr><td colspan="4" class="doc" id="classTemplateSpecialization0"><pre>Matches C++ class template specializations.
89
90Given
91 template&lt;typename T&gt; class A {};
92 template&lt;&gt; class A&lt;double&gt; {};
93 A&lt;int&gt; a;
94classTemplateSpecialization()
95 matches the specializations A&lt;int&gt; and A&lt;double&gt;
96</pre></td></tr>
97
98
99<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('constructor0')">constructor</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>&gt;...</td></tr>
100<tr><td colspan="4" class="doc" id="constructor0"><pre>Matches C++ constructor declarations.
101
102Example matches Foo::Foo() and Foo::Foo(int)
103 class Foo {
104 public:
105 Foo();
106 Foo(int);
107 int DoSomething();
108 };
109</pre></td></tr>
110
111
112<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('decl0')">decl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;...</td></tr>
113<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations.
114
115Examples matches X, C, and the friend declaration inside C;
116 void X();
117 class C {
118 friend X;
119 };
120</pre></td></tr>
121
122
123<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('destructor0')">destructor</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>&gt;...</td></tr>
124<tr><td colspan="4" class="doc" id="destructor0"><pre>Matches explicit C++ destructor declarations.
125
126Example matches Foo::~Foo()
127 class Foo {
128 public:
129 virtual ~Foo();
130 };
131</pre></td></tr>
132
133
134<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('enumConstant0')">enumConstant</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>&gt;...</td></tr>
135<tr><td colspan="4" class="doc" id="enumConstant0"><pre>Matches enum constants.
136
137Example matches A, B, C
138 enum X {
139 A, B, C
140 };
141</pre></td></tr>
142
143
144<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('enumDecl0')">enumDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>&gt;...</td></tr>
145<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations.
146
147Example matches X
148 enum X {
149 A, B, C
150 };
151</pre></td></tr>
152
153
154<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('field0')">field</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>&gt;...</td></tr>
155<tr><td colspan="4" class="doc" id="field0"><pre>Matches field declarations.
156
157Given
158 class X { int m; };
159field()
160 matches 'm'.
161</pre></td></tr>
162
163
164<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('function0')">function</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;...</td></tr>
165<tr><td colspan="4" class="doc" id="function0"><pre>Matches function declarations.
166
167Example matches f
168 void f();
169</pre></td></tr>
170
171
172<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('functionTemplate0')">functionTemplate</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>&gt;...</td></tr>
173<tr><td colspan="4" class="doc" id="functionTemplate0"><pre>Matches C++ function template declarations.
174
175Example matches f
176 template&lt;class T&gt; void f(T t) {}
177</pre></td></tr>
178
179
180<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('method0')">method</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;...</td></tr>
181<tr><td colspan="4" class="doc" id="method0"><pre>Matches method declarations.
182
183Example matches y
184 class X { void y() };
185</pre></td></tr>
186
187
188<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('nameableDeclaration0')">nameableDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;...</td></tr>
189<tr><td colspan="4" class="doc" id="nameableDeclaration0"><pre>Matches a declaration of anything that could have a name.
190
191Example matches X, S, the anonymous union type, i, and U;
192 typedef int X;
193 struct S {
194 union {
195 int i;
196 } U;
197 };
198</pre></td></tr>
199
200
201<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('record0')">record</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;...</td></tr>
202<tr><td colspan="4" class="doc" id="record0"><pre>Matches C++ class declarations.
203
204Example matches X, Z
205 class X;
206 template&lt;class T&gt; class Z {};
207</pre></td></tr>
208
209
210<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('usingDecl0')">usingDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>&gt;...</td></tr>
211<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations.
212
213Given
214 namespace X { int x; }
215 using X::x;
216usingDecl()
217 matches using X::x </pre></td></tr>
218
219
220<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('variable0')">variable</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;...</td></tr>
221<tr><td colspan="4" class="doc" id="variable0"><pre>Matches variable declarations.
222
223Note: this does not match declarations of member variables, which are
224"field" declarations in Clang parlance.
225
226Example matches a
227 int a;
228</pre></td></tr>
229
230
231<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('boolLiteral0')">boolLiteral</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>&gt;...</td></tr>
232<tr><td colspan="4" class="doc" id="boolLiteral0"><pre>Matches bool literals.
233
234Example matches true
235 true
236</pre></td></tr>
237
238
239<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('castExpr0')">castExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>&gt;...</td></tr>
240<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST.
241
242Example: castExpr() matches each of the following:
243 (int) 3;
244 const_cast&lt;Expr *&gt;(SubExpr);
245 char c = 0;
246but does not match
247 int i = (0);
248 int k = 0;
249</pre></td></tr>
250
251
252<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('characterLiteral0')">characterLiteral</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;...</td></tr>
253<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t).
254
255Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
256though.
257
258Example matches 'a', L'a'
259 char ch = 'a'; wchar_t chw = L'a';
260</pre></td></tr>
261
262
263<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('constCast0')">constCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>&gt;...</td></tr>
264<tr><td colspan="4" class="doc" id="constCast0"><pre>Matches a const_cast expression.
265
266Example: Matches const_cast&lt;int*&gt;(&amp;r) in
267 int n = 42;
268 const int &amp;r(n);
269 int* p = const_cast&lt;int*&gt;(&amp;r);
270</pre></td></tr>
271
272
273<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('dynamicCast0')">dynamicCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>&gt;...</td></tr>
274<tr><td colspan="4" class="doc" id="dynamicCast0"><pre>Matches a dynamic_cast expression.
275
276Example:
277 dynamicCast()
278matches
279 dynamic_cast&lt;D*&gt;(&amp;b);
280in
281 struct B { virtual ~B() {} }; struct D : B {};
282 B b;
283 D* p = dynamic_cast&lt;D*&gt;(&amp;b);
284</pre></td></tr>
285
286
287<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('explicitCast0')">explicitCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>&gt;...</td></tr>
288<tr><td colspan="4" class="doc" id="explicitCast0"><pre>Matches explicit cast expressions.
289
290Matches any cast expression written in user code, whether it be a
291C-style cast, a functional-style cast, or a keyword cast.
292
293Does not match implicit conversions.
294
295Note: the name "explicitCast" is chosen to match Clang's terminology, as
296Clang uses the term "cast" to apply to implicit conversions as well as to
297actual cast expressions.
298
299hasDestinationType.
300
301Example: matches all five of the casts in
302 int((int)(reinterpret_cast&lt;int&gt;(static_cast&lt;int&gt;(const_cast&lt;int&gt;(42)))))
303but does not match the implicit conversion in
304 long ell = 42;
305</pre></td></tr>
306
307
308<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('functionalCast0')">functionalCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>&gt;...</td></tr>
309<tr><td colspan="4" class="doc" id="functionalCast0"><pre>Matches functional cast expressions
310
311Example: Matches Foo(bar);
312 Foo f = bar;
313 Foo g = (Foo) bar;
314 Foo h = Foo(bar);
315</pre></td></tr>
316
317
318<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('implicitCast0')">implicitCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>&gt;...</td></tr>
319<tr><td colspan="4" class="doc" id="implicitCast0"><pre>Matches the implicit cast nodes of Clang's AST.
320
321This matches many different places, including function call return value
322eliding, as well as any type conversions.
323</pre></td></tr>
324
325
326<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('integerLiteral0')">integerLiteral</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;...</td></tr>
327<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings.
328
329Not matching character-encoded integers such as L'a'.
330
331Example matches 1, 1L, 0x1, 1U
332</pre></td></tr>
333
334
335<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('reinterpretCast0')">reinterpretCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>&gt;...</td></tr>
336<tr><td colspan="4" class="doc" id="reinterpretCast0"><pre>Matches a reinterpret_cast expression.
337
338Either the source expression or the destination type can be matched
339using has(), but hasDestinationType() is more specific and can be
340more readable.
341
342Example matches reinterpret_cast&lt;char*&gt;(&amp;p) in
343 void* p = reinterpret_cast&lt;char*&gt;(&amp;p);
344</pre></td></tr>
345
346
347<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('staticCast0')">staticCast</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>&gt;...</td></tr>
348<tr><td colspan="4" class="doc" id="staticCast0"><pre>Matches a C++ static_cast expression.
349
350hasDestinationType
351reinterpretCast
352
353Example:
354 staticCast()
355matches
356 static_cast&lt;long&gt;(8)
357in
358 long eight(static_cast&lt;long&gt;(8));
359</pre></td></tr>
360
361
362<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('stringLiteral0')">stringLiteral</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>&gt;...</td></tr>
363<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals).
364
365Example matches "abcd", L"abcd"
366 char *s = "abcd"; wchar_t *ws = L"abcd"
367</pre></td></tr>
368
369
370<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('arraySubscriptExpr0')">arraySubscriptExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;...</td></tr>
371<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions.
372
373Given
374 int i = a[1];
375arraySubscriptExpr()
376 matches "a[1]"
377</pre></td></tr>
378
379
380<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('binaryOperator0')">binaryOperator</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;...</td></tr>
381<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions.
382
383Example matches a || b
384 !(a || b)
385</pre></td></tr>
386
387
388<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('bindTemporaryExpression0')">bindTemporaryExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>&gt;...</td></tr>
389<tr><td colspan="4" class="doc" id="bindTemporaryExpression0"><pre>Matches nodes where temporaries are created.
390
391Example matches FunctionTakesString(GetStringByValue())
392 (matcher = bindTemporaryExpression())
393 FunctionTakesString(GetStringByValue());
394 FunctionTakesStringByPointer(GetStringPointer());
395</pre></td></tr>
396
397
398<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('call0')">call</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;...</td></tr>
399<tr><td colspan="4" class="doc" id="call0"><pre>Matches call expressions.
400
401Example matches x.y() and y()
402 X x;
403 x.y();
404 y();
405</pre></td></tr>
406
407
408<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('compoundStatement0')">compoundStatement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>&gt;...</td></tr>
409<tr><td colspan="4" class="doc" id="compoundStatement0"><pre>Matches compound statements.
410
411Example matches '{}' and '{{}}'in 'for (;;) {{}}'
412 for (;;) {{}}
413</pre></td></tr>
414
415
416<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('conditionalOperator0')">conditionalOperator</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>&gt;...</td></tr>
417<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions.
418
419Example matches a ? b : c
420 (a ? b : c) + 42
421</pre></td></tr>
422
423
424<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('constructorCall0')">constructorCall</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;...</td></tr>
425<tr><td colspan="4" class="doc" id="constructorCall0"><pre>Matches constructor call expressions (including implicit ones).
426
427Example matches string(ptr, n) and ptr within arguments of f
428 (matcher = constructorCall())
429 void f(const string &amp;a, const string &amp;b);
430 char *ptr;
431 int n;
432 f(string(ptr, n), ptr);
433</pre></td></tr>
434
435
436<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('declarationReference0')">declarationReference</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>&gt;...</td></tr>
437<tr><td colspan="4" class="doc" id="declarationReference0"><pre>Matches expressions that refer to declarations.
438
439Example matches x in if (x)
440 bool x;
441 if (x) {}
442</pre></td></tr>
443
444
445<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('declarationStatement0')">declarationStatement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt;...</td></tr>
446<tr><td colspan="4" class="doc" id="declarationStatement0"><pre>Matches declaration statements.
447
448Given
449 int a;
450declarationStatement()
451 matches 'int a'.
452</pre></td></tr>
453
454
455<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('defaultArgument0')">defaultArgument</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>&gt;...</td></tr>
456<tr><td colspan="4" class="doc" id="defaultArgument0"><pre>Matches the value of a default argument at the call site.
457
458Example matches the CXXDefaultArgExpr placeholder inserted for the
459 default value of the second parameter in the call expression f(42)
460 (matcher = defaultArgument())
461 void f(int x, int y = 0);
462 f(42);
463</pre></td></tr>
464
465
466<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('deleteExpression0')">deleteExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>&gt;...</td></tr>
467<tr><td colspan="4" class="doc" id="deleteExpression0"><pre>Matches delete expressions.
468
469Given
470 delete X;
471deleteExpression()
472 matches 'delete X'.
473</pre></td></tr>
474
475
476<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('doStmt0')">doStmt</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>&gt;...</td></tr>
477<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements.
478
479Given
480 do {} while (true);
481doStmt()
482 matches 'do {} while(true)'
483</pre></td></tr>
484
485
486<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('expression0')">expression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;...</td></tr>
487<tr><td colspan="4" class="doc" id="expression0"><pre>Matches expressions.
488
489Example matches x()
490 void f() { x(); }
491</pre></td></tr>
492
493
494<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('forStmt0')">forStmt</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;...</td></tr>
495<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements.
496
497Example matches 'for (;;) {}'
498 for (;;) {}
499</pre></td></tr>
500
501
502<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('ifStmt0')">ifStmt</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>&gt;...</td></tr>
503<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements.
504
505Example matches 'if (x) {}'
506 if (x) {}
507</pre></td></tr>
508
509
510<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('initListExpr0')">initListExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>&gt;...</td></tr>
511<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions.
512
513Given
514 int a[] = { 1, 2 };
515 struct B { int x, y; };
516 B b = { 5, 6 };
517initList()
518 matches "{ 1, 2 }" and "{ 5, 6 }"
519</pre></td></tr>
520
521
522<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('memberCall0')">memberCall</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;...</td></tr>
523<tr><td colspan="4" class="doc" id="memberCall0"><pre>Matches member call expressions.
524
525Example matches x.y()
526 X x;
527 x.y();
528</pre></td></tr>
529
530
531<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('memberExpression0')">memberExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;...</td></tr>
532<tr><td colspan="4" class="doc" id="memberExpression0"><pre>Matches member expressions.
533
534Given
535 class Y {
536 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
537 int a; static int b;
538 };
539memberExpression()
540 matches this-&gt;x, x, y.x, a, this-&gt;b
541</pre></td></tr>
542
543
544<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('newExpression0')">newExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>&gt;...</td></tr>
545<tr><td colspan="4" class="doc" id="newExpression0"><pre>Matches new expressions.
546
547Given
548 new X;
549newExpression()
550 matches 'new X'.
551</pre></td></tr>
552
553
554<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('overloadedOperatorCall0')">overloadedOperatorCall</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>&gt;...</td></tr>
555<tr><td colspan="4" class="doc" id="overloadedOperatorCall0"><pre>Matches overloaded operator calls.
556
557Note that if an operator isn't overloaded, it won't match. Instead, use
558binaryOperator matcher.
559Currently it does not match operators such as new delete.
560FIXME: figure out why these do not match?
561
562Example matches both operator&lt;&lt;((o &lt;&lt; b), c) and operator&lt;&lt;(o, b)
563 (matcher = overloadedOperatorCall())
564 ostream &amp;operator&lt;&lt; (ostream &amp;out, int i) { };
565 ostream &amp;o; int b = 1, c = 1;
566 o &lt;&lt; b &lt;&lt; c;
567</pre></td></tr>
568
569
570<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('statement0')">statement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;...</td></tr>
571<tr><td colspan="4" class="doc" id="statement0"><pre>Matches statements.
572
573Given
574 { ++a; }
575statement()
576 matches both the compound statement '{ ++a; }' and '++a'.
577</pre></td></tr>
578
579
580<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('switchCase0')">switchCase</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>&gt;...</td></tr>
581<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements.
582
583Given
584 switch(a) { case 42: break; default: break; }
585switchCase()
586 matches 'case 42: break;' and 'default: break;'.
587</pre></td></tr>
588
589
590<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('unaryExprOrTypeTraitExpr0')">unaryExprOrTypeTraitExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt;...</td></tr>
591<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
592
593Given
594 Foo x = bar;
595 int y = sizeof(x) + alignof(x);
596unaryExprOrTypeTraitExpr()
597 matches sizeof(x) and alignof(x)
598</pre></td></tr>
599
600
601<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('unaryOperator0')">unaryOperator</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>&gt;...</td></tr>
602<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions.
603
604Example matches !a
605 !a || b
606</pre></td></tr>
607
608
609<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('whileStmt0')">whileStmt</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>&gt;...</td></tr>
610<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements.
611
612Given
613 while (true) {}
614whileStmt()
615 matches 'while (true) {}'.
616</pre></td></tr>
617
618<!--END_DECL_MATCHERS -->
619</table>
620
621<!-- ======================================================================= -->
622<h2 id="narrowing-matchers">Narrowing Matchers</h2>
623<!-- ======================================================================= -->
624
625<p>Narrowing matchers match certain attributes on the current node, thus
626narrowing down the set of nodes of the current type to match on.</p>
627
628<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless)
629which allow users to create more powerful match expressions.</p>
630
631<table>
632<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
633<!-- START_NARROWING_MATCHERS -->
634
635<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('allOf0')">allOf</td><td>Matcher&lt;*&gt; P1, Matcher&lt;*&gt; P2</td></tr>
636<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match.
637
638Usable as: Any Matcher
639</pre></td></tr>
640
641
642<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('anyOf0')">anyOf</td><td>Matcher&lt;*&gt; P1, Matcher&lt;*&gt; P2</td></tr>
643<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches.
644
645Usable as: Any Matcher
646</pre></td></tr>
647
648
649<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('anything0')">anything</td><td></td></tr>
650<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node.
651
652Useful when another matcher requires a child matcher, but there's no
653additional constraint. This will often be used with an explicit conversion
654to an internal::Matcher&lt;&gt; type such as TypeMatcher.
655
656Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
657"int* p" and "void f()" in
658 int* p;
659 void f();
660
661Usable as: Any Matcher
662</pre></td></tr>
663
664
665<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('unless0')">unless</td><td>Matcher&lt;*&gt; InnerMatcher</td></tr>
666<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match.
667
668Example matches Y (matcher = record(unless(hasName("X"))))
669 class X {};
670 class Y {};
671
672Usable as: Any Matcher
673</pre></td></tr>
674
675
676<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasOperatorName0')">hasOperatorName</td><td>std::string Name</td></tr>
677<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or
678unary).
679
680Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
681 !(a || b)
682</pre></td></tr>
683
684
685<tr><td>Matcher&lt;CXXBoolLiteral&gt;</td><td class="name" onclick="toggle('equals2')">equals</td><td>ValueT Value</td></tr>
686<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value.
687
688Example matches true (matcher = boolLiteral(equals(true)))
689 true
690
691Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
692 Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;
693</pre></td></tr>
694
695
696<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>&gt;</td><td class="name" onclick="toggle('isImplicit0')">isImplicit</td><td></td></tr>
697<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a constructor declaration that has been implicitly added
698by the compiler (eg. implicit defaultcopy constructors).
699</pre></td></tr>
700
701
702<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>&gt;</td><td class="name" onclick="toggle('isWritten0')">isWritten</td><td></td></tr>
703<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a contructor initializer if it is explicitly written in
704code (as opposed to implicitly added by the compiler).
705
706Given
707 struct Foo {
708 Foo() { }
709 Foo(int) : foo_("A") { }
710 string foo_;
711 };
712constructor(hasAnyConstructorInitializer(isWritten()))
713 will match Foo(int), but not Foo()
714</pre></td></tr>
715
716
717<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>&gt;</td><td class="name" onclick="toggle('hasOverloadedOperatorName0')">hasOverloadedOperatorName</td><td>std::string Name</td></tr>
718<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names.
719
720Matches overloaded operator names specified in strings without the
721"operator" prefix, such as "&lt;&lt;", for OverloadedOperatorCall's.
722
723Example matches a &lt;&lt; b
724 (matcher == overloadedOperatorCall(hasOverloadedOperatorName("&lt;&lt;")))
725 a &lt;&lt; b;
726 c &amp;&amp; d; assuming both operator&lt;&lt;
727 and operator&amp;&amp; are overloaded somewhere.
728</pre></td></tr>
729
730
731<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isDerivedFrom1')">isDerivedFrom</td><td>StringRef BaseName</td></tr>
732<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).
733</pre></td></tr>
734
735
736<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isExplicitTemplateSpecialization0')">isExplicitTemplateSpecialization</td><td></td></tr>
737<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or
738static member variable template instantiations.
739
740Given
741 template&lt;typename T&gt; void A(T t) { }
742 template&lt;&gt; void A(int N) { }
743function(isExplicitSpecialization())
744 matches the specialization A&lt;int&gt;().
745
746Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
747</pre></td></tr>
748
749
750<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isTemplateInstantiation0')">isTemplateInstantiation</td><td></td></tr>
751<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static
752member variable template instantiations.
753
754Given
755 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
756or
757 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
758record(hasName("::X"), isTemplateInstantiation())
759 matches the template instantiation of X&lt;A&gt;.
760
761But given
762 template &lt;typename T&gt; class X {}; class A {};
763 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
764record(hasName("::X"), isTemplateInstantiation())
765 does not match, as X&lt;A&gt; is an explicit template specialization.
766
767Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
768</pre></td></tr>
769
770
771<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;</td><td class="name" onclick="toggle('argumentCountIs0')">argumentCountIs</td><td>unsigned N</td></tr>
772<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has
773a specific number of arguments (including absent default arguments).
774
775Example matches f(0, 0) (matcher = call(argumentCountIs(2)))
776 void f(int x, int y);
777 f(0, 0);
778</pre></td></tr>
779
780
781<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;</td><td class="name" onclick="toggle('equals3')">equals</td><td>ValueT Value</td></tr>
782<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value.
783
784Example matches true (matcher = boolLiteral(equals(true)))
785 true
786
787Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
788 Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;
789</pre></td></tr>
790
791
792<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>&gt;</td><td class="name" onclick="toggle('statementCountIs0')">statementCountIs</td><td>unsigned N</td></tr>
793<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of
794child statements.
795
796Example: Given
797 { for (;;) {} }
798compoundStatement(statementCountIs(0)))
799 matches '{}'
800 but does not match the outer compound statement.
801</pre></td></tr>
802
803
804<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt;</td><td class="name" onclick="toggle('declCountIs0')">declCountIs</td><td>unsigned N</td></tr>
805<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of
806declarations.
807
808Example: Given
809 int a, b;
810 int c;
811 int d = 2, e;
812declCountIs(2)
813 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
814</pre></td></tr>
815
816
817<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;</td><td class="name" onclick="toggle('equals1')">equals</td><td>ValueT Value</td></tr>
818<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value.
819
820Example matches true (matcher = boolLiteral(equals(true)))
821 true
822
823Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
824 Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;
825</pre></td></tr>
826
827
828<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isDefinition0')">isDefinition</td><td></td></tr>
829<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached.
830
831Example matches A, va, fa
832 class A {};
833 class B; Doesn't match, as it has no body.
834 int va;
835 extern int vb; Doesn't match, as it doesn't define the variable.
836 void fa() {}
837 void fb(); Doesn't match, as it has no body.
838
839Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;
840</pre></td></tr>
841
842
843<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isExplicitTemplateSpecialization2')">isExplicitTemplateSpecialization</td><td></td></tr>
844<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or
845static member variable template instantiations.
846
847Given
848 template&lt;typename T&gt; void A(T t) { }
849 template&lt;&gt; void A(int N) { }
850function(isExplicitSpecialization())
851 matches the specialization A&lt;int&gt;().
852
853Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
854</pre></td></tr>
855
856
857<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isExternC0')">isExternC</td><td></td></tr>
858<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function declarations.
859
860Given:
861 extern "C" void f() {}
862 extern "C" { void g() {} }
863 void h() {}
864function(isExternC())
865 matches the declaration of f and g, but not the declaration h
866</pre></td></tr>
867
868
869<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isTemplateInstantiation2')">isTemplateInstantiation</td><td></td></tr>
870<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static
871member variable template instantiations.
872
873Given
874 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
875or
876 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
877record(hasName("::X"), isTemplateInstantiation())
878 matches the template instantiation of X&lt;A&gt;.
879
880But given
881 template &lt;typename T&gt; class X {}; class A {};
882 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
883record(hasName("::X"), isTemplateInstantiation())
884 does not match, as X&lt;A&gt; is an explicit template specialization.
885
886Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
887</pre></td></tr>
888
889
890<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;</td><td class="name" onclick="toggle('equals0')">equals</td><td>ValueT Value</td></tr>
891<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value.
892
893Example matches true (matcher = boolLiteral(equals(true)))
894 true
895
896Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
897 Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;
898</pre></td></tr>
899
900
901<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;</td><td class="name" onclick="toggle('isArrow0')">isArrow</td><td></td></tr>
902<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '-&gt;' as opposed
903to '.'.
904
905Member calls on the implicit this pointer match as called with '-&gt;'.
906
907Given
908 class Y {
909 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
910 int a;
911 static int b;
912 };
913memberExpression(isArrow())
914 matches this-&gt;x, x, y.x, a, this-&gt;b
915</pre></td></tr>
916
917
918<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;</td><td class="name" onclick="toggle('hasName0')">hasName</td><td>std::string Name</td></tr>
919<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name.
920
921Supports specifying enclosing namespaces or classes by prefixing the name
922with '&lt;enclosing&gt;::'.
923Does not match typedefs of an underlying type with the given name.
924
925Example matches X (Name == "X")
926 class X;
927
928Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
929 namespace a { namespace b { class X; } }
930</pre></td></tr>
931
932
933<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;</td><td class="name" onclick="toggle('matchesName0')">matchesName</td><td>std::string RegExp</td></tr>
934<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose full names partially match the
935given RegExp.
936
937Supports specifying enclosing namespaces or classes by
938prefixing the name with '&lt;enclosing&gt;::'. Does not match typedefs
939of an underlying type with the given name.
940
941Example matches X (regexp == "::X")
942 class X;
943
944Example matches X (regexp is one of "::X", "^foo::.*X", among others)
945 namespace foo { namespace bar { class X; } }
946</pre></td></tr>
947
948
949<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('asString0')">asString</td><td>std::string Name</td></tr>
950<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string.
951
952Given
953 class Y { public: void x(); };
954 void z() { Y* y; y-&gt;x(); }
955call(on(hasType(asString("class Y *"))))
956 matches y-&gt;x()
957</pre></td></tr>
958
959
960<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('isConstQualified0')">isConstQualified</td><td></td></tr>
961<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that
962include "top-level" const.
963
964Given
965 void a(int);
966 void b(int const);
967 void c(const int);
968 void d(const int*);
969 void e(int const) {};
970function(hasAnyParameter(hasType(isConstQualified())))
971 matches "void b(int const)", "void c(const int)" and
972 "void e(int const) {}". It does not match d as there
973 is no top-level const on the parameter type "const int *".
974</pre></td></tr>
975
976
977<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('isInteger0')">isInteger</td><td></td></tr>
978<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type.
979
980Given
981 void a(int);
982 void b(long);
983 void c(double);
984function(hasAnyParameter(hasType(isInteger())))
985matches "a(int)", "b(long)", but not "c(double)".
986</pre></td></tr>
987
988
989<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>&gt;</td><td class="name" onclick="toggle('isDefinition2')">isDefinition</td><td></td></tr>
990<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached.
991
992Example matches A, va, fa
993 class A {};
994 class B; Doesn't match, as it has no body.
995 int va;
996 extern int vb; Doesn't match, as it doesn't define the variable.
997 void fa() {}
998 void fb(); Doesn't match, as it has no body.
999
1000Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;
1001</pre></td></tr>
1002
1003
1004<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt;</td><td class="name" onclick="toggle('ofKind0')">ofKind</td><td>UnaryExprOrTypeTrait Kind</td></tr>
1005<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind.
1006
1007Given
1008 int x;
1009 int s = sizeof(x) + alignof(x)
1010unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
1011 matches sizeof(x)
1012</pre></td></tr>
1013
1014
1015<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasOperatorName1')">hasOperatorName</td><td>std::string Name</td></tr>
1016<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or
1017unary).
1018
1019Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
1020 !(a || b)
1021</pre></td></tr>
1022
1023
1024<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isDefinition1')">isDefinition</td><td></td></tr>
1025<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached.
1026
1027Example matches A, va, fa
1028 class A {};
1029 class B; Doesn't match, as it has no body.
1030 int va;
1031 extern int vb; Doesn't match, as it doesn't define the variable.
1032 void fa() {}
1033 void fb(); Doesn't match, as it has no body.
1034
1035Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;
1036</pre></td></tr>
1037
1038
1039<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isExplicitTemplateSpecialization1')">isExplicitTemplateSpecialization</td><td></td></tr>
1040<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or
1041static member variable template instantiations.
1042
1043Given
1044 template&lt;typename T&gt; void A(T t) { }
1045 template&lt;&gt; void A(int N) { }
1046function(isExplicitSpecialization())
1047 matches the specialization A&lt;int&gt;().
1048
1049Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
1050</pre></td></tr>
1051
1052
1053<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isTemplateInstantiation1')">isTemplateInstantiation</td><td></td></tr>
1054<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static
1055member variable template instantiations.
1056
1057Given
1058 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
1059or
1060 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
1061record(hasName("::X"), isTemplateInstantiation())
1062 matches the template instantiation of X&lt;A&gt;.
1063
1064But given
1065 template &lt;typename T&gt; class X {}; class A {};
1066 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
1067record(hasName("::X"), isTemplateInstantiation())
1068 does not match, as X&lt;A&gt; is an explicit template specialization.
1069
1070Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;
1071</pre></td></tr>
1072
1073<!--END_NARROWING_MATCHERS -->
1074</table>
1075
1076<!-- ======================================================================= -->
1077<h2 id="traversal-matchers">AST Traversal Matchers</h2>
1078<!-- ======================================================================= -->
1079
1080<p>Traversal matchers specify the relationship to other nodes that are
1081reachable from the current node.</p>
1082
1083<p>Note that there are special traversal matchers (has, hasDescendant, forEach and
1084forEachDescendant) which work on all nodes and allow users to write more generic
1085match expressions.</p>
1086
1087<table>
1088<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
1089<!-- START_TRAVERSAL_MATCHERS -->
1090
1091<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEach0')">forEach</td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
1092<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the
1093provided matcher.
1094
1095Example matches X, Y (matcher = record(forEach(record(hasName("X")))
1096 class X {}; Matches X, because X::X is a class of name X inside X.
1097 class Y { class X {}; };
1098 class Z { class Y { class X {}; }; }; Does not match Z.
1099
1100ChildT must be an AST base type.
1101
1102As opposed to 'has', 'forEach' will cause a match for each result that
1103matches instead of only on the first one.
1104
1105Usable as: Any Matcher
1106</pre></td></tr>
1107
1108
1109<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEachDescendant0')">forEachDescendant</td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
1110<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1111provided matcher.
1112
1113Example matches X, A, B, C
1114 (matcher = record(forEachDescendant(record(hasName("X")))))
1115 class X {}; Matches X, because X::X is a class of name X inside X.
1116 class A { class X {}; };
1117 class B { class C { class X {}; }; };
1118
1119DescendantT must be an AST base type.
1120
1121As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
1122each result that matches instead of only on the first one.
1123
1124Note: Recursively combined ForEachDescendant can cause many matches:
1125 record(forEachDescendant(record(forEachDescendant(record()))))
1126will match 10 times (plus injected class name matches) on:
1127 class A { class B { class C { class D { class E {}; }; }; }; };
1128
1129Usable as: Any Matcher
1130</pre></td></tr>
1131
1132
1133<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('has0')">has</td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
1134<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the
1135provided matcher.
1136
1137Example matches X, Y (matcher = record(has(record(hasName("X")))
1138 class X {}; Matches X, because X::X is a class of name X inside X.
1139 class Y { class X {}; };
1140 class Z { class Y { class X {}; }; }; Does not match Z.
1141
1142ChildT must be an AST base type.
1143
1144Usable as: Any Matcher
1145</pre></td></tr>
1146
1147
1148<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('hasDescendant0')">hasDescendant</td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
1149<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1150provided matcher.
1151
1152Example matches X, Y, Z
1153 (matcher = record(hasDescendant(record(hasName("X")))))
1154 class X {}; Matches X, because X::X is a class of name X inside X.
1155 class Y { class X {}; };
1156 class Z { class Y { class X {}; }; };
1157
1158DescendantT must be an AST base type.
1159
1160Usable as: Any Matcher
1161</pre></td></tr>
1162
1163
1164<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;</td><td class="name" onclick="toggle('hasBase0')">hasBase</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1165<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression.
1166
1167Given
1168 int i[5];
1169 void f() { i[1] = 42; }
1170arraySubscriptExpression(hasBase(implicitCast(
1171 hasSourceExpression(declarationReference()))))
1172 matches i[1] with the declarationReference() matching i
1173</pre></td></tr>
1174
1175
1176<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;</td><td class="name" onclick="toggle('hasIndex0')">hasIndex</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1177<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression.
1178
1179Given
1180 int i[5];
1181 void f() { i[1] = 42; }
1182arraySubscriptExpression(hasIndex(integerLiteral()))
1183 matches i[1] with the integerLiteral() matching 1
1184</pre></td></tr>
1185
1186
1187<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasEitherOperand0')">hasEitherOperand</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1188<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a
1189binary operator matches.
1190</pre></td></tr>
1191
1192
1193<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasLHS0')">hasLHS</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1194<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions.
1195
1196Example matches a (matcher = binaryOperator(hasLHS()))
1197 a || b
1198</pre></td></tr>
1199
1200
1201<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasRHS0')">hasRHS</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1202<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions.
1203
1204Example matches b (matcher = binaryOperator(hasRHS()))
1205 a || b
1206</pre></td></tr>
1207
1208
1209<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;</td><td class="name" onclick="toggle('hasDeclaration0')">hasDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1210<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a type if the declaration of the type matches the given
1211matcher.
1212
1213Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;
1214</pre></td></tr>
1215
1216
1217<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>&gt;</td><td class="name" onclick="toggle('hasAnyConstructorInitializer0')">hasAnyConstructorInitializer</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>&gt; InnerMatcher</td></tr>
1218<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer.
1219
1220Given
1221 struct Foo {
1222 Foo() : foo_(1) { }
1223 int foo_;
1224 };
1225record(has(constructor(hasAnyConstructorInitializer(anything()))))
1226 record matches Foo, hasAnyConstructorInitializer matches foo_(1)
1227</pre></td></tr>
1228
1229
1230<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>&gt;</td><td class="name" onclick="toggle('forField0')">forField</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>&gt; InnerMatcher</td></tr>
1231<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer.
1232
1233Given
1234 struct Foo {
1235 Foo() : foo_(1) { }
1236 int foo_;
1237 };
1238record(has(constructor(hasAnyConstructorInitializer(
1239 forField(hasName("foo_"))))))
1240 matches Foo
1241with forField matching foo_
1242</pre></td></tr>
1243
1244
1245<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>&gt;</td><td class="name" onclick="toggle('withInitializer0')">withInitializer</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1246<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer.
1247
1248Given
1249 struct Foo {
1250 Foo() : foo_(1) { }
1251 int foo_;
1252 };
1253record(has(constructor(hasAnyConstructorInitializer(
1254 withInitializer(integerLiteral(equals(1)))))))
1255 matches Foo
1256with withInitializer matching (1)
1257</pre></td></tr>
1258
1259
1260<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;</td><td class="name" onclick="toggle('on0')">on</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1261<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression.
1262
1263Example matches y.x() (matcher = call(on(hasType(record(hasName("Y"))))))
1264 class Y { public: void x(); };
1265 void z() { Y y; y.x(); }",
1266
1267FIXME: Overload to allow directly matching types?
1268</pre></td></tr>
1269
1270
1271<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;</td><td class="name" onclick="toggle('onImplicitObjectArgument0')">onImplicitObjectArgument</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1272<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre></pre></td></tr>
1273
1274
1275<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;</td><td class="name" onclick="toggle('thisPointerType1')">thisPointerType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1276<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration.
1277</pre></td></tr>
1278
1279
1280<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</td><td class="name" onclick="toggle('ofClass0')">ofClass</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt; InnerMatcher</td></tr>
1281<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration
1282belongs to.
1283
1284FIXME: Generalize this for other kinds of declarations.
1285FIXME: What other kind of declarations would we need to generalize
1286this to?
1287
1288Example matches A() in the last line
1289 (matcher = constructorCall(hasDeclaration(method(
1290 ofClass(hasName("A"))))))
1291 class A {
1292 public:
1293 A();
1294 };
1295 A a = A();
1296</pre></td></tr>
1297
1298
1299<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isDerivedFrom0')">isDerivedFrom</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt; Base</td></tr>
1300<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from
1301a class matching Base.
1302
1303Note that a class is considered to be also derived from itself.
1304
1305Example matches X, Y, Z, C (Base == hasName("X"))
1306 class X; A class is considered to be derived from itself
1307 class Y : public X {}; directly derived
1308 class Z : public Y {}; indirectly derived
1309 typedef X A;
1310 typedef A B;
1311 class C : public B {}; derived from a typedef of X
1312
1313In the following example, Bar matches isDerivedFrom(hasName("X")):
1314 class Foo;
1315 typedef Foo X;
1316 class Bar : public Foo {}; derived from a type that X is a typedef of
1317</pre></td></tr>
1318
1319
1320<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;</td><td class="name" onclick="toggle('callee1')">callee</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1321<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the
1322given matcher.
1323
1324Example matches y.x() (matcher = call(callee(method(hasName("x")))))
1325 class Y { public: void x(); };
1326 void z() { Y y; y.x();
1327</pre></td></tr>
1328
1329
1330<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;</td><td class="name" onclick="toggle('hasAnyArgument0')">hasAnyArgument</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1331<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call
1332expression.
1333
1334Given
1335 void x(int, int, int) { int y; x(1, y, 42); }
1336call(hasAnyArgument(declarationReference()))
1337 matches x(1, y, 42)
1338with hasAnyArgument(...)
1339 matching y
1340</pre></td></tr>
1341
1342
1343<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;</td><td class="name" onclick="toggle('hasArgument0')">hasArgument</td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1344<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor
1345call expression.
1346
1347Example matches y in x(y)
1348 (matcher = call(hasArgument(0, declarationReference())))
1349 void x(int) { int y; x(y); }
1350</pre></td></tr>
1351
1352
1353<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;</td><td class="name" onclick="toggle('hasDeclaration1')">hasDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1354<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a type if the declaration of the type matches the given
1355matcher.
1356
1357Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;
1358</pre></td></tr>
1359
1360
1361<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>&gt;</td><td class="name" onclick="toggle('hasSourceExpression0')">hasSourceExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1362<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression matches the given matcher.
1363
1364Example: matches "a string" (matcher =
1365 hasSourceExpression(constructorCall()))
1366class URL { URL(string); };
1367URL url = "a string";
1368</pre></td></tr>
1369
1370
1371<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;</td><td class="name" onclick="toggle('hasAnyTemplateArgument0')">hasAnyTemplateArgument</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
1372<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations that have at least one
1373TemplateArgument matching the given InnerMatcher.
1374
1375Given
1376 template&lt;typename T&gt; class A {};
1377 template&lt;&gt; class A&lt;double&gt; {};
1378 A&lt;int&gt; a;
1379classTemplateSpecialization(hasAnyTemplateArgument(
1380 refersToType(asString("int"))))
1381 matches the specialization A&lt;int&gt;
1382</pre></td></tr>
1383
1384
1385<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;</td><td class="name" onclick="toggle('hasTemplateArgument0')">hasTemplateArgument</td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
1386<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument
1387matches the given InnerMatcher.
1388
1389Given
1390 template&lt;typename T, typename U&gt; class A {};
1391 A&lt;bool, int&gt; b;
1392 A&lt;int, bool&gt; c;
1393classTemplateSpecialization(hasTemplateArgument(
1394 1, refersToType(asString("int"))))
1395 matches the specialization A&lt;bool, int&gt;
1396</pre></td></tr>
1397
1398
1399<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>&gt;</td><td class="name" onclick="toggle('hasAnySubstatement0')">hasAnySubstatement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1400<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches
1401a given matcher.
1402
1403Given
1404 { {}; 1+2; }
1405hasAnySubstatement(compoundStatement())
1406 matches '{ {}; 1+2; }'
1407with compoundStatement()
1408 matching '{}'
1409</pre></td></tr>
1410
1411
1412<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>&gt;</td><td class="name" onclick="toggle('hasCondition4')">hasCondition</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1413<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop,
1414or conditional operator.
1415
1416Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1417 if (true) {}
1418</pre></td></tr>
1419
1420
1421<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>&gt;</td><td class="name" onclick="toggle('hasFalseExpression0')">hasFalseExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1422<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator.
1423
1424Example matches b
1425 condition ? a : b
1426</pre></td></tr>
1427
1428
1429<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>&gt;</td><td class="name" onclick="toggle('hasTrueExpression0')">hasTrueExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1430<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator.
1431
1432Example matches a
1433 condition ? a : b
1434</pre></td></tr>
1435
1436
1437<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>&gt;</td><td class="name" onclick="toggle('throughUsingDecl0')">throughUsingDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>&gt; InnerMatcher</td></tr>
1438<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a
1439specific using shadow declaration.
1440
1441FIXME: This currently only works for functions. Fix.
1442
1443Given
1444 namespace a { void f() {} }
1445 using a::f;
1446 void g() {
1447 f(); Matches this ..
1448 a::f(); .. but not this.
1449 }
1450declarationReference(throughUsingDeclaration(anything()))
1451 matches f()
1452</pre></td></tr>
1453
1454
1455<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>&gt;</td><td class="name" onclick="toggle('to0')">to</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1456<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the
1457specified matcher.
1458
1459Example matches x in if(x)
1460 (matcher = declarationReference(to(variable(hasName("x")))))
1461 bool x;
1462 if (x) {}
1463</pre></td></tr>
1464
1465
1466<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt;</td><td class="name" onclick="toggle('containsDeclaration0')">containsDeclaration</td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1467<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement.
1468
1469Note that this does not work for global declarations because the AST
1470breaks up multiple-declaration DeclStmt's into multiple single-declaration
1471DeclStmt's.
1472Example: Given non-global declarations
1473 int a, b = 0;
1474 int c;
1475 int d = 2, e;
1476declarationStatement(containsDeclaration(
1477 0, variable(hasInitializer(anything()))))
1478 matches only 'int d = 2, e;', and
1479declarationStatement(containsDeclaration(1, variable()))
1480 matches 'int a, b = 0' as well as 'int d = 2, e;'
1481 but 'int c;' is not matched.
1482</pre></td></tr>
1483
1484
1485<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt;</td><td class="name" onclick="toggle('hasSingleDecl0')">hasSingleDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1486<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration.
1487
1488Given
1489 int a, b;
1490 int c;
1491declarationStatement(hasSingleDecl(anything()))
1492 matches 'int c;' but not 'int a, b;'.
1493</pre></td></tr>
1494
1495
1496<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>&gt;</td><td class="name" onclick="toggle('hasBody0')">hasBody</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1497<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', or 'do while' statement that has
1498a given body.
1499
1500Given
1501 for (;;) {}
1502hasBody(compoundStatement())
1503 matches 'for (;;) {}'
1504with compoundStatement()
1505 matching '{}'
1506</pre></td></tr>
1507
1508
1509<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>&gt;</td><td class="name" onclick="toggle('hasCondition3')">hasCondition</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1510<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop,
1511or conditional operator.
1512
1513Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1514 if (true) {}
1515</pre></td></tr>
1516
1517
1518<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>&gt;</td><td class="name" onclick="toggle('hasDestinationType0')">hasDestinationType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
1519<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher.
1520
1521(Note: Clang's AST refers to other conversions as "casts" too, and calls
1522actual casts "explicit" casts.)
1523</pre></td></tr>
1524
1525
1526<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('hasType3')">hasType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1527<tr><td colspan="4" class="doc" id="hasType3"><pre>Overloaded to match the declaration of the expression's or value
1528declaration's type.
1529
1530In case of a value declaration (for example a variable declaration),
1531this resolves one layer of indirection. For example, in the value
1532declaration "X x;", record(hasName("X")) matches the declaration of X,
1533while variable(hasType(record(hasName("X")))) matches the declaration
1534of x."
1535
1536Example matches x (matcher = expression(hasType(record(hasName("X")))))
1537 and z (matcher = variable(hasType(record(hasName("X")))))
1538 class X {};
1539 void y(X &amp;x) { x; X z; }
1540
1541Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>&gt;
1542</pre></td></tr>
1543
1544
1545<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('ignoringImpCasts0')">ignoringImpCasts</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1546<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts
1547are stripped off.
1548
1549Parentheses and explicit casts are not discarded.
1550Given
1551 int arr[5];
1552 int a = 0;
1553 char b = 0;
1554 const int c = a;
1555 int *d = arr;
1556 long e = (long) 0l;
1557The matchers
1558 variable(hasInitializer(ignoringImpCasts(integerLiteral())))
1559 variable(hasInitializer(ignoringImpCasts(declarationReference())))
1560would match the declarations for a, b, c, and d, but not e.
1561While
1562 variable(hasInitializer(integerLiteral()))
1563 variable(hasInitializer(declarationReference()))
1564only match the declarations for b, c, and d.
1565</pre></td></tr>
1566
1567
1568<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('ignoringParenCasts0')">ignoringParenCasts</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1569<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and
1570casts are stripped off.
1571
1572Implicit and non-C Style casts are also discarded.
1573Given
1574 int a = 0;
1575 char b = (0);
1576 void* c = reinterpret_cast&lt;char*&gt;(0);
1577 char d = char(0);
1578The matcher
1579 variable(hasInitializer(ignoringParenCasts(integerLiteral())))
1580would match the declarations for a, b, c, and d.
1581while
1582 variable(hasInitializer(integerLiteral()))
1583only match the declaration for a.
1584</pre></td></tr>
1585
1586
1587<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('ignoringParenImpCasts0')">ignoringParenImpCasts</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1588<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and
1589parentheses are stripped off.
1590
1591Explicit casts are not discarded.
1592Given
1593 int arr[5];
1594 int a = 0;
1595 char b = (0);
1596 const int c = a;
1597 int *d = (arr);
1598 long e = ((long) 0l);
1599The matchers
1600 variable(hasInitializer(ignoringParenImpCasts(
1601 integerLiteral())))
1602 variable(hasInitializer(ignoringParenImpCasts(
1603 declarationReference())))
1604would match the declarations for a, b, c, and d, but not e.
1605while
1606 variable(hasInitializer(integerLiteral()))
1607 variable(hasInitializer(declarationReference()))
1608would only match the declaration for a.
1609</pre></td></tr>
1610
1611
1612<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;</td><td class="name" onclick="toggle('hasBody1')">hasBody</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1613<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', or 'do while' statement that has
1614a given body.
1615
1616Given
1617 for (;;) {}
1618hasBody(compoundStatement())
1619 matches 'for (;;) {}'
1620with compoundStatement()
1621 matching '{}'
1622</pre></td></tr>
1623
1624
1625<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;</td><td class="name" onclick="toggle('hasCondition1')">hasCondition</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1626<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop,
1627or conditional operator.
1628
1629Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1630 if (true) {}
1631</pre></td></tr>
1632
1633
1634<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;</td><td class="name" onclick="toggle('hasIncrement0')">hasIncrement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1635<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop.
1636
1637Example:
1638 forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
1639matches '++x' in
1640 for (x; x &lt; N; ++x) { }
1641</pre></td></tr>
1642
1643
1644<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;</td><td class="name" onclick="toggle('hasLoopInit0')">hasLoopInit</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1645<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop.
1646
1647Example:
1648 forStmt(hasLoopInit(declarationStatement()))
1649matches 'int x = 0' in
1650 for (int x = 0; x &lt; N; ++x) { }
1651</pre></td></tr>
1652
1653
1654<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('hasAnyParameter0')">hasAnyParameter</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>&gt; InnerMatcher</td></tr>
1655<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function declaration.
1656
1657Does not match the 'this' parameter of a method.
1658
1659Given
1660 class X { void f(int x, int y, int z) {} };
1661method(hasAnyParameter(hasName("y")))
1662 matches f(int x, int y, int z) {}
1663with hasAnyParameter(...)
1664 matching int y
1665</pre></td></tr>
1666
1667
1668<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('hasParameter0')">hasParameter</td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>&gt; InnerMatcher</td></tr>
1669<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function declaration.
1670
1671Given
1672 class X { void f(int x) {} };
1673method(hasParameter(0, hasType(variable())))
1674 matches f(int x) {}
1675with hasParameter(...)
1676 matching int x
1677</pre></td></tr>
1678
1679
1680<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('returns0')">returns</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
1681<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration.
1682
1683Given:
1684 class X { int f() { return 1; } };
1685method(returns(asString("int")))
1686 matches int f() { return 1; }
1687</pre></td></tr>
1688
1689
1690<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>&gt;</td><td class="name" onclick="toggle('hasCondition0')">hasCondition</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1691<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop,
1692or conditional operator.
1693
1694Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1695 if (true) {}
1696</pre></td></tr>
1697
1698
1699<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>&gt;</td><td class="name" onclick="toggle('hasConditionVariableStatement0')">hasConditionVariableStatement</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt; InnerMatcher</td></tr>
1700<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement.
1701
1702Given
1703 if (A* a = GetAPointer()) {}
1704hasConditionVariableStatment(...)
1705 matches 'A* a = GetAPointer()'.
1706</pre></td></tr>
1707
1708
1709<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>&gt;</td><td class="name" onclick="toggle('hasImplicitDestinationType0')">hasImplicitDestinationType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
1710<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given
1711matcher.
1712
1713FIXME: Unit test this matcher
1714</pre></td></tr>
1715
1716
1717<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;</td><td class="name" onclick="toggle('hasObjectExpression0')">hasObjectExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1718<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is
1719matched by a given matcher.
1720
1721Given
1722 struct X { int m; };
1723 void f(X x) { x.m; m; }
1724memberExpression(hasObjectExpression(hasType(record(hasName("X")))))))
1725 matches "x.m" and "m"
1726with hasObjectExpression(...)
1727 matching "x" and the implicit object expression of "m" which has type X*.
1728</pre></td></tr>
1729
1730
1731<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;</td><td class="name" onclick="toggle('member0')">member</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>&gt; InnerMatcher</td></tr>
1732<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a
1733given matcher.
1734
1735Given
1736 struct { int first, second; } first, second;
1737 int i(second.first);
1738 int j(first.second);
1739memberExpression(member(hasName("first")))
1740 matches second.first
1741 but not first.second (because the member name there is "second").
1742</pre></td></tr>
1743
1744
1745<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('hasDeclaration2')">hasDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1746<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a type if the declaration of the type matches the given
1747matcher.
1748
1749Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;
1750</pre></td></tr>
1751
1752
1753<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('pointsTo1')">pointsTo</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1754<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration.
1755</pre></td></tr>
1756
1757
1758<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</td><td class="name" onclick="toggle('references1')">references</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1759<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration.
1760</pre></td></tr>
1761
1762
1763<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('alignOfExpr0')">alignOfExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt; InnerMatcher</td></tr>
1764<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1765alignof.
1766</pre></td></tr>
1767
1768
1769<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('sizeOfExpr0')">sizeOfExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt; InnerMatcher</td></tr>
1770<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1771sizeof.
1772</pre></td></tr>
1773
1774
1775<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt;</td><td class="name" onclick="toggle('refersToDeclaration0')">refersToDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1776<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a TemplateArgument that refers to a certain declaration.
1777
1778Given
1779 template&lt;typename T&gt; struct A {};
1780 struct B { B* next; };
1781 A&lt;&amp;B::next&gt; a;
1782classTemplateSpecialization(hasAnyTemplateArgument(
1783 refersToDeclaration(field(hasName("next"))))
1784 matches the specialization A&lt;&amp;B::next&gt; with field(...) matching
1785 B::next
1786</pre></td></tr>
1787
1788
1789<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt;</td><td class="name" onclick="toggle('refersToType0')">refersToType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
1790<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type.
1791
1792Given
1793 struct X {};
1794 template&lt;typename T&gt; struct A {};
1795 A&lt;X&gt; a;
1796classTemplateSpecialization(hasAnyTemplateArgument(
1797 refersToType(class(hasName("X")))))
1798 matches the specialization A&lt;X&gt;
1799</pre></td></tr>
1800
1801
1802<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt;</td><td class="name" onclick="toggle('hasArgumentOfType0')">hasArgumentOfType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
1803<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument.
1804
1805Given
1806 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
1807unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
1808 matches sizeof(a) and alignof(c)
1809</pre></td></tr>
1810
1811
1812<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>&gt;</td><td class="name" onclick="toggle('hasUnaryOperand0')">hasUnaryOperand</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1813<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches.
1814
1815Example matches true (matcher = hasOperand(boolLiteral(equals(true))))
1816 !true
1817</pre></td></tr>
1818
1819
1820<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>&gt;</td><td class="name" onclick="toggle('hasAnyUsingShadowDecl0')">hasAnyUsingShadowDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>&gt; InnerMatcher</td></tr>
1821<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration.
1822
1823Given
1824 namespace X { void b(); }
1825 using X::b;
1826usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
1827 matches using X::b </pre></td></tr>
1828
1829
1830<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>&gt;</td><td class="name" onclick="toggle('hasTargetDecl0')">hasTargetDecl</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt; InnerMatcher</td></tr>
1831<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is
1832matched by the given matcher.
1833
1834Given
1835 namespace X { int a; void b(); }
1836 using X::a;
1837 using X::b;
1838usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(function())))
1839 matches using X::b but not using X::a </pre></td></tr>
1840
1841
1842<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>&gt;</td><td class="name" onclick="toggle('hasType2')">hasType</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1843<tr><td colspan="4" class="doc" id="hasType2"><pre>Overloaded to match the declaration of the expression's or value
1844declaration's type.
1845
1846In case of a value declaration (for example a variable declaration),
1847this resolves one layer of indirection. For example, in the value
1848declaration "X x;", record(hasName("X")) matches the declaration of X,
1849while variable(hasType(record(hasName("X")))) matches the declaration
1850of x."
1851
1852Example matches x (matcher = expression(hasType(record(hasName("X")))))
1853 and z (matcher = variable(hasType(record(hasName("X")))))
1854 class X {};
1855 void y(X &amp;x) { x; X z; }
1856
1857Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>&gt;
1858</pre></td></tr>
1859
1860
1861<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasInitializer0')">hasInitializer</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1862<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression
1863that matches the given matcher.
1864
1865Example matches x (matcher = variable(hasInitializer(call())))
1866 bool y() { return true; }
1867 bool x = y();
1868</pre></td></tr>
1869
1870
1871<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>&gt;</td><td class="name" onclick="toggle('hasBody2')">hasBody</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
1872<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', or 'do while' statement that has
1873a given body.
1874
1875Given
1876 for (;;) {}
1877hasBody(compoundStatement())
1878 matches 'for (;;) {}'
1879with compoundStatement()
1880 matching '{}'
1881</pre></td></tr>
1882
1883
1884<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>&gt;</td><td class="name" onclick="toggle('hasCondition2')">hasCondition</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1885<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop,
1886or conditional operator.
1887
1888Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1889 if (true) {}
1890</pre></td></tr>
1891
1892<!--END_TRAVERSAL_MATCHERS -->
1893</table>
1894
1895</div>
1896</body>
1897</html>
1898
1899