blob: ea038e38c83d5357de19ae9956c8d2ae21389d92 [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) {
Manuel Klimek67619ff2012-09-07 13:10:32 +000023 if (!id) return;
Manuel Klimek1da79332012-08-20 20:54:03 +000024 row = document.getElementById(id);
25 if (row.style.display != 'table-cell')
26 row.style.display = 'table-cell';
27 else
28 row.style.display = 'none';
29}
30</script>
31</head>
Manuel Klimek67619ff2012-09-07 13:10:32 +000032<body onLoad="toggle(location.hash.substring(1, location.hash.length - 6))">
Manuel Klimek1da79332012-08-20 20:54:03 +000033
34<!--#include virtual="../menu.html.incl"-->
35
36<div id="content">
37
38<h1>AST Matcher Reference</h1>
39
40<p>This document shows all currently implemented matchers. The matchers are grouped
41by category and node type they match. You can click on matcher names to show the
42matcher's source documentation.</p>
43
44<p>There are three different basic categories of matchers:
45<ul>
46<li><a href="#decl-matchers">Node Matchers:</a> Matchers that match a specific type of AST node.</li>
47<li><a href="#narrowing-matchers">Narrowing Matchers:</a> Matchers that match attributes on AST nodes.</li>
48<li><a href="#traversal-matchers">Traversal Matchers:</a> Matchers that allow traversal between AST nodes.</li>
49</ul>
50</p>
51
52<p>Within each category the matchers are ordered by node type they match on.
53Note that if a matcher can match multiple node types, it will it will appear
54multiple times. This means that by searching for Matcher&lt;Stmt&gt; you can
55find all matchers that can be used to match on Stmt nodes.</p>
56
57<p>The exception to that rule are matchers that can match on any node. Those
58are marked with a * and are listed in the beginning of each category.</p>
59
60<!-- ======================================================================= -->
61<h2 id="decl-matchers">Node Matchers</h2>
62<!-- ======================================================================= -->
63
64<p>Node matchers are at the core of matcher expressions - they specify the type
65of node that is expected. Every match expression starts with a node matcher,
66which can then be further refined with a narrowing or traversal matcher. All
67traversal matchers take node matchers as their arguments.</p>
68
69<p>For convenience, all node matchers take an arbitrary number of arguments
70and implicitly act as allOf matchers.</p>
71
72<p>Node matchers are the only matchers that support the bind("id") call to
73bind the matched node to the given string, to be later retrieved from the
74match callback.</p>
75
76<table>
77<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
78<!-- START_DECL_MATCHERS -->
79
Manuel Klimek67619ff2012-09-07 13:10:32 +000080<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')"><a name="classTemplateDecl0Anchor">classTemplateDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +000081<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +000082
83Example matches Z
84 template&lt;class T&gt; class Z {};
85</pre></td></tr>
86
87
Manuel Klimek67619ff2012-09-07 13:10:32 +000088<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')"><a name="classTemplateSpecializationDecl0Anchor">classTemplateSpecializationDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +000089<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations.
Manuel Klimek1da79332012-08-20 20:54:03 +000090
91Given
92 template&lt;typename T&gt; class A {};
93 template&lt;&gt; class A&lt;double&gt; {};
94 A&lt;int&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +000095classTemplateSpecializationDecl()
Manuel Klimek1da79332012-08-20 20:54:03 +000096 matches the specializations A&lt;int&gt; and A&lt;double&gt;
97</pre></td></tr>
98
99
Manuel Klimek67619ff2012-09-07 13:10:32 +0000100<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')"><a name="constructorDecl0Anchor">constructorDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000101<tr><td colspan="4" class="doc" id="constructorDecl0"><pre>Matches C++ constructor declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000102
103Example matches Foo::Foo() and Foo::Foo(int)
104 class Foo {
105 public:
106 Foo();
107 Foo(int);
108 int DoSomething();
109 };
110</pre></td></tr>
111
112
Manuel Klimek67619ff2012-09-07 13:10:32 +0000113<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')"><a name="decl0Anchor">decl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000114<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations.
115
116Examples matches X, C, and the friend declaration inside C;
117 void X();
118 class C {
119 friend X;
120 };
121</pre></td></tr>
122
123
Manuel Klimek67619ff2012-09-07 13:10:32 +0000124<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')"><a name="destructorDecl0Anchor">destructorDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000125<tr><td colspan="4" class="doc" id="destructorDecl0"><pre>Matches explicit C++ destructor declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000126
127Example matches Foo::~Foo()
128 class Foo {
129 public:
130 virtual ~Foo();
131 };
132</pre></td></tr>
133
134
Manuel Klimek67619ff2012-09-07 13:10:32 +0000135<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')"><a name="enumConstantDecl0Anchor">enumConstantDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000136<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants.
Manuel Klimek1da79332012-08-20 20:54:03 +0000137
138Example matches A, B, C
139 enum X {
140 A, B, C
141 };
142</pre></td></tr>
143
144
Manuel Klimek67619ff2012-09-07 13:10:32 +0000145<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')"><a name="enumDecl0Anchor">enumDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000146<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations.
147
148Example matches X
149 enum X {
150 A, B, C
151 };
152</pre></td></tr>
153
154
Manuel Klimek67619ff2012-09-07 13:10:32 +0000155<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')"><a name="fieldDecl0Anchor">fieldDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000156<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000157
158Given
159 class X { int m; };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000160fieldDecl()
Manuel Klimek1da79332012-08-20 20:54:03 +0000161 matches 'm'.
162</pre></td></tr>
163
164
Manuel Klimek67619ff2012-09-07 13:10:32 +0000165<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')"><a name="functionDecl0Anchor">functionDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000166<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000167
168Example matches f
169 void f();
170</pre></td></tr>
171
172
Manuel Klimek67619ff2012-09-07 13:10:32 +0000173<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')"><a name="functionTemplateDecl0Anchor">functionTemplateDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000174<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000175
176Example matches f
177 template&lt;class T&gt; void f(T t) {}
178</pre></td></tr>
179
180
Manuel Klimek67619ff2012-09-07 13:10:32 +0000181<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')"><a name="methodDecl0Anchor">methodDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000182<tr><td colspan="4" class="doc" id="methodDecl0"><pre>Matches method declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000183
184Example matches y
185 class X { void y() };
186</pre></td></tr>
187
188
Manuel Klimek67619ff2012-09-07 13:10:32 +0000189<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')"><a name="namedDecl0Anchor">namedDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000190<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 +0000191
192Example matches X, S, the anonymous union type, i, and U;
193 typedef int X;
194 struct S {
195 union {
196 int i;
197 } U;
198 };
199</pre></td></tr>
200
201
Manuel Klimek67619ff2012-09-07 13:10:32 +0000202<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')"><a name="recordDecl0Anchor">recordDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000203<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches C++ class declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000204
205Example matches X, Z
206 class X;
207 template&lt;class T&gt; class Z {};
208</pre></td></tr>
209
210
Manuel Klimek67619ff2012-09-07 13:10:32 +0000211<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')"><a name="usingDecl0Anchor">usingDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000212<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations.
213
214Given
215 namespace X { int x; }
216 using X::x;
217usingDecl()
218 matches using X::x </pre></td></tr>
219
220
Manuel Klimek67619ff2012-09-07 13:10:32 +0000221<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')"><a name="varDecl0Anchor">varDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000222<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000223
224Note: this does not match declarations of member variables, which are
225"field" declarations in Clang parlance.
226
227Example matches a
228 int a;
229</pre></td></tr>
230
231
Manuel Klimek67619ff2012-09-07 13:10:32 +0000232<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')"><a name="boolLiteral0Anchor">boolLiteral</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000233<tr><td colspan="4" class="doc" id="boolLiteral0"><pre>Matches bool literals.
234
235Example matches true
236 true
237</pre></td></tr>
238
239
Manuel Klimek67619ff2012-09-07 13:10:32 +0000240<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')"><a name="castExpr0Anchor">castExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000241<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST.
242
243Example: castExpr() matches each of the following:
244 (int) 3;
245 const_cast&lt;Expr *&gt;(SubExpr);
246 char c = 0;
247but does not match
248 int i = (0);
249 int k = 0;
250</pre></td></tr>
251
252
Manuel Klimek67619ff2012-09-07 13:10:32 +0000253<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')"><a name="characterLiteral0Anchor">characterLiteral</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000254<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t).
255
256Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
257though.
258
259Example matches 'a', L'a'
260 char ch = 'a'; wchar_t chw = L'a';
261</pre></td></tr>
262
263
Manuel Klimek67619ff2012-09-07 13:10:32 +0000264<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')"><a name="constCastExpr0Anchor">constCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000265<tr><td colspan="4" class="doc" id="constCastExpr0"><pre>Matches a const_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000266
267Example: Matches const_cast&lt;int*&gt;(&amp;r) in
268 int n = 42;
269 const int &amp;r(n);
270 int* p = const_cast&lt;int*&gt;(&amp;r);
271</pre></td></tr>
272
273
Manuel Klimek67619ff2012-09-07 13:10:32 +0000274<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')"><a name="dynamicCastExpr0Anchor">dynamicCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000275<tr><td colspan="4" class="doc" id="dynamicCastExpr0"><pre>Matches a dynamic_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000276
277Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +0000278 dynamicCastExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000279matches
280 dynamic_cast&lt;D*&gt;(&amp;b);
281in
282 struct B { virtual ~B() {} }; struct D : B {};
283 B b;
284 D* p = dynamic_cast&lt;D*&gt;(&amp;b);
285</pre></td></tr>
286
287
Manuel Klimek67619ff2012-09-07 13:10:32 +0000288<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')"><a name="explicitCastExpr0Anchor">explicitCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000289<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000290
291Matches any cast expression written in user code, whether it be a
292C-style cast, a functional-style cast, or a keyword cast.
293
294Does not match implicit conversions.
295
296Note: the name "explicitCast" is chosen to match Clang's terminology, as
297Clang uses the term "cast" to apply to implicit conversions as well as to
298actual cast expressions.
299
300hasDestinationType.
301
302Example: matches all five of the casts in
303 int((int)(reinterpret_cast&lt;int&gt;(static_cast&lt;int&gt;(const_cast&lt;int&gt;(42)))))
304but does not match the implicit conversion in
305 long ell = 42;
306</pre></td></tr>
307
308
Manuel Klimek67619ff2012-09-07 13:10:32 +0000309<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')"><a name="functionalCastExpr0Anchor">functionalCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000310<tr><td colspan="4" class="doc" id="functionalCastExpr0"><pre>Matches functional cast expressions
Manuel Klimek1da79332012-08-20 20:54:03 +0000311
312Example: Matches Foo(bar);
313 Foo f = bar;
314 Foo g = (Foo) bar;
315 Foo h = Foo(bar);
316</pre></td></tr>
317
318
Manuel Klimek67619ff2012-09-07 13:10:32 +0000319<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')"><a name="implicitCastExpr0Anchor">implicitCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000320<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 +0000321
322This matches many different places, including function call return value
323eliding, as well as any type conversions.
324</pre></td></tr>
325
326
Manuel Klimek67619ff2012-09-07 13:10:32 +0000327<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')"><a name="integerLiteral0Anchor">integerLiteral</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000328<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings.
329
330Not matching character-encoded integers such as L'a'.
331
332Example matches 1, 1L, 0x1, 1U
333</pre></td></tr>
334
335
Manuel Klimek67619ff2012-09-07 13:10:32 +0000336<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')"><a name="reinterpretCastExpr0Anchor">reinterpretCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000337<tr><td colspan="4" class="doc" id="reinterpretCastExpr0"><pre>Matches a reinterpret_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000338
339Either the source expression or the destination type can be matched
340using has(), but hasDestinationType() is more specific and can be
341more readable.
342
343Example matches reinterpret_cast&lt;char*&gt;(&amp;p) in
344 void* p = reinterpret_cast&lt;char*&gt;(&amp;p);
345</pre></td></tr>
346
347
Manuel Klimek67619ff2012-09-07 13:10:32 +0000348<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')"><a name="staticCastExpr0Anchor">staticCastExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000349<tr><td colspan="4" class="doc" id="staticCastExpr0"><pre>Matches a C++ static_cast expression.
Manuel Klimek1da79332012-08-20 20:54:03 +0000350
351hasDestinationType
352reinterpretCast
353
354Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +0000355 staticCastExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000356matches
357 static_cast&lt;long&gt;(8)
358in
359 long eight(static_cast&lt;long&gt;(8));
360</pre></td></tr>
361
362
Manuel Klimek67619ff2012-09-07 13:10:32 +0000363<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')"><a name="stringLiteral0Anchor">stringLiteral</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000364<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals).
365
366Example matches "abcd", L"abcd"
367 char *s = "abcd"; wchar_t *ws = L"abcd"
368</pre></td></tr>
369
370
Manuel Klimek67619ff2012-09-07 13:10:32 +0000371<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')"><a name="arraySubscriptExpr0Anchor">arraySubscriptExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000372<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions.
373
374Given
375 int i = a[1];
376arraySubscriptExpr()
377 matches "a[1]"
378</pre></td></tr>
379
380
Manuel Klimek67619ff2012-09-07 13:10:32 +0000381<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')"><a name="binaryOperator0Anchor">binaryOperator</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000382<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions.
383
384Example matches a || b
385 !(a || b)
386</pre></td></tr>
387
388
Manuel Klimek67619ff2012-09-07 13:10:32 +0000389<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')"><a name="bindTemporaryExpr0Anchor">bindTemporaryExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000390<tr><td colspan="4" class="doc" id="bindTemporaryExpr0"><pre>Matches nodes where temporaries are created.
Manuel Klimek1da79332012-08-20 20:54:03 +0000391
392Example matches FunctionTakesString(GetStringByValue())
Manuel Klimeke44a0062012-08-26 23:55:24 +0000393 (matcher = bindTemporaryExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000394 FunctionTakesString(GetStringByValue());
395 FunctionTakesStringByPointer(GetStringPointer());
396</pre></td></tr>
397
398
Manuel Klimek67619ff2012-09-07 13:10:32 +0000399<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')"><a name="callExpr0Anchor">callExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000400<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000401
402Example matches x.y() and y()
403 X x;
404 x.y();
405 y();
406</pre></td></tr>
407
408
Manuel Klimek67619ff2012-09-07 13:10:32 +0000409<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')"><a name="compoundStmt0Anchor">compoundStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000410<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000411
412Example matches '{}' and '{{}}'in 'for (;;) {{}}'
413 for (;;) {{}}
414</pre></td></tr>
415
416
Manuel Klimek67619ff2012-09-07 13:10:32 +0000417<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')"><a name="conditionalOperator0Anchor">conditionalOperator</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000418<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions.
419
420Example matches a ? b : c
421 (a ? b : c) + 42
422</pre></td></tr>
423
424
Manuel Klimek67619ff2012-09-07 13:10:32 +0000425<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')"><a name="constructExpr0Anchor">constructExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000426<tr><td colspan="4" class="doc" id="constructExpr0"><pre>Matches constructor call expressions (including implicit ones).
Manuel Klimek1da79332012-08-20 20:54:03 +0000427
428Example matches string(ptr, n) and ptr within arguments of f
Manuel Klimeke44a0062012-08-26 23:55:24 +0000429 (matcher = constructExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000430 void f(const string &amp;a, const string &amp;b);
431 char *ptr;
432 int n;
433 f(string(ptr, n), ptr);
434</pre></td></tr>
435
436
Manuel Klimek67619ff2012-09-07 13:10:32 +0000437<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')"><a name="declRefExpr0Anchor">declRefExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000438<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations.
Manuel Klimek1da79332012-08-20 20:54:03 +0000439
440Example matches x in if (x)
441 bool x;
442 if (x) {}
443</pre></td></tr>
444
445
Manuel Klimek67619ff2012-09-07 13:10:32 +0000446<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')"><a name="declStmt0Anchor">declStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000447<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000448
449Given
450 int a;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000451declStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +0000452 matches 'int a'.
453</pre></td></tr>
454
455
Manuel Klimek67619ff2012-09-07 13:10:32 +0000456<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')"><a name="defaultArgExpr0Anchor">defaultArgExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000457<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 +0000458
459Example matches the CXXDefaultArgExpr placeholder inserted for the
460 default value of the second parameter in the call expression f(42)
Manuel Klimeke44a0062012-08-26 23:55:24 +0000461 (matcher = defaultArgExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000462 void f(int x, int y = 0);
463 f(42);
464</pre></td></tr>
465
466
Manuel Klimek67619ff2012-09-07 13:10:32 +0000467<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')"><a name="deleteExpr0Anchor">deleteExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000468<tr><td colspan="4" class="doc" id="deleteExpr0"><pre>Matches delete expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000469
470Given
471 delete X;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000472deleteExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000473 matches 'delete X'.
474</pre></td></tr>
475
476
Manuel Klimek67619ff2012-09-07 13:10:32 +0000477<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')"><a name="doStmt0Anchor">doStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000478<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements.
479
480Given
481 do {} while (true);
482doStmt()
483 matches 'do {} while(true)'
484</pre></td></tr>
485
486
Manuel Klimek67619ff2012-09-07 13:10:32 +0000487<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')"><a name="expr0Anchor">expr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000488<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000489
490Example matches x()
491 void f() { x(); }
492</pre></td></tr>
493
494
Manuel Klimek67619ff2012-09-07 13:10:32 +0000495<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')"><a name="forStmt0Anchor">forStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000496<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements.
497
498Example matches 'for (;;) {}'
499 for (;;) {}
500</pre></td></tr>
501
502
Manuel Klimek67619ff2012-09-07 13:10:32 +0000503<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')"><a name="ifStmt0Anchor">ifStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000504<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements.
505
506Example matches 'if (x) {}'
507 if (x) {}
508</pre></td></tr>
509
510
Manuel Klimek67619ff2012-09-07 13:10:32 +0000511<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')"><a name="initListExpr0Anchor">initListExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000512<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions.
513
514Given
515 int a[] = { 1, 2 };
516 struct B { int x, y; };
517 B b = { 5, 6 };
518initList()
519 matches "{ 1, 2 }" and "{ 5, 6 }"
520</pre></td></tr>
521
522
Manuel Klimek67619ff2012-09-07 13:10:32 +0000523<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')"><a name="materializeTemporaryExpr0Anchor">materializeTemporaryExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000524<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized.
525
526Example: Given
527 struct T {void func()};
528 T f();
529 void g(T);
530materializeTemporaryExpr() matches 'f()' in these statements
531 T u(f());
532 g(f());
533but does not match
534 f();
535 f().func();
536</pre></td></tr>
537
538
Manuel Klimek67619ff2012-09-07 13:10:32 +0000539<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')"><a name="memberCallExpr0Anchor">memberCallExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000540<tr><td colspan="4" class="doc" id="memberCallExpr0"><pre>Matches member call expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000541
542Example matches x.y()
543 X x;
544 x.y();
545</pre></td></tr>
546
547
Manuel Klimek67619ff2012-09-07 13:10:32 +0000548<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')"><a name="memberExpr0Anchor">memberExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000549<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000550
551Given
552 class Y {
553 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
554 int a; static int b;
555 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000556memberExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000557 matches this-&gt;x, x, y.x, a, this-&gt;b
558</pre></td></tr>
559
560
Manuel Klimek67619ff2012-09-07 13:10:32 +0000561<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')"><a name="newExpr0Anchor">newExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000562<tr><td colspan="4" class="doc" id="newExpr0"><pre>Matches new expressions.
Manuel Klimek1da79332012-08-20 20:54:03 +0000563
564Given
565 new X;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000566newExpr()
Manuel Klimek1da79332012-08-20 20:54:03 +0000567 matches 'new X'.
568</pre></td></tr>
569
570
Manuel Klimek67619ff2012-09-07 13:10:32 +0000571<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')"><a name="operatorCallExpr0Anchor">operatorCallExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000572<tr><td colspan="4" class="doc" id="operatorCallExpr0"><pre>Matches overloaded operator calls.
Manuel Klimek1da79332012-08-20 20:54:03 +0000573
574Note that if an operator isn't overloaded, it won't match. Instead, use
575binaryOperator matcher.
576Currently it does not match operators such as new delete.
577FIXME: figure out why these do not match?
578
579Example matches both operator&lt;&lt;((o &lt;&lt; b), c) and operator&lt;&lt;(o, b)
Manuel Klimeke44a0062012-08-26 23:55:24 +0000580 (matcher = operatorCallExpr())
Manuel Klimek1da79332012-08-20 20:54:03 +0000581 ostream &amp;operator&lt;&lt; (ostream &amp;out, int i) { };
582 ostream &amp;o; int b = 1, c = 1;
583 o &lt;&lt; b &lt;&lt; c;
584</pre></td></tr>
585
586
Manuel Klimek67619ff2012-09-07 13:10:32 +0000587<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')"><a name="stmt0Anchor">stmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;...</td></tr>
Manuel Klimeke44a0062012-08-26 23:55:24 +0000588<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements.
Manuel Klimek1da79332012-08-20 20:54:03 +0000589
590Given
591 { ++a; }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000592stmt()
Manuel Klimek1da79332012-08-20 20:54:03 +0000593 matches both the compound statement '{ ++a; }' and '++a'.
594</pre></td></tr>
595
596
Manuel Klimek67619ff2012-09-07 13:10:32 +0000597<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')"><a name="switchCase0Anchor">switchCase</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000598<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements.
599
600Given
601 switch(a) { case 42: break; default: break; }
602switchCase()
603 matches 'case 42: break;' and 'default: break;'.
604</pre></td></tr>
605
606
Manuel Klimek67619ff2012-09-07 13:10:32 +0000607<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')"><a name="unaryExprOrTypeTraitExpr0Anchor">unaryExprOrTypeTraitExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000608<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
609
610Given
611 Foo x = bar;
612 int y = sizeof(x) + alignof(x);
613unaryExprOrTypeTraitExpr()
614 matches sizeof(x) and alignof(x)
615</pre></td></tr>
616
617
Manuel Klimek67619ff2012-09-07 13:10:32 +0000618<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')"><a name="unaryOperator0Anchor">unaryOperator</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000619<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions.
620
621Example matches !a
622 !a || b
623</pre></td></tr>
624
625
Manuel Klimek67619ff2012-09-07 13:10:32 +0000626<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')"><a name="whileStmt0Anchor">whileStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>&gt;...</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000627<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements.
628
629Given
630 while (true) {}
631whileStmt()
632 matches 'while (true) {}'.
633</pre></td></tr>
634
635<!--END_DECL_MATCHERS -->
636</table>
637
638<!-- ======================================================================= -->
639<h2 id="narrowing-matchers">Narrowing Matchers</h2>
640<!-- ======================================================================= -->
641
642<p>Narrowing matchers match certain attributes on the current node, thus
643narrowing down the set of nodes of the current type to match on.</p>
644
645<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless)
646which allow users to create more powerful match expressions.</p>
647
648<table>
649<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
650<!-- START_NARROWING_MATCHERS -->
651
Manuel Klimek67619ff2012-09-07 13:10:32 +0000652<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher&lt;*&gt; P1, Matcher&lt;*&gt; P2</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000653<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match.
654
655Usable as: Any Matcher
656</pre></td></tr>
657
658
Manuel Klimek67619ff2012-09-07 13:10:32 +0000659<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher&lt;*&gt; P1, Matcher&lt;*&gt; P2</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000660<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches.
661
662Usable as: Any Matcher
663</pre></td></tr>
664
665
Manuel Klimek67619ff2012-09-07 13:10:32 +0000666<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000667<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node.
668
669Useful when another matcher requires a child matcher, but there's no
670additional constraint. This will often be used with an explicit conversion
671to an internal::Matcher&lt;&gt; type such as TypeMatcher.
672
673Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
674"int* p" and "void f()" in
675 int* p;
676 void f();
677
678Usable as: Any Matcher
679</pre></td></tr>
680
681
Manuel Klimek67619ff2012-09-07 13:10:32 +0000682<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher&lt;*&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000683<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match.
684
Manuel Klimeke44a0062012-08-26 23:55:24 +0000685Example matches Y (matcher = recordDecl(unless(hasName("X"))))
Manuel Klimek1da79332012-08-20 20:54:03 +0000686 class X {};
687 class Y {};
688
689Usable as: Any Matcher
690</pre></td></tr>
691
692
Manuel Klimek67619ff2012-09-07 13:10:32 +0000693<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')"><a name="hasOperatorName0Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000694<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or
695unary).
696
697Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
698 !(a || b)
699</pre></td></tr>
700
701
Manuel Klimek67619ff2012-09-07 13:10:32 +0000702<tr><td>Matcher&lt;CXXBoolLiteral&gt;</td><td class="name" onclick="toggle('equals2')"><a name="equals2Anchor">equals</a></td><td>ValueT Value</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000703<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value.
704
705Example matches true (matcher = boolLiteral(equals(true)))
706 true
707
708Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
709 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;
710</pre></td></tr>
711
712
Manuel Klimek67619ff2012-09-07 13:10:32 +0000713<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')"><a name="isImplicit0Anchor">isImplicit</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000714<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a constructor declaration that has been implicitly added
715by the compiler (eg. implicit defaultcopy constructors).
716</pre></td></tr>
717
718
Manuel Klimek67619ff2012-09-07 13:10:32 +0000719<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')"><a name="isWritten0Anchor">isWritten</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000720<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a contructor initializer if it is explicitly written in
721code (as opposed to implicitly added by the compiler).
722
723Given
724 struct Foo {
725 Foo() { }
726 Foo(int) : foo_("A") { }
727 string foo_;
728 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000729constructorDecl(hasAnyConstructorInitializer(isWritten()))
Manuel Klimek1da79332012-08-20 20:54:03 +0000730 will match Foo(int), but not Foo()
731</pre></td></tr>
732
733
Manuel Klimek67619ff2012-09-07 13:10:32 +0000734<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')"><a name="hasOverloadedOperatorName0Anchor">hasOverloadedOperatorName</a></td><td>std::string Name</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000735<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names.
736
737Matches overloaded operator names specified in strings without the
738"operator" prefix, such as "&lt;&lt;", for OverloadedOperatorCall's.
739
740Example matches a &lt;&lt; b
Manuel Klimeke44a0062012-08-26 23:55:24 +0000741 (matcher == operatorCallExpr(hasOverloadedOperatorName("&lt;&lt;")))
Manuel Klimek1da79332012-08-20 20:54:03 +0000742 a &lt;&lt; b;
743 c &amp;&amp; d; assuming both operator&lt;&lt;
744 and operator&amp;&amp; are overloaded somewhere.
745</pre></td></tr>
746
747
Manuel Klimek67619ff2012-09-07 13:10:32 +0000748<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isA1')"><a name="isA1Anchor">isA</a></td><td>StringRef BaseName</td></tr>
749<tr><td colspan="4" class="doc" id="isA1"><pre>Overloaded method as shortcut for isA(hasName(...)).
750</pre></td></tr>
751
752
753<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')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>StringRef BaseName</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000754<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).
755</pre></td></tr>
756
757
Manuel Klimek67619ff2012-09-07 13:10:32 +0000758<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')"><a name="isExplicitTemplateSpecialization0Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000759<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or
760static member variable template instantiations.
761
762Given
763 template&lt;typename T&gt; void A(T t) { }
764 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000765functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +0000766 matches the specialization A&lt;int&gt;().
767
768Usable 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;
769</pre></td></tr>
770
771
Manuel Klimek67619ff2012-09-07 13:10:32 +0000772<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')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000773<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static
774member variable template instantiations.
775
776Given
777 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
778or
779 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000780recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000781 matches the template instantiation of X&lt;A&gt;.
782
783But given
784 template &lt;typename T&gt; class X {}; class A {};
785 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000786recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000787 does not match, as X&lt;A&gt; is an explicit template specialization.
788
789Usable 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;
790</pre></td></tr>
791
792
Manuel Klimek67619ff2012-09-07 13:10:32 +0000793<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')"><a name="argumentCountIs0Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000794<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has
795a specific number of arguments (including absent default arguments).
796
Manuel Klimeke44a0062012-08-26 23:55:24 +0000797Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
Manuel Klimek1da79332012-08-20 20:54:03 +0000798 void f(int x, int y);
799 f(0, 0);
800</pre></td></tr>
801
802
Manuel Klimek67619ff2012-09-07 13:10:32 +0000803<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')"><a name="equals3Anchor">equals</a></td><td>ValueT Value</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000804<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value.
805
806Example matches true (matcher = boolLiteral(equals(true)))
807 true
808
809Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
810 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;
811</pre></td></tr>
812
813
Manuel Klimek67619ff2012-09-07 13:10:32 +0000814<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')"><a name="statementCountIs0Anchor">statementCountIs</a></td><td>unsigned N</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000815<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of
816child statements.
817
818Example: Given
819 { for (;;) {} }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000820compoundStmt(statementCountIs(0)))
Manuel Klimek1da79332012-08-20 20:54:03 +0000821 matches '{}'
822 but does not match the outer compound statement.
823</pre></td></tr>
824
825
Manuel Klimek67619ff2012-09-07 13:10:32 +0000826<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')"><a name="declCountIs0Anchor">declCountIs</a></td><td>unsigned N</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000827<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of
828declarations.
829
830Example: Given
831 int a, b;
832 int c;
833 int d = 2, e;
834declCountIs(2)
835 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
836</pre></td></tr>
837
838
Manuel Klimek67619ff2012-09-07 13:10:32 +0000839<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')"><a name="equals1Anchor">equals</a></td><td>ValueT Value</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000840<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value.
841
842Example matches true (matcher = boolLiteral(equals(true)))
843 true
844
845Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
846 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;
847</pre></td></tr>
848
849
Manuel Klimek67619ff2012-09-07 13:10:32 +0000850<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')"><a name="isDefinition0Anchor">isDefinition</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000851<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached.
852
853Example matches A, va, fa
854 class A {};
855 class B; Doesn't match, as it has no body.
856 int va;
857 extern int vb; Doesn't match, as it doesn't define the variable.
858 void fa() {}
859 void fb(); Doesn't match, as it has no body.
860
861Usable 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;
862</pre></td></tr>
863
864
Manuel Klimek67619ff2012-09-07 13:10:32 +0000865<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')"><a name="isExplicitTemplateSpecialization2Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000866<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or
867static member variable template instantiations.
868
869Given
870 template&lt;typename T&gt; void A(T t) { }
871 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000872functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +0000873 matches the specialization A&lt;int&gt;().
874
875Usable 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;
876</pre></td></tr>
877
878
Manuel Klimek67619ff2012-09-07 13:10:32 +0000879<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')"><a name="isExternC0Anchor">isExternC</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000880<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function declarations.
881
882Given:
883 extern "C" void f() {}
884 extern "C" { void g() {} }
885 void h() {}
Manuel Klimeke44a0062012-08-26 23:55:24 +0000886functionDecl(isExternC())
Manuel Klimek1da79332012-08-20 20:54:03 +0000887 matches the declaration of f and g, but not the declaration h
888</pre></td></tr>
889
890
Manuel Klimek67619ff2012-09-07 13:10:32 +0000891<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')"><a name="isTemplateInstantiation2Anchor">isTemplateInstantiation</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000892<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static
893member variable template instantiations.
894
895Given
896 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
897or
898 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000899recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000900 matches the template instantiation of X&lt;A&gt;.
901
902But given
903 template &lt;typename T&gt; class X {}; class A {};
904 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +0000905recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +0000906 does not match, as X&lt;A&gt; is an explicit template specialization.
907
908Usable 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;
909</pre></td></tr>
910
911
Manuel Klimek67619ff2012-09-07 13:10:32 +0000912<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')"><a name="equals0Anchor">equals</a></td><td>ValueT Value</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000913<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value.
914
915Example matches true (matcher = boolLiteral(equals(true)))
916 true
917
918Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>&gt;, Matcher&lt;CXXBoolLiteral&gt;,
919 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;
920</pre></td></tr>
921
922
Manuel Klimek67619ff2012-09-07 13:10:32 +0000923<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')"><a name="isArrow0Anchor">isArrow</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000924<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '-&gt;' as opposed
925to '.'.
926
927Member calls on the implicit this pointer match as called with '-&gt;'.
928
929Given
930 class Y {
931 void x() { this-&gt;x(); x(); Y y; y.x(); a; this-&gt;b; Y::b; }
932 int a;
933 static int b;
934 };
Manuel Klimeke44a0062012-08-26 23:55:24 +0000935memberExpr(isArrow())
Manuel Klimek1da79332012-08-20 20:54:03 +0000936 matches this-&gt;x, x, y.x, a, this-&gt;b
937</pre></td></tr>
938
939
Manuel Klimek67619ff2012-09-07 13:10:32 +0000940<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')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000941<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name.
942
943Supports specifying enclosing namespaces or classes by prefixing the name
944with '&lt;enclosing&gt;::'.
945Does not match typedefs of an underlying type with the given name.
946
947Example matches X (Name == "X")
948 class X;
949
950Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
951 namespace a { namespace b { class X; } }
952</pre></td></tr>
953
954
Manuel Klimek67619ff2012-09-07 13:10:32 +0000955<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')"><a name="matchesName0Anchor">matchesName</a></td><td>std::string RegExp</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000956<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose full names partially match the
957given RegExp.
958
959Supports specifying enclosing namespaces or classes by
960prefixing the name with '&lt;enclosing&gt;::'. Does not match typedefs
961of an underlying type with the given name.
962
963Example matches X (regexp == "::X")
964 class X;
965
966Example matches X (regexp is one of "::X", "^foo::.*X", among others)
967 namespace foo { namespace bar { class X; } }
968</pre></td></tr>
969
970
Manuel Klimek67619ff2012-09-07 13:10:32 +0000971<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')"><a name="asString0Anchor">asString</a></td><td>std::string Name</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000972<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string.
973
974Given
975 class Y { public: void x(); };
976 void z() { Y* y; y-&gt;x(); }
Manuel Klimeke44a0062012-08-26 23:55:24 +0000977callExpr(on(hasType(asString("class Y *"))))
Manuel Klimek1da79332012-08-20 20:54:03 +0000978 matches y-&gt;x()
979</pre></td></tr>
980
981
Manuel Klimek67619ff2012-09-07 13:10:32 +0000982<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')"><a name="isConstQualified0Anchor">isConstQualified</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +0000983<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that
984include "top-level" const.
985
986Given
987 void a(int);
988 void b(int const);
989 void c(const int);
990 void d(const int*);
991 void e(int const) {};
Manuel Klimeke44a0062012-08-26 23:55:24 +0000992functionDecl(hasAnyParameter(hasType(isConstQualified())))
Manuel Klimek1da79332012-08-20 20:54:03 +0000993 matches "void b(int const)", "void c(const int)" and
994 "void e(int const) {}". It does not match d as there
995 is no top-level const on the parameter type "const int *".
996</pre></td></tr>
997
998
Manuel Klimek67619ff2012-09-07 13:10:32 +0000999<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')"><a name="isInteger0Anchor">isInteger</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001000<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type.
1001
1002Given
1003 void a(int);
1004 void b(long);
1005 void c(double);
Manuel Klimeke44a0062012-08-26 23:55:24 +00001006functionDecl(hasAnyParameter(hasType(isInteger())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001007matches "a(int)", "b(long)", but not "c(double)".
1008</pre></td></tr>
1009
1010
Manuel Klimek67619ff2012-09-07 13:10:32 +00001011<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')"><a name="isDefinition2Anchor">isDefinition</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001012<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached.
1013
1014Example matches A, va, fa
1015 class A {};
1016 class B; Doesn't match, as it has no body.
1017 int va;
1018 extern int vb; Doesn't match, as it doesn't define the variable.
1019 void fa() {}
1020 void fb(); Doesn't match, as it has no body.
1021
1022Usable 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;
1023</pre></td></tr>
1024
1025
Manuel Klimek67619ff2012-09-07 13:10:32 +00001026<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')"><a name="ofKind0Anchor">ofKind</a></td><td>UnaryExprOrTypeTrait Kind</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001027<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind.
1028
1029Given
1030 int x;
1031 int s = sizeof(x) + alignof(x)
1032unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
1033 matches sizeof(x)
1034</pre></td></tr>
1035
1036
Manuel Klimek67619ff2012-09-07 13:10:32 +00001037<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')"><a name="hasOperatorName1Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001038<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or
1039unary).
1040
1041Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
1042 !(a || b)
1043</pre></td></tr>
1044
1045
Manuel Klimek67619ff2012-09-07 13:10:32 +00001046<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')"><a name="isDefinition1Anchor">isDefinition</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001047<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached.
1048
1049Example matches A, va, fa
1050 class A {};
1051 class B; Doesn't match, as it has no body.
1052 int va;
1053 extern int vb; Doesn't match, as it doesn't define the variable.
1054 void fa() {}
1055 void fb(); Doesn't match, as it has no body.
1056
1057Usable 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;
1058</pre></td></tr>
1059
1060
Manuel Klimek67619ff2012-09-07 13:10:32 +00001061<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')"><a name="isExplicitTemplateSpecialization1Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001062<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or
1063static member variable template instantiations.
1064
1065Given
1066 template&lt;typename T&gt; void A(T t) { }
1067 template&lt;&gt; void A(int N) { }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001068functionDecl(isExplicitTemplateSpecialization())
Manuel Klimek1da79332012-08-20 20:54:03 +00001069 matches the specialization A&lt;int&gt;().
1070
1071Usable 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;
1072</pre></td></tr>
1073
1074
Manuel Klimek67619ff2012-09-07 13:10:32 +00001075<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')"><a name="isTemplateInstantiation1Anchor">isTemplateInstantiation</a></td><td></td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001076<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static
1077member variable template instantiations.
1078
1079Given
1080 template &lt;typename T&gt; class X {}; class A {}; X&lt;A&gt; x;
1081or
1082 template &lt;typename T&gt; class X {}; class A {}; template class X&lt;A&gt;;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001083recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +00001084 matches the template instantiation of X&lt;A&gt;.
1085
1086But given
1087 template &lt;typename T&gt; class X {}; class A {};
1088 template &lt;&gt; class X&lt;A&gt; {}; X&lt;A&gt; x;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001089recordDecl(hasName("::X"), isTemplateInstantiation())
Manuel Klimek1da79332012-08-20 20:54:03 +00001090 does not match, as X&lt;A&gt; is an explicit template specialization.
1091
1092Usable 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;
1093</pre></td></tr>
1094
1095<!--END_NARROWING_MATCHERS -->
1096</table>
1097
1098<!-- ======================================================================= -->
1099<h2 id="traversal-matchers">AST Traversal Matchers</h2>
1100<!-- ======================================================================= -->
1101
1102<p>Traversal matchers specify the relationship to other nodes that are
1103reachable from the current node.</p>
1104
1105<p>Note that there are special traversal matchers (has, hasDescendant, forEach and
1106forEachDescendant) which work on all nodes and allow users to write more generic
1107match expressions.</p>
1108
1109<table>
1110<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
1111<!-- START_TRAVERSAL_MATCHERS -->
1112
Manuel Klimek67619ff2012-09-07 13:10:32 +00001113<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001114<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the
1115provided matcher.
1116
Manuel Klimeke44a0062012-08-26 23:55:24 +00001117Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001118 class X {}; Matches X, because X::X is a class of name X inside X.
1119 class Y { class X {}; };
1120 class Z { class Y { class X {}; }; }; Does not match Z.
1121
1122ChildT must be an AST base type.
1123
1124As opposed to 'has', 'forEach' will cause a match for each result that
1125matches instead of only on the first one.
1126
1127Usable as: Any Matcher
1128</pre></td></tr>
1129
1130
Manuel Klimek67619ff2012-09-07 13:10:32 +00001131<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001132<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1133provided matcher.
1134
1135Example matches X, A, B, C
Manuel Klimeke44a0062012-08-26 23:55:24 +00001136 (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001137 class X {}; Matches X, because X::X is a class of name X inside X.
1138 class A { class X {}; };
1139 class B { class C { class X {}; }; };
1140
1141DescendantT must be an AST base type.
1142
1143As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
1144each result that matches instead of only on the first one.
1145
1146Note: Recursively combined ForEachDescendant can cause many matches:
Manuel Klimeke44a0062012-08-26 23:55:24 +00001147 recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001148will match 10 times (plus injected class name matches) on:
1149 class A { class B { class C { class D { class E {}; }; }; }; };
1150
1151Usable as: Any Matcher
1152</pre></td></tr>
1153
1154
Manuel Klimek67619ff2012-09-07 13:10:32 +00001155<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher&lt;ChildT&gt; ChildMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001156<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the
1157provided matcher.
1158
Manuel Klimeke44a0062012-08-26 23:55:24 +00001159Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001160 class X {}; Matches X, because X::X is a class of name X inside X.
1161 class Y { class X {}; };
1162 class Z { class Y { class X {}; }; }; Does not match Z.
1163
1164ChildT must be an AST base type.
1165
1166Usable as: Any Matcher
1167</pre></td></tr>
1168
1169
Manuel Klimek67619ff2012-09-07 13:10:32 +00001170<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher&lt;AncestorT&gt; AncestorMatcher</td></tr>
1171<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided
1172matcher.
1173
1174Given
1175void f() { if (true) { int x = 42; } }
1176void g() { for (;;) { int x = 43; } }
1177expr(integerLiteral(hasAncsestor(ifStmt()))) matches 42, but not 43.
1178
1179Usable as: Any Matcher
1180</pre></td></tr>
1181
1182
1183<tr><td>Matcher&lt;*&gt;</td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher&lt;DescendantT&gt; DescendantMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001184<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
1185provided matcher.
1186
1187Example matches X, Y, Z
Manuel Klimeke44a0062012-08-26 23:55:24 +00001188 (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001189 class X {}; Matches X, because X::X is a class of name X inside X.
1190 class Y { class X {}; };
1191 class Z { class Y { class X {}; }; };
1192
1193DescendantT must be an AST base type.
1194
1195Usable as: Any Matcher
1196</pre></td></tr>
1197
1198
Manuel Klimek67619ff2012-09-07 13:10:32 +00001199<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')"><a name="hasBase0Anchor">hasBase</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001200<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression.
1201
1202Given
1203 int i[5];
1204 void f() { i[1] = 42; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001205arraySubscriptExpression(hasBase(implicitCastExpr(
1206 hasSourceExpression(declRefExpr()))))
1207 matches i[1] with the declRefExpr() matching i
Manuel Klimek1da79332012-08-20 20:54:03 +00001208</pre></td></tr>
1209
1210
Manuel Klimek67619ff2012-09-07 13:10:32 +00001211<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')"><a name="hasIndex0Anchor">hasIndex</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001212<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression.
1213
1214Given
1215 int i[5];
1216 void f() { i[1] = 42; }
1217arraySubscriptExpression(hasIndex(integerLiteral()))
1218 matches i[1] with the integerLiteral() matching 1
1219</pre></td></tr>
1220
1221
Manuel Klimek67619ff2012-09-07 13:10:32 +00001222<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')"><a name="hasEitherOperand0Anchor">hasEitherOperand</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001223<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a
1224binary operator matches.
1225</pre></td></tr>
1226
1227
Manuel Klimek67619ff2012-09-07 13:10:32 +00001228<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')"><a name="hasLHS0Anchor">hasLHS</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001229<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions.
1230
1231Example matches a (matcher = binaryOperator(hasLHS()))
1232 a || b
1233</pre></td></tr>
1234
1235
Manuel Klimek67619ff2012-09-07 13:10:32 +00001236<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')"><a name="hasRHS0Anchor">hasRHS</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001237<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions.
1238
1239Example matches b (matcher = binaryOperator(hasRHS()))
1240 a || b
1241</pre></td></tr>
1242
1243
Manuel Klimek67619ff2012-09-07 13:10:32 +00001244<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')"><a name="hasDeclaration0Anchor">hasDeclaration</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001245<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a type if the declaration of the type matches the given
1246matcher.
1247
1248Usable 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;
1249</pre></td></tr>
1250
1251
Manuel Klimek67619ff2012-09-07 13:10:32 +00001252<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')"><a name="hasAnyConstructorInitializer0Anchor">hasAnyConstructorInitializer</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001253<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer.
1254
1255Given
1256 struct Foo {
1257 Foo() : foo_(1) { }
1258 int foo_;
1259 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001260recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001261 record matches Foo, hasAnyConstructorInitializer matches foo_(1)
1262</pre></td></tr>
1263
1264
Manuel Klimek67619ff2012-09-07 13:10:32 +00001265<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')"><a name="forField0Anchor">forField</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001266<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer.
1267
1268Given
1269 struct Foo {
1270 Foo() : foo_(1) { }
1271 int foo_;
1272 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001273recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
Manuel Klimek1da79332012-08-20 20:54:03 +00001274 forField(hasName("foo_"))))))
1275 matches Foo
1276with forField matching foo_
1277</pre></td></tr>
1278
1279
Manuel Klimek67619ff2012-09-07 13:10:32 +00001280<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')"><a name="withInitializer0Anchor">withInitializer</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001281<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer.
1282
1283Given
1284 struct Foo {
1285 Foo() : foo_(1) { }
1286 int foo_;
1287 };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001288recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
Manuel Klimek1da79332012-08-20 20:54:03 +00001289 withInitializer(integerLiteral(equals(1)))))))
1290 matches Foo
1291with withInitializer matching (1)
1292</pre></td></tr>
1293
1294
Manuel Klimek67619ff2012-09-07 13:10:32 +00001295<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')"><a name="on0Anchor">on</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001296<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression.
1297
Manuel Klimeke44a0062012-08-26 23:55:24 +00001298Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y"))))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001299 class Y { public: void x(); };
1300 void z() { Y y; y.x(); }",
1301
1302FIXME: Overload to allow directly matching types?
1303</pre></td></tr>
1304
1305
Manuel Klimek67619ff2012-09-07 13:10:32 +00001306<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')"><a name="onImplicitObjectArgument0Anchor">onImplicitObjectArgument</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001307<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre></pre></td></tr>
1308
1309
Manuel Klimek67619ff2012-09-07 13:10:32 +00001310<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')"><a name="thisPointerType1Anchor">thisPointerType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001311<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration.
1312</pre></td></tr>
1313
1314
Manuel Klimek67619ff2012-09-07 13:10:32 +00001315<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')"><a name="ofClass0Anchor">ofClass</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001316<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration
1317belongs to.
1318
1319FIXME: Generalize this for other kinds of declarations.
1320FIXME: What other kind of declarations would we need to generalize
1321this to?
1322
1323Example matches A() in the last line
Manuel Klimeke44a0062012-08-26 23:55:24 +00001324 (matcher = constructExpr(hasDeclaration(methodDecl(
Manuel Klimek1da79332012-08-20 20:54:03 +00001325 ofClass(hasName("A"))))))
1326 class A {
1327 public:
1328 A();
1329 };
1330 A a = A();
1331</pre></td></tr>
1332
1333
Manuel Klimek67619ff2012-09-07 13:10:32 +00001334<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isA0')"><a name="isA0Anchor">isA</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt; Base</td></tr>
1335<tr><td colspan="4" class="doc" id="isA0"><pre>Similar to isDerivedFrom(), but also matches classes that directly
1336match Base.
1337</pre></td></tr>
1338
1339
1340<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')"><a name="isDerivedFrom0Anchor">isDerivedFrom</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt; Base</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001341<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from
1342a class matching Base.
1343
Manuel Klimek67619ff2012-09-07 13:10:32 +00001344Note that a class is not considered to be derived from itself.
Manuel Klimek1da79332012-08-20 20:54:03 +00001345
Manuel Klimek67619ff2012-09-07 13:10:32 +00001346Example matches Y, Z, C (Base == hasName("X"))
1347 class X;
Manuel Klimek1da79332012-08-20 20:54:03 +00001348 class Y : public X {}; directly derived
1349 class Z : public Y {}; indirectly derived
1350 typedef X A;
1351 typedef A B;
1352 class C : public B {}; derived from a typedef of X
1353
1354In the following example, Bar matches isDerivedFrom(hasName("X")):
1355 class Foo;
1356 typedef Foo X;
1357 class Bar : public Foo {}; derived from a type that X is a typedef of
1358</pre></td></tr>
1359
1360
Manuel Klimek67619ff2012-09-07 13:10:32 +00001361<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')"><a name="callee1Anchor">callee</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001362<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the
1363given matcher.
1364
Manuel Klimeke44a0062012-08-26 23:55:24 +00001365Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001366 class Y { public: void x(); };
1367 void z() { Y y; y.x();
1368</pre></td></tr>
1369
1370
Manuel Klimek67619ff2012-09-07 13:10:32 +00001371<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')"><a name="hasAnyArgument0Anchor">hasAnyArgument</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001372<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call
1373expression.
1374
1375Given
1376 void x(int, int, int) { int y; x(1, y, 42); }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001377callExpr(hasAnyArgument(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001378 matches x(1, y, 42)
1379with hasAnyArgument(...)
1380 matching y
1381</pre></td></tr>
1382
1383
Manuel Klimek67619ff2012-09-07 13:10:32 +00001384<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')"><a name="hasArgument0Anchor">hasArgument</a></td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001385<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor
1386call expression.
1387
1388Example matches y in x(y)
Manuel Klimeke44a0062012-08-26 23:55:24 +00001389 (matcher = callExpr(hasArgument(0, declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001390 void x(int) { int y; x(y); }
1391</pre></td></tr>
1392
1393
Manuel Klimek67619ff2012-09-07 13:10:32 +00001394<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')"><a name="hasDeclaration1Anchor">hasDeclaration</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001395<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a type if the declaration of the type matches the given
1396matcher.
1397
1398Usable 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;
1399</pre></td></tr>
1400
1401
Manuel Klimek67619ff2012-09-07 13:10:32 +00001402<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')"><a name="hasSourceExpression0Anchor">hasSourceExpression</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001403<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression matches the given matcher.
1404
1405Example: matches "a string" (matcher =
Manuel Klimeke44a0062012-08-26 23:55:24 +00001406 hasSourceExpression(constructExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001407class URL { URL(string); };
1408URL url = "a string";
1409</pre></td></tr>
1410
1411
Manuel Klimek67619ff2012-09-07 13:10:32 +00001412<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')"><a name="hasAnyTemplateArgument0Anchor">hasAnyTemplateArgument</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001413<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations that have at least one
1414TemplateArgument matching the given InnerMatcher.
1415
1416Given
1417 template&lt;typename T&gt; class A {};
1418 template&lt;&gt; class A&lt;double&gt; {};
1419 A&lt;int&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001420classTemplateSpecializationDecl(hasAnyTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001421 refersToType(asString("int"))))
1422 matches the specialization A&lt;int&gt;
1423</pre></td></tr>
1424
1425
Manuel Klimek67619ff2012-09-07 13:10:32 +00001426<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')"><a name="hasTemplateArgument0Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001427<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument
1428matches the given InnerMatcher.
1429
1430Given
1431 template&lt;typename T, typename U&gt; class A {};
1432 A&lt;bool, int&gt; b;
1433 A&lt;int, bool&gt; c;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001434classTemplateSpecializationDecl(hasTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001435 1, refersToType(asString("int"))))
1436 matches the specialization A&lt;bool, int&gt;
1437</pre></td></tr>
1438
1439
Manuel Klimek67619ff2012-09-07 13:10:32 +00001440<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')"><a name="hasAnySubstatement0Anchor">hasAnySubstatement</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001441<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches
1442a given matcher.
1443
1444Given
1445 { {}; 1+2; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001446hasAnySubstatement(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001447 matches '{ {}; 1+2; }'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001448with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001449 matching '{}'
1450</pre></td></tr>
1451
1452
Manuel Klimek67619ff2012-09-07 13:10:32 +00001453<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')"><a name="hasCondition4Anchor">hasCondition</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001454<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop,
1455or conditional operator.
1456
1457Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1458 if (true) {}
1459</pre></td></tr>
1460
1461
Manuel Klimek67619ff2012-09-07 13:10:32 +00001462<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')"><a name="hasFalseExpression0Anchor">hasFalseExpression</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001463<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator.
1464
1465Example matches b
1466 condition ? a : b
1467</pre></td></tr>
1468
1469
Manuel Klimek67619ff2012-09-07 13:10:32 +00001470<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')"><a name="hasTrueExpression0Anchor">hasTrueExpression</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001471<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator.
1472
1473Example matches a
1474 condition ? a : b
1475</pre></td></tr>
1476
1477
Manuel Klimek67619ff2012-09-07 13:10:32 +00001478<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')"><a name="throughUsingDecl0Anchor">throughUsingDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001479<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a
1480specific using shadow declaration.
1481
1482FIXME: This currently only works for functions. Fix.
1483
1484Given
1485 namespace a { void f() {} }
1486 using a::f;
1487 void g() {
1488 f(); Matches this ..
1489 a::f(); .. but not this.
1490 }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001491declRefExpr(throughUsingDeclaration(anything()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001492 matches f()
1493</pre></td></tr>
1494
1495
Manuel Klimek67619ff2012-09-07 13:10:32 +00001496<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')"><a name="to0Anchor">to</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001497<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the
1498specified matcher.
1499
1500Example matches x in if(x)
Manuel Klimeke44a0062012-08-26 23:55:24 +00001501 (matcher = declRefExpr(to(varDecl(hasName("x")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001502 bool x;
1503 if (x) {}
1504</pre></td></tr>
1505
1506
Manuel Klimek67619ff2012-09-07 13:10:32 +00001507<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')"><a name="containsDeclaration0Anchor">containsDeclaration</a></td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001508<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement.
1509
1510Note that this does not work for global declarations because the AST
1511breaks up multiple-declaration DeclStmt's into multiple single-declaration
1512DeclStmt's.
1513Example: Given non-global declarations
1514 int a, b = 0;
1515 int c;
1516 int d = 2, e;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001517declStmt(containsDeclaration(
1518 0, varDecl(hasInitializer(anything()))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001519 matches only 'int d = 2, e;', and
Manuel Klimeke44a0062012-08-26 23:55:24 +00001520declStmt(containsDeclaration(1, varDecl()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001521 matches 'int a, b = 0' as well as 'int d = 2, e;'
1522 but 'int c;' is not matched.
1523</pre></td></tr>
1524
1525
Manuel Klimek67619ff2012-09-07 13:10:32 +00001526<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')"><a name="hasSingleDecl0Anchor">hasSingleDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001527<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration.
1528
1529Given
1530 int a, b;
1531 int c;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001532declStmt(hasSingleDecl(anything()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001533 matches 'int c;' but not 'int a, b;'.
1534</pre></td></tr>
1535
1536
Manuel Klimek67619ff2012-09-07 13:10:32 +00001537<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')"><a name="hasBody0Anchor">hasBody</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001538<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', or 'do while' statement that has
1539a given body.
1540
1541Given
1542 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001543hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001544 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001545with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001546 matching '{}'
1547</pre></td></tr>
1548
1549
Manuel Klimek67619ff2012-09-07 13:10:32 +00001550<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')"><a name="hasCondition3Anchor">hasCondition</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001551<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop,
1552or conditional operator.
1553
1554Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1555 if (true) {}
1556</pre></td></tr>
1557
1558
Manuel Klimek67619ff2012-09-07 13:10:32 +00001559<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')"><a name="hasDestinationType0Anchor">hasDestinationType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001560<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher.
1561
1562(Note: Clang's AST refers to other conversions as "casts" too, and calls
1563actual casts "explicit" casts.)
1564</pre></td></tr>
1565
1566
Manuel Klimek67619ff2012-09-07 13:10:32 +00001567<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')"><a name="hasType3Anchor">hasType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001568<tr><td colspan="4" class="doc" id="hasType3"><pre>Overloaded to match the declaration of the expression's or value
1569declaration's type.
1570
1571In case of a value declaration (for example a variable declaration),
1572this resolves one layer of indirection. For example, in the value
Manuel Klimeke44a0062012-08-26 23:55:24 +00001573declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
1574while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
Manuel Klimek1da79332012-08-20 20:54:03 +00001575of x."
1576
Manuel Klimeke44a0062012-08-26 23:55:24 +00001577Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
1578 and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001579 class X {};
1580 void y(X &amp;x) { x; X z; }
1581
1582Usable 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;
1583</pre></td></tr>
1584
1585
Manuel Klimek67619ff2012-09-07 13:10:32 +00001586<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')"><a name="ignoringImpCasts0Anchor">ignoringImpCasts</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001587<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts
1588are stripped off.
1589
1590Parentheses and explicit casts are not discarded.
1591Given
1592 int arr[5];
1593 int a = 0;
1594 char b = 0;
1595 const int c = a;
1596 int *d = arr;
1597 long e = (long) 0l;
1598The matchers
Manuel Klimeke44a0062012-08-26 23:55:24 +00001599 varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
1600 varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001601would match the declarations for a, b, c, and d, but not e.
1602While
Manuel Klimeke44a0062012-08-26 23:55:24 +00001603 varDecl(hasInitializer(integerLiteral()))
1604 varDecl(hasInitializer(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001605only match the declarations for b, c, and d.
1606</pre></td></tr>
1607
1608
Manuel Klimek67619ff2012-09-07 13:10:32 +00001609<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')"><a name="ignoringParenCasts0Anchor">ignoringParenCasts</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001610<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and
1611casts are stripped off.
1612
1613Implicit and non-C Style casts are also discarded.
1614Given
1615 int a = 0;
1616 char b = (0);
1617 void* c = reinterpret_cast&lt;char*&gt;(0);
1618 char d = char(0);
1619The matcher
Manuel Klimeke44a0062012-08-26 23:55:24 +00001620 varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001621would match the declarations for a, b, c, and d.
1622while
Manuel Klimeke44a0062012-08-26 23:55:24 +00001623 varDecl(hasInitializer(integerLiteral()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001624only match the declaration for a.
1625</pre></td></tr>
1626
1627
Manuel Klimek67619ff2012-09-07 13:10:32 +00001628<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')"><a name="ignoringParenImpCasts0Anchor">ignoringParenImpCasts</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001629<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and
1630parentheses are stripped off.
1631
1632Explicit casts are not discarded.
1633Given
1634 int arr[5];
1635 int a = 0;
1636 char b = (0);
1637 const int c = a;
1638 int *d = (arr);
1639 long e = ((long) 0l);
1640The matchers
Manuel Klimeke44a0062012-08-26 23:55:24 +00001641 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
1642 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001643would match the declarations for a, b, c, and d, but not e.
1644while
Manuel Klimeke44a0062012-08-26 23:55:24 +00001645 varDecl(hasInitializer(integerLiteral()))
1646 varDecl(hasInitializer(declRefExpr()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001647would only match the declaration for a.
1648</pre></td></tr>
1649
1650
Manuel Klimek67619ff2012-09-07 13:10:32 +00001651<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')"><a name="hasBody1Anchor">hasBody</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001652<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', or 'do while' statement that has
1653a given body.
1654
1655Given
1656 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001657hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001658 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001659with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001660 matching '{}'
1661</pre></td></tr>
1662
1663
Manuel Klimek67619ff2012-09-07 13:10:32 +00001664<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')"><a name="hasCondition1Anchor">hasCondition</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001665<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop,
1666or conditional operator.
1667
1668Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1669 if (true) {}
1670</pre></td></tr>
1671
1672
Manuel Klimek67619ff2012-09-07 13:10:32 +00001673<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')"><a name="hasIncrement0Anchor">hasIncrement</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001674<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop.
1675
1676Example:
1677 forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
1678matches '++x' in
1679 for (x; x &lt; N; ++x) { }
1680</pre></td></tr>
1681
1682
Manuel Klimek67619ff2012-09-07 13:10:32 +00001683<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')"><a name="hasLoopInit0Anchor">hasLoopInit</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001684<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop.
1685
1686Example:
Manuel Klimeke44a0062012-08-26 23:55:24 +00001687 forStmt(hasLoopInit(declStmt()))
Manuel Klimek1da79332012-08-20 20:54:03 +00001688matches 'int x = 0' in
1689 for (int x = 0; x &lt; N; ++x) { }
1690</pre></td></tr>
1691
1692
Manuel Klimek67619ff2012-09-07 13:10:32 +00001693<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')"><a name="hasAnyParameter0Anchor">hasAnyParameter</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001694<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function declaration.
1695
1696Does not match the 'this' parameter of a method.
1697
1698Given
1699 class X { void f(int x, int y, int z) {} };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001700methodDecl(hasAnyParameter(hasName("y")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001701 matches f(int x, int y, int z) {}
1702with hasAnyParameter(...)
1703 matching int y
1704</pre></td></tr>
1705
1706
Manuel Klimek67619ff2012-09-07 13:10:32 +00001707<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')"><a name="hasParameter0Anchor">hasParameter</a></td><td>unsigned N, Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001708<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function declaration.
1709
1710Given
1711 class X { void f(int x) {} };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001712methodDecl(hasParameter(0, hasType(varDecl())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001713 matches f(int x) {}
1714with hasParameter(...)
1715 matching int x
1716</pre></td></tr>
1717
1718
Manuel Klimek67619ff2012-09-07 13:10:32 +00001719<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')"><a name="returns0Anchor">returns</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001720<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration.
1721
1722Given:
1723 class X { int f() { return 1; } };
Manuel Klimeke44a0062012-08-26 23:55:24 +00001724methodDecl(returns(asString("int")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001725 matches int f() { return 1; }
1726</pre></td></tr>
1727
1728
Manuel Klimek67619ff2012-09-07 13:10:32 +00001729<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')"><a name="hasCondition0Anchor">hasCondition</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001730<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop,
1731or conditional operator.
1732
1733Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1734 if (true) {}
1735</pre></td></tr>
1736
1737
Manuel Klimek67619ff2012-09-07 13:10:32 +00001738<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')"><a name="hasConditionVariableStatement0Anchor">hasConditionVariableStatement</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001739<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement.
1740
1741Given
1742 if (A* a = GetAPointer()) {}
1743hasConditionVariableStatment(...)
1744 matches 'A* a = GetAPointer()'.
1745</pre></td></tr>
1746
1747
Manuel Klimek67619ff2012-09-07 13:10:32 +00001748<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')"><a name="hasImplicitDestinationType0Anchor">hasImplicitDestinationType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001749<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given
1750matcher.
1751
1752FIXME: Unit test this matcher
1753</pre></td></tr>
1754
1755
Manuel Klimek67619ff2012-09-07 13:10:32 +00001756<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')"><a name="hasObjectExpression0Anchor">hasObjectExpression</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001757<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is
1758matched by a given matcher.
1759
1760Given
1761 struct X { int m; };
1762 void f(X x) { x.m; m; }
Manuel Klimeke44a0062012-08-26 23:55:24 +00001763memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X")))))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001764 matches "x.m" and "m"
1765with hasObjectExpression(...)
1766 matching "x" and the implicit object expression of "m" which has type X*.
1767</pre></td></tr>
1768
1769
Manuel Klimek67619ff2012-09-07 13:10:32 +00001770<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')"><a name="member0Anchor">member</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001771<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a
1772given matcher.
1773
1774Given
1775 struct { int first, second; } first, second;
1776 int i(second.first);
1777 int j(first.second);
Manuel Klimeke44a0062012-08-26 23:55:24 +00001778memberExpr(member(hasName("first")))
Manuel Klimek1da79332012-08-20 20:54:03 +00001779 matches second.first
1780 but not first.second (because the member name there is "second").
1781</pre></td></tr>
1782
1783
Manuel Klimek67619ff2012-09-07 13:10:32 +00001784<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')"><a name="hasDeclaration2Anchor">hasDeclaration</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001785<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a type if the declaration of the type matches the given
1786matcher.
1787
1788Usable 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;
1789</pre></td></tr>
1790
1791
Manuel Klimek67619ff2012-09-07 13:10:32 +00001792<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')"><a name="pointsTo1Anchor">pointsTo</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001793<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration.
1794</pre></td></tr>
1795
1796
Manuel Klimek67619ff2012-09-07 13:10:32 +00001797<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')"><a name="references1Anchor">references</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001798<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration.
1799</pre></td></tr>
1800
1801
Manuel Klimek67619ff2012-09-07 13:10:32 +00001802<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')"><a name="alignOfExpr0Anchor">alignOfExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001803<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1804alignof.
1805</pre></td></tr>
1806
1807
Manuel Klimek67619ff2012-09-07 13:10:32 +00001808<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')"><a name="sizeOfExpr0Anchor">sizeOfExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001809<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching
1810sizeof.
1811</pre></td></tr>
1812
1813
Manuel Klimek67619ff2012-09-07 13:10:32 +00001814<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')"><a name="refersToDeclaration0Anchor">refersToDeclaration</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001815<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a TemplateArgument that refers to a certain declaration.
1816
1817Given
1818 template&lt;typename T&gt; struct A {};
1819 struct B { B* next; };
1820 A&lt;&amp;B::next&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001821classTemplateSpecializationDecl(hasAnyTemplateArgument(
1822 refersToDeclaration(fieldDecl(hasName("next"))))
1823 matches the specialization A&lt;&amp;B::next&gt; with fieldDecl(...) matching
Manuel Klimek1da79332012-08-20 20:54:03 +00001824 B::next
1825</pre></td></tr>
1826
1827
Manuel Klimek67619ff2012-09-07 13:10:32 +00001828<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')"><a name="refersToType0Anchor">refersToType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001829<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type.
1830
1831Given
1832 struct X {};
1833 template&lt;typename T&gt; struct A {};
1834 A&lt;X&gt; a;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001835classTemplateSpecializationDecl(hasAnyTemplateArgument(
Manuel Klimek1da79332012-08-20 20:54:03 +00001836 refersToType(class(hasName("X")))))
1837 matches the specialization A&lt;X&gt;
1838</pre></td></tr>
1839
1840
Manuel Klimek67619ff2012-09-07 13:10:32 +00001841<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')"><a name="hasArgumentOfType0Anchor">hasArgumentOfType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001842<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument.
1843
1844Given
1845 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
1846unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
1847 matches sizeof(a) and alignof(c)
1848</pre></td></tr>
1849
1850
Manuel Klimek67619ff2012-09-07 13:10:32 +00001851<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')"><a name="hasUnaryOperand0Anchor">hasUnaryOperand</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001852<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches.
1853
1854Example matches true (matcher = hasOperand(boolLiteral(equals(true))))
1855 !true
1856</pre></td></tr>
1857
1858
Manuel Klimek67619ff2012-09-07 13:10:32 +00001859<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')"><a name="hasAnyUsingShadowDecl0Anchor">hasAnyUsingShadowDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001860<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration.
1861
1862Given
1863 namespace X { void b(); }
1864 using X::b;
1865usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
1866 matches using X::b </pre></td></tr>
1867
1868
Manuel Klimek67619ff2012-09-07 13:10:32 +00001869<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')"><a name="hasTargetDecl0Anchor">hasTargetDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001870<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is
1871matched by the given matcher.
1872
1873Given
1874 namespace X { int a; void b(); }
1875 using X::a;
1876 using X::b;
Manuel Klimeke44a0062012-08-26 23:55:24 +00001877usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001878 matches using X::b but not using X::a </pre></td></tr>
1879
1880
Manuel Klimek67619ff2012-09-07 13:10:32 +00001881<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')"><a name="hasType2Anchor">hasType</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001882<tr><td colspan="4" class="doc" id="hasType2"><pre>Overloaded to match the declaration of the expression's or value
1883declaration's type.
1884
1885In case of a value declaration (for example a variable declaration),
1886this resolves one layer of indirection. For example, in the value
Manuel Klimeke44a0062012-08-26 23:55:24 +00001887declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
1888while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
Manuel Klimek1da79332012-08-20 20:54:03 +00001889of x."
1890
Manuel Klimeke44a0062012-08-26 23:55:24 +00001891Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
1892 and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
Manuel Klimek1da79332012-08-20 20:54:03 +00001893 class X {};
1894 void y(X &amp;x) { x; X z; }
1895
1896Usable 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;
1897</pre></td></tr>
1898
1899
Manuel Klimek67619ff2012-09-07 13:10:32 +00001900<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')"><a name="hasInitializer0Anchor">hasInitializer</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001901<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression
1902that matches the given matcher.
1903
Manuel Klimeke44a0062012-08-26 23:55:24 +00001904Example matches x (matcher = varDecl(hasInitializer(callExpr())))
Manuel Klimek1da79332012-08-20 20:54:03 +00001905 bool y() { return true; }
1906 bool x = y();
1907</pre></td></tr>
1908
1909
Manuel Klimek67619ff2012-09-07 13:10:32 +00001910<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')"><a name="hasBody2Anchor">hasBody</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001911<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', or 'do while' statement that has
1912a given body.
1913
1914Given
1915 for (;;) {}
Manuel Klimeke44a0062012-08-26 23:55:24 +00001916hasBody(compoundStmt())
Manuel Klimek1da79332012-08-20 20:54:03 +00001917 matches 'for (;;) {}'
Manuel Klimeke44a0062012-08-26 23:55:24 +00001918with compoundStmt()
Manuel Klimek1da79332012-08-20 20:54:03 +00001919 matching '{}'
1920</pre></td></tr>
1921
1922
Manuel Klimek67619ff2012-09-07 13:10:32 +00001923<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')"><a name="hasCondition2Anchor">hasCondition</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
Manuel Klimek1da79332012-08-20 20:54:03 +00001924<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop,
1925or conditional operator.
1926
1927Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
1928 if (true) {}
1929</pre></td></tr>
1930
1931<!--END_TRAVERSAL_MATCHERS -->
1932</table>
1933
1934</div>
1935</body>
1936</html>
1937
1938