blob: 55ac8ca4b3467b1e44e40a8dfdbeb1d9c929d096 [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
Manuel Klimeke44a0062012-08-26 23:55:24 +000079<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('classTemplateDecl0')">classTemplateDecl</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="classTemplateDecl0"><pre>Matches C++ class template declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +000081
82Example matches Z
83 template&lt;class T&gt; class Z {};
84</pre></td></tr>
85
86
Manuel Klimeke44a0062012-08-26 23:55:24 +000087<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('classTemplateSpecializationDecl0')">classTemplateSpecializationDecl</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="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations.
Manuel Klimek1da79332012-08-20 20:54:03 +000089
90Given
91 template&lt;typename T&gt; class A {};
92 template&lt;&gt; class A&lt;double&gt; {};
93 A&lt;int&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +000094classTemplateSpecializationDecl()
Manuel Klimek1da79332012-08-20 20:54:03 +000095 matches the specializations A&lt;int&gt; and A&lt;double&gt;
96</pre></td></tr>
97
98
Manuel Klimeke44a0062012-08-26 23:55:24 +000099<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('constructorDecl0')">constructorDecl</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="constructorDecl0"><pre>Matches C++ constructor declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000101
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000123<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('destructorDecl0')">destructorDecl</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="destructorDecl0"><pre>Matches explicit C++ destructor declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000125
126Example matches Foo::~Foo()
127 class Foo {
128 public:
129 virtual ~Foo();
130 };
131</pre></td></tr>
132
133
Manuel Klimeke44a0062012-08-26 23:55:24 +0000134<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('enumConstantDecl0')">enumConstantDecl</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="enumConstantDecl0"><pre>Matches enum constants.
Manuel Klimek1da79332012-08-20 20:54:03 +0000136
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000154<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('fieldDecl0')">fieldDecl</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="fieldDecl0"><pre>Matches field declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000156
157Given
158 class X { int m; };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000159fieldDecl()
Manuel Klimek1da79332012-08-20 20:54:03 +0000160 matches 'm'.
161</pre></td></tr>
162
163
Manuel Klimeke44a0062012-08-26 23:55:24 +0000164<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('functionDecl0')">functionDecl</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="functionDecl0"><pre>Matches function declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000166
167Example matches f
168 void f();
169</pre></td></tr>
170
171
Manuel Klimeke44a0062012-08-26 23:55:24 +0000172<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('functionTemplateDecl0')">functionTemplateDecl</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="functionTemplateDecl0"><pre>Matches C++ function template declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000174
175Example matches f
176 template&lt;class T&gt; void f(T t) {}
177</pre></td></tr>
178
179
Manuel Klimeke44a0062012-08-26 23:55:24 +0000180<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('methodDecl0')">methodDecl</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="methodDecl0"><pre>Matches method declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000182
183Example matches y
184 class X { void y() };
185</pre></td></tr>
186
187
Manuel Klimeke44a0062012-08-26 23:55:24 +0000188<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('namedDecl0')">namedDecl</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="namedDecl0"><pre>Matches a declaration of anything that could have a name.
Manuel Klimek1da79332012-08-20 20:54:03 +0000190
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000201<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('recordDecl0')">recordDecl</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="recordDecl0"><pre>Matches C++ class declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000203
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000220<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('varDecl0')">varDecl</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="varDecl0"><pre>Matches variable declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000222
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000263<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('constCastExpr0')">constCastExpr</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="constCastExpr0"><pre>Matches a const_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000265
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000273<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('dynamicCastExpr0')">dynamicCastExpr</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="dynamicCastExpr0"><pre>Matches a dynamic_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000275
276Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +0000277 dynamicCastExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000278matches
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000287<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('explicitCastExpr0')">explicitCastExpr</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="explicitCastExpr0"><pre>Matches explicit cast expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000289
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000308<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('functionalCastExpr0')">functionalCastExpr</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="functionalCastExpr0"><pre>Matches functional cast expressions
Manuel Klimek1da79332012-08-20 20:54:03 +0000310
311Example: Matches Foo(bar);
312 Foo f = bar;
313 Foo g = (Foo) bar;
314 Foo h = Foo(bar);
315</pre></td></tr>
316
317
Manuel Klimeke44a0062012-08-26 23:55:24 +0000318<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('implicitCastExpr0')">implicitCastExpr</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="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST.
Manuel Klimek1da79332012-08-20 20:54:03 +0000320
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000335<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('reinterpretCastExpr0')">reinterpretCastExpr</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="reinterpretCastExpr0"><pre>Matches a reinterpret_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000337
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000347<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('staticCastExpr0')">staticCastExpr</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="staticCastExpr0"><pre>Matches a C++ static_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000349
350hasDestinationType
351reinterpretCast
352
353Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +0000354 staticCastExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000355matches
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000388<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('bindTemporaryExpr0')">bindTemporaryExpr</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="bindTemporaryExpr0"><pre>Matches nodes where temporaries are created.
Manuel Klimek1da79332012-08-20 20:54:03 +0000390
391Example matches FunctionTakesString(GetStringByValue())
Manuel Klimeke44a0062012-08-26 23:55:24 +0000392 (matcher = bindTemporaryExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000393 FunctionTakesString(GetStringByValue());
394 FunctionTakesStringByPointer(GetStringPointer());
395</pre></td></tr>
396
397
Manuel Klimeke44a0062012-08-26 23:55:24 +0000398<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('callExpr0')">callExpr</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="callExpr0"><pre>Matches call expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000400
401Example matches x.y() and y()
402 X x;
403 x.y();
404 y();
405</pre></td></tr>
406
407
Manuel Klimeke44a0062012-08-26 23:55:24 +0000408<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('compoundStmt0')">compoundStmt</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="compoundStmt0"><pre>Matches compound statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000410
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000424<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('constructExpr0')">constructExpr</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="constructExpr0"><pre>Matches constructor call expressions (including implicit ones).
Manuel Klimek1da79332012-08-20 20:54:03 +0000426
427Example matches string(ptr, n) and ptr within arguments of f
Manuel Klimeke44a0062012-08-26 23:55:24 +0000428 (matcher = constructExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000429 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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000436<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('declRefExpr0')">declRefExpr</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="declRefExpr0"><pre>Matches expressions that refer to declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000438
439Example matches x in if (x)
440 bool x;
441 if (x) {}
442</pre></td></tr>
443
444
Manuel Klimeke44a0062012-08-26 23:55:24 +0000445<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('declStmt0')">declStmt</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="declStmt0"><pre>Matches declaration statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000447
448Given
449 int a;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000450declStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +0000451 matches 'int a'.
452</pre></td></tr>
453
454
Manuel Klimeke44a0062012-08-26 23:55:24 +0000455<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('defaultArgExpr0')">defaultArgExpr</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="defaultArgExpr0"><pre>Matches the value of a default argument at the call site.
Manuel Klimek1da79332012-08-20 20:54:03 +0000457
458Example matches the CXXDefaultArgExpr placeholder inserted for the
459 default value of the second parameter in the call expression f(42)
Manuel Klimeke44a0062012-08-26 23:55:24 +0000460 (matcher = defaultArgExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000461 void f(int x, int y = 0);
462 f(42);
463</pre></td></tr>
464
465
Manuel Klimeke44a0062012-08-26 23:55:24 +0000466<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('deleteExpr0')">deleteExpr</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="deleteExpr0"><pre>Matches delete expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000468
469Given
470 delete X;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000471deleteExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000472 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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000486<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('expr0')">expr</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="expr0"><pre>Matches expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000488
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
Manuel Klimeke44a0062012-08-26 23:55:24 +0000522<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('materializeTemporaryExpr0')">materializeTemporaryExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>&gt;...</td></tr>
523<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized.
524
525Example: Given
526 struct T {void func()};
527 T f();
528 void g(T);
529materializeTemporaryExpr() matches 'f()' in these statements
530 T u(f());
531 g(f());
532but does not match
533 f();
534 f().func();
535</pre></td></tr>
536
537
538<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('memberCallExpr0')">memberCallExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;...</td></tr>
539<tr><td colspan="4" class="doc" id="memberCallExpr0"><pre>Matches member call expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000540
541Example matches x.y()
542 X x;
543 x.y();
544</pre></td></tr>
545
546
Manuel Klimeke44a0062012-08-26 23:55:24 +0000547<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('memberExpr0')">memberExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;...</td></tr>
548<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000549
550Given
551 class Y {
552 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
553 int a; static int b;
554 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000555memberExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000556 matches this-&gt;x, x, y.x, a, this-&gt;b
557</pre></td></tr>
558
559
Manuel Klimeke44a0062012-08-26 23:55:24 +0000560<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('newExpr0')">newExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>&gt;...</td></tr>
561<tr><td colspan="4" class="doc" id="newExpr0"><pre>Matches new expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000562
563Given
564 new X;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000565newExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000566 matches 'new X'.
567</pre></td></tr>
568
569
Manuel Klimeke44a0062012-08-26 23:55:24 +0000570<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('operatorCallExpr0')">operatorCallExpr</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>&gt;...</td></tr>
571<tr><td colspan="4" class="doc" id="operatorCallExpr0"><pre>Matches overloaded operator calls.
Manuel Klimek1da79332012-08-20 20:54:03 +0000572
573Note that if an operator isn't overloaded, it won't match. Instead, use
574binaryOperator matcher.
575Currently it does not match operators such as new delete.
576FIXME: figure out why these do not match?
577
578Example matches both operator&lt;&lt;((o &lt;&lt; b), c) and operator&lt;&lt;(o, b)
Manuel Klimeke44a0062012-08-26 23:55:24 +0000579 (matcher = operatorCallExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000580 ostream &amp;operator&lt;&lt; (ostream &amp;out, int i) { };
581 ostream &amp;o; int b = 1, c = 1;
582 o &lt;&lt; b &lt;&lt; c;
583</pre></td></tr>
584
585
Manuel Klimeke44a0062012-08-26 23:55:24 +0000586<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('stmt0')">stmt</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;...</td></tr>
587<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000588
589Given
590 { ++a; }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000591stmt()
Manuel Klimek1da79332012-08-20 20:54:03 +0000592 matches both the compound statement '{ ++a; }' and '++a'.
593</pre></td></tr>
594
595
596<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>
597<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements.
598
599Given
600 switch(a) { case 42: break; default: break; }
601switchCase()
602 matches 'case 42: break;' and 'default: break;'.
603</pre></td></tr>
604
605
606<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>
607<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
608
609Given
610 Foo x = bar;
611 int y = sizeof(x) + alignof(x);
612unaryExprOrTypeTraitExpr()
613 matches sizeof(x) and alignof(x)
614</pre></td></tr>
615
616
617<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>
618<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions.
619
620Example matches !a
621 !a || b
622</pre></td></tr>
623
624
625<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>
626<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements.
627
628Given
629 while (true) {}
630whileStmt()
631 matches 'while (true) {}'.
632</pre></td></tr>
633
634<!--END_DECL_MATCHERS -->
635</table>
636
637<!-- ======================================================================= -->
638<h2 id="narrowing-matchers">Narrowing Matchers</h2>
639<!-- ======================================================================= -->
640
641<p>Narrowing matchers match certain attributes on the current node, thus
642narrowing down the set of nodes of the current type to match on.</p>
643
644<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless)
645which allow users to create more powerful match expressions.</p>
646
647<table>
648<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
649<!-- START_NARROWING_MATCHERS -->
650
651<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>
652<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match.
653
654Usable as: Any Matcher
655</pre></td></tr>
656
657
658<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>
659<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches.
660
661Usable as: Any Matcher
662</pre></td></tr>
663
664
665<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('anything0')">anything</td><td></td></tr>
666<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node.
667
668Useful when another matcher requires a child matcher, but there's no
669additional constraint. This will often be used with an explicit conversion
670to an internal::Matcher&lt;&gt; type such as TypeMatcher.
671
672Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
673"int* p" and "void f()" in
674 int* p;
675 void f();
676
677Usable as: Any Matcher
678</pre></td></tr>
679
680
681<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('unless0')">unless</td><td>Matcher&lt;*&gt; InnerMatcher</td></tr>
682<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match.
683
Manuel Klimeke44a0062012-08-26 23:55:24 +0000684Example matches Y (matcher = recordDecl(unless(hasName("X"))))
Manuel Klimek1da79332012-08-20 20:54:03 +0000685 class X {};
686 class Y {};
687
688Usable as: Any Matcher
689</pre></td></tr>
690
691
692<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>
693<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or
694unary).
695
696Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
697 !(a || b)
698</pre></td></tr>
699
700
701<tr><td>Matcher&lt;CXXBoolLiteral&gt;</td><td class="name" onclick="toggle('equals2')">equals</td><td>ValueT Value</td></tr>
702<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value.
703
704Example matches true (matcher = boolLiteral(equals(true)))
705 true
706
707Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
708 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;
709</pre></td></tr>
710
711
712<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>
713<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a constructor declaration that has been implicitly added
714by the compiler (eg. implicit defaultcopy constructors).
715</pre></td></tr>
716
717
718<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>
719<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a contructor initializer if it is explicitly written in
720code (as opposed to implicitly added by the compiler).
721
722Given
723 struct Foo {
724 Foo() { }
725 Foo(int) : foo_("A") { }
726 string foo_;
727 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000728constructorDecl(hasAnyConstructorInitializer(isWritten()))
Manuel Klimek1da79332012-08-20 20:54:03 +0000729 will match Foo(int), but not Foo()
730</pre></td></tr>
731
732
733<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>
734<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names.
735
736Matches overloaded operator names specified in strings without the
737"operator" prefix, such as "&lt;&lt;", for OverloadedOperatorCall's.
738
739Example matches a &lt;&lt; b
Manuel Klimeke44a0062012-08-26 23:55:24 +0000740 (matcher == operatorCallExpr(hasOverloadedOperatorName("&lt;&lt;")))
Manuel Klimek1da79332012-08-20 20:54:03 +0000741 a &lt;&lt; b;
742 c &amp;&amp; d; assuming both operator&lt;&lt;
743 and operator&amp;&amp; are overloaded somewhere.
744</pre></td></tr>
745
746
747<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>
748<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).
749</pre></td></tr>
750
751
752<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>
753<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or
754static member variable template instantiations.
755
756Given
757 template&lt;typename T&gt; void A(T t) { }
758 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000759functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +0000760 matches the specialization A&lt;int&gt;().
761
762Usable 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;
763</pre></td></tr>
764
765
766<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>
767<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static
768member variable template instantiations.
769
770Given
771 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
772or
773 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000774recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000775 matches the template instantiation of X&lt;A&gt;.
776
777But given
778 template &lt;typename T&gt; class X {}; class A {};
779 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000780recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000781 does not match, as X&lt;A&gt; is an explicit template specialization.
782
783Usable 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;
784</pre></td></tr>
785
786
787<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>
788<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has
789a specific number of arguments (including absent default arguments).
790
Manuel Klimeke44a0062012-08-26 23:55:24 +0000791Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
Manuel Klimek1da79332012-08-20 20:54:03 +0000792 void f(int x, int y);
793 f(0, 0);
794</pre></td></tr>
795
796
797<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>
798<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value.
799
800Example matches true (matcher = boolLiteral(equals(true)))
801 true
802
803Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
804 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;
805</pre></td></tr>
806
807
808<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>
809<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of
810child statements.
811
812Example: Given
813 { for (;;) {} }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000814compoundStmt(statementCountIs(0)))
Manuel Klimek1da79332012-08-20 20:54:03 +0000815 matches '{}'
816 but does not match the outer compound statement.
817</pre></td></tr>
818
819
820<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>
821<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of
822declarations.
823
824Example: Given
825 int a, b;
826 int c;
827 int d = 2, e;
828declCountIs(2)
829 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
830</pre></td></tr>
831
832
833<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>
834<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value.
835
836Example matches true (matcher = boolLiteral(equals(true)))
837 true
838
839Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
840 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;
841</pre></td></tr>
842
843
844<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>
845<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached.
846
847Example matches A, va, fa
848 class A {};
849 class B; Doesn't match, as it has no body.
850 int va;
851 extern int vb; Doesn't match, as it doesn't define the variable.
852 void fa() {}
853 void fb(); Doesn't match, as it has no body.
854
855Usable 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;
856</pre></td></tr>
857
858
859<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>
860<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or
861static member variable template instantiations.
862
863Given
864 template&lt;typename T&gt; void A(T t) { }
865 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000866functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +0000867 matches the specialization A&lt;int&gt;().
868
869Usable 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;
870</pre></td></tr>
871
872
873<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>
874<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function declarations.
875
876Given:
877 extern "C" void f() {}
878 extern "C" { void g() {} }
879 void h() {}
Manuel Klimeke44a0062012-08-26 23:55:24 +0000880functionDecl(isExternC())
Manuel Klimek1da79332012-08-20 20:54:03 +0000881 matches the declaration of f and g, but not the declaration h
882</pre></td></tr>
883
884
885<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>
886<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static
887member variable template instantiations.
888
889Given
890 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
891or
892 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000893recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000894 matches the template instantiation of X&lt;A&gt;.
895
896But given
897 template &lt;typename T&gt; class X {}; class A {};
898 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000899recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000900 does not match, as X&lt;A&gt; is an explicit template specialization.
901
902Usable 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;
903</pre></td></tr>
904
905
906<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>
907<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value.
908
909Example matches true (matcher = boolLiteral(equals(true)))
910 true
911
912Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
913 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;
914</pre></td></tr>
915
916
917<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>
918<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '-&gt;' as opposed
919to '.'.
920
921Member calls on the implicit this pointer match as called with '-&gt;'.
922
923Given
924 class Y {
925 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
926 int a;
927 static int b;
928 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000929memberExpr(isArrow())
Manuel Klimek1da79332012-08-20 20:54:03 +0000930 matches this-&gt;x, x, y.x, a, this-&gt;b
931</pre></td></tr>
932
933
934<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>
935<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name.
936
937Supports specifying enclosing namespaces or classes by prefixing the name
938with '&lt;enclosing&gt;::'.
939Does not match typedefs of an underlying type with the given name.
940
941Example matches X (Name == "X")
942 class X;
943
944Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
945 namespace a { namespace b { class X; } }
946</pre></td></tr>
947
948
949<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>
950<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose full names partially match the
951given RegExp.
952
953Supports specifying enclosing namespaces or classes by
954prefixing the name with '&lt;enclosing&gt;::'. Does not match typedefs
955of an underlying type with the given name.
956
957Example matches X (regexp == "::X")
958 class X;
959
960Example matches X (regexp is one of "::X", "^foo::.*X", among others)
961 namespace foo { namespace bar { class X; } }
962</pre></td></tr>
963
964
965<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>
966<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string.
967
968Given
969 class Y { public: void x(); };
970 void z() { Y* y; y-&gt;x(); }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000971callExpr(on(hasType(asString("class Y *"))))
Manuel Klimek1da79332012-08-20 20:54:03 +0000972 matches y-&gt;x()
973</pre></td></tr>
974
975
976<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>
977<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that
978include "top-level" const.
979
980Given
981 void a(int);
982 void b(int const);
983 void c(const int);
984 void d(const int*);
985 void e(int const) {};
Manuel Klimeke44a0062012-08-26 23:55:24 +0000986functionDecl(hasAnyParameter(hasType(isConstQualified())))
Manuel Klimek1da79332012-08-20 20:54:03 +0000987 matches "void b(int const)", "void c(const int)" and
988 "void e(int const) {}". It does not match d as there
989 is no top-level const on the parameter type "const int *".
990</pre></td></tr>
991
992
993<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>
994<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type.
995
996Given
997 void a(int);
998 void b(long);
999 void c(double);
Manuel Klimeke44a0062012-08-26 23:55:24 +00001000functionDecl(hasAnyParameter(hasType(isInteger())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001001matches "a(int)", "b(long)", but not "c(double)".
1002</pre></td></tr>
1003
1004
1005<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>
1006<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached.
1007
1008Example matches A, va, fa
1009 class A {};
1010 class B; Doesn't match, as it has no body.
1011 int va;
1012 extern int vb; Doesn't match, as it doesn't define the variable.
1013 void fa() {}
1014 void fb(); Doesn't match, as it has no body.
1015
1016Usable 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;
1017</pre></td></tr>
1018
1019
1020<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>
1021<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind.
1022
1023Given
1024 int x;
1025 int s = sizeof(x) + alignof(x)
1026unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
1027 matches sizeof(x)
1028</pre></td></tr>
1029
1030
1031<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>
1032<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or
1033unary).
1034
1035Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
1036 !(a || b)
1037</pre></td></tr>
1038
1039
1040<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>
1041<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached.
1042
1043Example matches A, va, fa
1044 class A {};
1045 class B; Doesn't match, as it has no body.
1046 int va;
1047 extern int vb; Doesn't match, as it doesn't define the variable.
1048 void fa() {}
1049 void fb(); Doesn't match, as it has no body.
1050
1051Usable 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;
1052</pre></td></tr>
1053
1054
1055<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>
1056<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or
1057static member variable template instantiations.
1058
1059Given
1060 template&lt;typename T&gt; void A(T t) { }
1061 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001062functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +00001063 matches the specialization A&lt;int&gt;().
1064
1065Usable 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;
1066</pre></td></tr>
1067
1068
1069<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>
1070<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static
1071member variable template instantiations.
1072
1073Given
1074 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
1075or
1076 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001077recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +00001078 matches the template instantiation of X&lt;A&gt;.
1079
1080But given
1081 template &lt;typename T&gt; class X {}; class A {};
1082 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001083recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +00001084 does not match, as X&lt;A&gt; is an explicit template specialization.
1085
1086Usable 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;
1087</pre></td></tr>
1088
1089<!--END_NARROWING_MATCHERS -->
1090</table>
1091
1092<!-- ======================================================================= -->
1093<h2 id="traversal-matchers">AST Traversal Matchers</h2>
1094<!-- ======================================================================= -->
1095
1096<p>Traversal matchers specify the relationship to other nodes that are
1097reachable from the current node.</p>
1098
1099<p>Note that there are special traversal matchers (has, hasDescendant, forEach and
1100forEachDescendant) which work on all nodes and allow users to write more generic
1101match expressions.</p>
1102
1103<table>
1104<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
1105<!-- START_TRAVERSAL_MATCHERS -->
1106
1107<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEach0')">forEach</td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
1108<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the
1109provided matcher.
1110
Manuel Klimeke44a0062012-08-26 23:55:24 +00001111Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001112 class X {}; Matches X, because X::X is a class of name X inside X.
1113 class Y { class X {}; };
1114 class Z { class Y { class X {}; }; }; Does not match Z.
1115
1116ChildT must be an AST base type.
1117
1118As opposed to 'has', 'forEach' will cause a match for each result that
1119matches instead of only on the first one.
1120
1121Usable as: Any Matcher
1122</pre></td></tr>
1123
1124
1125<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEachDescendant0')">forEachDescendant</td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
1126<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1127provided matcher.
1128
1129Example matches X, A, B, C
Manuel Klimeke44a0062012-08-26 23:55:24 +00001130 (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001131 class X {}; Matches X, because X::X is a class of name X inside X.
1132 class A { class X {}; };
1133 class B { class C { class X {}; }; };
1134
1135DescendantT must be an AST base type.
1136
1137As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
1138each result that matches instead of only on the first one.
1139
1140Note: Recursively combined ForEachDescendant can cause many matches:
Manuel Klimeke44a0062012-08-26 23:55:24 +00001141 recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001142will match 10 times (plus injected class name matches) on:
1143 class A { class B { class C { class D { class E {}; }; }; }; };
1144
1145Usable as: Any Matcher
1146</pre></td></tr>
1147
1148
1149<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('has0')">has</td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
1150<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the
1151provided matcher.
1152
Manuel Klimeke44a0062012-08-26 23:55:24 +00001153Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001154 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 {}; }; }; Does not match Z.
1157
1158ChildT must be an AST base type.
1159
1160Usable as: Any Matcher
1161</pre></td></tr>
1162
1163
1164<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('hasDescendant0')">hasDescendant</td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
1165<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1166provided matcher.
1167
1168Example matches X, Y, Z
Manuel Klimeke44a0062012-08-26 23:55:24 +00001169 (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001170 class X {}; Matches X, because X::X is a class of name X inside X.
1171 class Y { class X {}; };
1172 class Z { class Y { class X {}; }; };
1173
1174DescendantT must be an AST base type.
1175
1176Usable as: Any Matcher
1177</pre></td></tr>
1178
1179
1180<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>
1181<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression.
1182
1183Given
1184 int i[5];
1185 void f() { i[1] = 42; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001186arraySubscriptExpression(hasBase(implicitCastExpr(
1187 hasSourceExpression(declRefExpr()))))
1188 matches i[1] with the declRefExpr() matching i
Manuel Klimek1da79332012-08-20 20:54:03 +00001189</pre></td></tr>
1190
1191
1192<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>
1193<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression.
1194
1195Given
1196 int i[5];
1197 void f() { i[1] = 42; }
1198arraySubscriptExpression(hasIndex(integerLiteral()))
1199 matches i[1] with the integerLiteral() matching 1
1200</pre></td></tr>
1201
1202
1203<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>
1204<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a
1205binary operator matches.
1206</pre></td></tr>
1207
1208
1209<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>
1210<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions.
1211
1212Example matches a (matcher = binaryOperator(hasLHS()))
1213 a || b
1214</pre></td></tr>
1215
1216
1217<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>
1218<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions.
1219
1220Example matches b (matcher = binaryOperator(hasRHS()))
1221 a || b
1222</pre></td></tr>
1223
1224
1225<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>
1226<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a type if the declaration of the type matches the given
1227matcher.
1228
1229Usable 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;
1230</pre></td></tr>
1231
1232
1233<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>
1234<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer.
1235
1236Given
1237 struct Foo {
1238 Foo() : foo_(1) { }
1239 int foo_;
1240 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001241recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001242 record matches Foo, hasAnyConstructorInitializer matches foo_(1)
1243</pre></td></tr>
1244
1245
1246<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>
1247<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer.
1248
1249Given
1250 struct Foo {
1251 Foo() : foo_(1) { }
1252 int foo_;
1253 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001254recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
Manuel Klimek1da79332012-08-20 20:54:03 +00001255 forField(hasName("foo_"))))))
1256 matches Foo
1257with forField matching foo_
1258</pre></td></tr>
1259
1260
1261<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>
1262<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer.
1263
1264Given
1265 struct Foo {
1266 Foo() : foo_(1) { }
1267 int foo_;
1268 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001269recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
Manuel Klimek1da79332012-08-20 20:54:03 +00001270 withInitializer(integerLiteral(equals(1)))))))
1271 matches Foo
1272with withInitializer matching (1)
1273</pre></td></tr>
1274
1275
1276<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>
1277<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression.
1278
Manuel Klimeke44a0062012-08-26 23:55:24 +00001279Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y"))))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001280 class Y { public: void x(); };
1281 void z() { Y y; y.x(); }",
1282
1283FIXME: Overload to allow directly matching types?
1284</pre></td></tr>
1285
1286
1287<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>
1288<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre></pre></td></tr>
1289
1290
1291<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>
1292<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration.
1293</pre></td></tr>
1294
1295
1296<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>
1297<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration
1298belongs to.
1299
1300FIXME: Generalize this for other kinds of declarations.
1301FIXME: What other kind of declarations would we need to generalize
1302this to?
1303
1304Example matches A() in the last line
Manuel Klimeke44a0062012-08-26 23:55:24 +00001305 (matcher = constructExpr(hasDeclaration(methodDecl(
Manuel Klimek1da79332012-08-20 20:54:03 +00001306 ofClass(hasName("A"))))))
1307 class A {
1308 public:
1309 A();
1310 };
1311 A a = A();
1312</pre></td></tr>
1313
1314
1315<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>
1316<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from
1317a class matching Base.
1318
1319Note that a class is considered to be also derived from itself.
1320
1321Example matches X, Y, Z, C (Base == hasName("X"))
1322 class X; A class is considered to be derived from itself
1323 class Y : public X {}; directly derived
1324 class Z : public Y {}; indirectly derived
1325 typedef X A;
1326 typedef A B;
1327 class C : public B {}; derived from a typedef of X
1328
1329In the following example, Bar matches isDerivedFrom(hasName("X")):
1330 class Foo;
1331 typedef Foo X;
1332 class Bar : public Foo {}; derived from a type that X is a typedef of
1333</pre></td></tr>
1334
1335
1336<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>
1337<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the
1338given matcher.
1339
Manuel Klimeke44a0062012-08-26 23:55:24 +00001340Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001341 class Y { public: void x(); };
1342 void z() { Y y; y.x();
1343</pre></td></tr>
1344
1345
1346<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>
1347<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call
1348expression.
1349
1350Given
1351 void x(int, int, int) { int y; x(1, y, 42); }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001352callExpr(hasAnyArgument(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001353 matches x(1, y, 42)
1354with hasAnyArgument(...)
1355 matching y
1356</pre></td></tr>
1357
1358
1359<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>
1360<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor
1361call expression.
1362
1363Example matches y in x(y)
Manuel Klimeke44a0062012-08-26 23:55:24 +00001364 (matcher = callExpr(hasArgument(0, declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001365 void x(int) { int y; x(y); }
1366</pre></td></tr>
1367
1368
1369<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>
1370<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a type if the declaration of the type matches the given
1371matcher.
1372
1373Usable 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;
1374</pre></td></tr>
1375
1376
1377<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>
1378<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression matches the given matcher.
1379
1380Example: matches "a string" (matcher =
Manuel Klimeke44a0062012-08-26 23:55:24 +00001381 hasSourceExpression(constructExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001382class URL { URL(string); };
1383URL url = "a string";
1384</pre></td></tr>
1385
1386
1387<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>
1388<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations that have at least one
1389TemplateArgument matching the given InnerMatcher.
1390
1391Given
1392 template&lt;typename T&gt; class A {};
1393 template&lt;&gt; class A&lt;double&gt; {};
1394 A&lt;int&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001395classTemplateSpecializationDecl(hasAnyTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001396 refersToType(asString("int"))))
1397 matches the specialization A&lt;int&gt;
1398</pre></td></tr>
1399
1400
1401<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>
1402<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument
1403matches the given InnerMatcher.
1404
1405Given
1406 template&lt;typename T, typename U&gt; class A {};
1407 A&lt;bool, int&gt; b;
1408 A&lt;int, bool&gt; c;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001409classTemplateSpecializationDecl(hasTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001410 1, refersToType(asString("int"))))
1411 matches the specialization A&lt;bool, int&gt;
1412</pre></td></tr>
1413
1414
1415<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>
1416<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches
1417a given matcher.
1418
1419Given
1420 { {}; 1+2; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001421hasAnySubstatement(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001422 matches '{ {}; 1+2; }'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001423with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001424 matching '{}'
1425</pre></td></tr>
1426
1427
1428<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>
1429<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop,
1430or conditional operator.
1431
1432Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1433 if (true) {}
1434</pre></td></tr>
1435
1436
1437<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>
1438<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator.
1439
1440Example matches b
1441 condition ? a : b
1442</pre></td></tr>
1443
1444
1445<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>
1446<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator.
1447
1448Example matches a
1449 condition ? a : b
1450</pre></td></tr>
1451
1452
1453<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>
1454<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a
1455specific using shadow declaration.
1456
1457FIXME: This currently only works for functions. Fix.
1458
1459Given
1460 namespace a { void f() {} }
1461 using a::f;
1462 void g() {
1463 f(); Matches this ..
1464 a::f(); .. but not this.
1465 }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001466declRefExpr(throughUsingDeclaration(anything()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001467 matches f()
1468</pre></td></tr>
1469
1470
1471<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>
1472<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the
1473specified matcher.
1474
1475Example matches x in if(x)
Manuel Klimeke44a0062012-08-26 23:55:24 +00001476 (matcher = declRefExpr(to(varDecl(hasName("x")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001477 bool x;
1478 if (x) {}
1479</pre></td></tr>
1480
1481
1482<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>
1483<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement.
1484
1485Note that this does not work for global declarations because the AST
1486breaks up multiple-declaration DeclStmt's into multiple single-declaration
1487DeclStmt's.
1488Example: Given non-global declarations
1489 int a, b = 0;
1490 int c;
1491 int d = 2, e;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001492declStmt(containsDeclaration(
1493 0, varDecl(hasInitializer(anything()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001494 matches only 'int d = 2, e;', and
Manuel Klimeke44a0062012-08-26 23:55:24 +00001495declStmt(containsDeclaration(1, varDecl()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001496 matches 'int a, b = 0' as well as 'int d = 2, e;'
1497 but 'int c;' is not matched.
1498</pre></td></tr>
1499
1500
1501<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>
1502<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration.
1503
1504Given
1505 int a, b;
1506 int c;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001507declStmt(hasSingleDecl(anything()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001508 matches 'int c;' but not 'int a, b;'.
1509</pre></td></tr>
1510
1511
1512<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>
1513<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', or 'do while' statement that has
1514a given body.
1515
1516Given
1517 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001518hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001519 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001520with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001521 matching '{}'
1522</pre></td></tr>
1523
1524
1525<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>
1526<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop,
1527or conditional operator.
1528
1529Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1530 if (true) {}
1531</pre></td></tr>
1532
1533
1534<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>
1535<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher.
1536
1537(Note: Clang's AST refers to other conversions as "casts" too, and calls
1538actual casts "explicit" casts.)
1539</pre></td></tr>
1540
1541
1542<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>
1543<tr><td colspan="4" class="doc" id="hasType3"><pre>Overloaded to match the declaration of the expression's or value
1544declaration's type.
1545
1546In case of a value declaration (for example a variable declaration),
1547this resolves one layer of indirection. For example, in the value
Manuel Klimeke44a0062012-08-26 23:55:24 +00001548declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
1549while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
Manuel Klimek1da79332012-08-20 20:54:03 +00001550of x."
1551
Manuel Klimeke44a0062012-08-26 23:55:24 +00001552Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
1553 and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001554 class X {};
1555 void y(X &amp;x) { x; X z; }
1556
1557Usable 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;
1558</pre></td></tr>
1559
1560
1561<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>
1562<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts
1563are stripped off.
1564
1565Parentheses and explicit casts are not discarded.
1566Given
1567 int arr[5];
1568 int a = 0;
1569 char b = 0;
1570 const int c = a;
1571 int *d = arr;
1572 long e = (long) 0l;
1573The matchers
Manuel Klimeke44a0062012-08-26 23:55:24 +00001574 varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
1575 varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001576would match the declarations for a, b, c, and d, but not e.
1577While
Manuel Klimeke44a0062012-08-26 23:55:24 +00001578 varDecl(hasInitializer(integerLiteral()))
1579 varDecl(hasInitializer(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001580only match the declarations for b, c, and d.
1581</pre></td></tr>
1582
1583
1584<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>
1585<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and
1586casts are stripped off.
1587
1588Implicit and non-C Style casts are also discarded.
1589Given
1590 int a = 0;
1591 char b = (0);
1592 void* c = reinterpret_cast&lt;char*&gt;(0);
1593 char d = char(0);
1594The matcher
Manuel Klimeke44a0062012-08-26 23:55:24 +00001595 varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001596would match the declarations for a, b, c, and d.
1597while
Manuel Klimeke44a0062012-08-26 23:55:24 +00001598 varDecl(hasInitializer(integerLiteral()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001599only match the declaration for a.
1600</pre></td></tr>
1601
1602
1603<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>
1604<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and
1605parentheses are stripped off.
1606
1607Explicit casts are not discarded.
1608Given
1609 int arr[5];
1610 int a = 0;
1611 char b = (0);
1612 const int c = a;
1613 int *d = (arr);
1614 long e = ((long) 0l);
1615The matchers
Manuel Klimeke44a0062012-08-26 23:55:24 +00001616 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
1617 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001618would match the declarations for a, b, c, and d, but not e.
1619while
Manuel Klimeke44a0062012-08-26 23:55:24 +00001620 varDecl(hasInitializer(integerLiteral()))
1621 varDecl(hasInitializer(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001622would only match the declaration for a.
1623</pre></td></tr>
1624
1625
1626<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>
1627<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', or 'do while' statement that has
1628a given body.
1629
1630Given
1631 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001632hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001633 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001634with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001635 matching '{}'
1636</pre></td></tr>
1637
1638
1639<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>
1640<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop,
1641or conditional operator.
1642
1643Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1644 if (true) {}
1645</pre></td></tr>
1646
1647
1648<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>
1649<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop.
1650
1651Example:
1652 forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
1653matches '++x' in
1654 for (x; x &lt; N; ++x) { }
1655</pre></td></tr>
1656
1657
1658<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>
1659<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop.
1660
1661Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +00001662 forStmt(hasLoopInit(declStmt()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001663matches 'int x = 0' in
1664 for (int x = 0; x &lt; N; ++x) { }
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('hasAnyParameter0')">hasAnyParameter</td><td>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="hasAnyParameter0"><pre>Matches any parameter of a function declaration.
1670
1671Does not match the 'this' parameter of a method.
1672
1673Given
1674 class X { void f(int x, int y, int z) {} };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001675methodDecl(hasAnyParameter(hasName("y")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001676 matches f(int x, int y, int z) {}
1677with hasAnyParameter(...)
1678 matching int y
1679</pre></td></tr>
1680
1681
1682<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>
1683<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function declaration.
1684
1685Given
1686 class X { void f(int x) {} };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001687methodDecl(hasParameter(0, hasType(varDecl())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001688 matches f(int x) {}
1689with hasParameter(...)
1690 matching int x
1691</pre></td></tr>
1692
1693
1694<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>
1695<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration.
1696
1697Given:
1698 class X { int f() { return 1; } };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001699methodDecl(returns(asString("int")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001700 matches int f() { return 1; }
1701</pre></td></tr>
1702
1703
1704<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>
1705<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop,
1706or conditional operator.
1707
1708Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1709 if (true) {}
1710</pre></td></tr>
1711
1712
1713<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>
1714<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement.
1715
1716Given
1717 if (A* a = GetAPointer()) {}
1718hasConditionVariableStatment(...)
1719 matches 'A* a = GetAPointer()'.
1720</pre></td></tr>
1721
1722
1723<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>
1724<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given
1725matcher.
1726
1727FIXME: Unit test this matcher
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('hasObjectExpression0')">hasObjectExpression</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
1732<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is
1733matched by a given matcher.
1734
1735Given
1736 struct X { int m; };
1737 void f(X x) { x.m; m; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001738memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X")))))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001739 matches "x.m" and "m"
1740with hasObjectExpression(...)
1741 matching "x" and the implicit object expression of "m" which has type X*.
1742</pre></td></tr>
1743
1744
1745<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>
1746<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a
1747given matcher.
1748
1749Given
1750 struct { int first, second; } first, second;
1751 int i(second.first);
1752 int j(first.second);
Manuel Klimeke44a0062012-08-26 23:55:24 +00001753memberExpr(member(hasName("first")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001754 matches second.first
1755 but not first.second (because the member name there is "second").
1756</pre></td></tr>
1757
1758
1759<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>
1760<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a type if the declaration of the type matches the given
1761matcher.
1762
1763Usable 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;
1764</pre></td></tr>
1765
1766
1767<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>
1768<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration.
1769</pre></td></tr>
1770
1771
1772<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>
1773<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration.
1774</pre></td></tr>
1775
1776
1777<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>
1778<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1779alignof.
1780</pre></td></tr>
1781
1782
1783<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>
1784<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1785sizeof.
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('refersToDeclaration0')">refersToDeclaration</td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
1790<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a TemplateArgument that refers to a certain declaration.
1791
1792Given
1793 template&lt;typename T&gt; struct A {};
1794 struct B { B* next; };
1795 A&lt;&amp;B::next&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001796classTemplateSpecializationDecl(hasAnyTemplateArgument(
1797 refersToDeclaration(fieldDecl(hasName("next"))))
1798 matches the specialization A&lt;&amp;B::next&gt; with fieldDecl(...) matching
Manuel Klimek1da79332012-08-20 20:54:03 +00001799 B::next
1800</pre></td></tr>
1801
1802
1803<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>
1804<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type.
1805
1806Given
1807 struct X {};
1808 template&lt;typename T&gt; struct A {};
1809 A&lt;X&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001810classTemplateSpecializationDecl(hasAnyTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001811 refersToType(class(hasName("X")))))
1812 matches the specialization A&lt;X&gt;
1813</pre></td></tr>
1814
1815
1816<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>
1817<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument.
1818
1819Given
1820 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
1821unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
1822 matches sizeof(a) and alignof(c)
1823</pre></td></tr>
1824
1825
1826<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>
1827<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches.
1828
1829Example matches true (matcher = hasOperand(boolLiteral(equals(true))))
1830 !true
1831</pre></td></tr>
1832
1833
1834<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>
1835<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration.
1836
1837Given
1838 namespace X { void b(); }
1839 using X::b;
1840usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
1841 matches using X::b </pre></td></tr>
1842
1843
1844<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>
1845<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is
1846matched by the given matcher.
1847
1848Given
1849 namespace X { int a; void b(); }
1850 using X::a;
1851 using X::b;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001852usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001853 matches using X::b but not using X::a </pre></td></tr>
1854
1855
1856<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>
1857<tr><td colspan="4" class="doc" id="hasType2"><pre>Overloaded to match the declaration of the expression's or value
1858declaration's type.
1859
1860In case of a value declaration (for example a variable declaration),
1861this resolves one layer of indirection. For example, in the value
Manuel Klimeke44a0062012-08-26 23:55:24 +00001862declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
1863while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
Manuel Klimek1da79332012-08-20 20:54:03 +00001864of x."
1865
Manuel Klimeke44a0062012-08-26 23:55:24 +00001866Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
1867 and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001868 class X {};
1869 void y(X &amp;x) { x; X z; }
1870
1871Usable 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;
1872</pre></td></tr>
1873
1874
1875<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>
1876<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression
1877that matches the given matcher.
1878
Manuel Klimeke44a0062012-08-26 23:55:24 +00001879Example matches x (matcher = varDecl(hasInitializer(callExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001880 bool y() { return true; }
1881 bool x = y();
1882</pre></td></tr>
1883
1884
1885<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>
1886<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', or 'do while' statement that has
1887a given body.
1888
1889Given
1890 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001891hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001892 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001893with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001894 matching '{}'
1895</pre></td></tr>
1896
1897
1898<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>
1899<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop,
1900or conditional operator.
1901
1902Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1903 if (true) {}
1904</pre></td></tr>
1905
1906<!--END_TRAVERSAL_MATCHERS -->
1907</table>
1908
1909</div>
1910</body>
1911</html>
1912
1913