1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3<html> 4<head> 5<title>AST Matcher Reference</title> 6<link type="text/css" rel="stylesheet" href="../menu.css" /> 7<link type="text/css" rel="stylesheet" href="../content.css" /> 8<style type="text/css"> 9td { 10 padding: .33em; 11} 12td.doc { 13 display: none; 14 border-bottom: 1px solid black; 15} 16td.name:hover { 17 color: blue; 18 cursor: pointer; 19} 20</style> 21<script type="text/javascript"> 22function toggle(id) { 23 if (!id) return; 24 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> 32<body onLoad="toggle(location.hash.substring(1, location.hash.length - 6))"> 33 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<Stmt> 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<p>Note that the categorization of matchers is a great help when you combine 61them into matcher expressions. You will usually want to form matcher expressions 62that read like english sentences by alternating between node matchers and 63narrowing or traversal matchers, like this: 64<pre> 65recordDecl(hasDescendant( 66 ifStmt(hasTrueExpression( 67 expr(hasDescendant( 68 ifStmt())))))) 69</pre> 70</p> 71 72<!-- ======================================================================= --> 73<h2 id="decl-matchers">Node Matchers</h2> 74<!-- ======================================================================= --> 75 76<p>Node matchers are at the core of matcher expressions - they specify the type 77of node that is expected. Every match expression starts with a node matcher, 78which can then be further refined with a narrowing or traversal matcher. All 79traversal matchers take node matchers as their arguments.</p> 80 81<p>For convenience, all node matchers take an arbitrary number of arguments 82and implicitly act as allOf matchers.</p> 83 84<p>Node matchers are the only matchers that support the bind("id") call to 85bind the matched node to the given string, to be later retrieved from the 86match callback.</p> 87 88<p>It is important to remember that the arguments to node matchers are 89predicates on the same node, just with additional information about the type. 90This is often useful to make matcher expression more readable by inlining bind 91calls into redundant node matchers inside another node matcher: 92<pre> 93// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on 94// the same node. 95recordDecl(decl().bind("id"), hasName("::MyClass")) 96</pre> 97</p> 98 99<table> 100<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 101<!-- START_DECL_MATCHERS --> 102 103<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('ctorInitializer0')"><a name="ctorInitializer0Anchor">ctorInitializer</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>...</td></tr> 104<tr><td colspan="4" class="doc" id="ctorInitializer0"><pre>Matches constructor initializers. 105 106Examples matches i(42). 107 class C { 108 C() : i(42) {} 109 int i; 110 }; 111</pre></td></tr> 112 113 114<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('accessSpecDecl0')"><a name="accessSpecDecl0Anchor">accessSpecDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AccessSpecDecl.html">AccessSpecDecl</a>>...</td></tr> 115<tr><td colspan="4" class="doc" id="accessSpecDecl0"><pre>Matches C++ access specifier declarations. 116 117Given 118 class C { 119 public: 120 int a; 121 }; 122accessSpecDecl() 123 matches 'public:' 124</pre></td></tr> 125 126 127<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateDecl0')"><a name="classTemplateDecl0Anchor">classTemplateDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>>...</td></tr> 128<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations. 129 130Example matches Z 131 template<class T> class Z {}; 132</pre></td></tr> 133 134 135<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateSpecializationDecl0')"><a name="classTemplateSpecializationDecl0Anchor">classTemplateSpecializationDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>>...</td></tr> 136<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations. 137 138Given 139 template<typename T> class A {}; 140 template<> class A<double> {}; 141 A<int> a; 142classTemplateSpecializationDecl() 143 matches the specializations A<int> and A<double> 144</pre></td></tr> 145 146 147<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('constructorDecl0')"><a name="constructorDecl0Anchor">constructorDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>>...</td></tr> 148<tr><td colspan="4" class="doc" id="constructorDecl0"><pre>Matches C++ constructor declarations. 149 150Example matches Foo::Foo() and Foo::Foo(int) 151 class Foo { 152 public: 153 Foo(); 154 Foo(int); 155 int DoSomething(); 156 }; 157</pre></td></tr> 158 159 160<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('decl0')"><a name="decl0Anchor">decl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>...</td></tr> 161<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations. 162 163Examples matches X, C, and the friend declaration inside C; 164 void X(); 165 class C { 166 friend X; 167 }; 168</pre></td></tr> 169 170 171<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('declaratorDecl0')"><a name="declaratorDecl0Anchor">declaratorDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>...</td></tr> 172<tr><td colspan="4" class="doc" id="declaratorDecl0"><pre>Matches declarator declarations (field, variable, function 173and non-type template parameter declarations). 174 175Given 176 class X { int y; }; 177declaratorDecl() 178 matches int y. 179</pre></td></tr> 180 181 182<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('destructorDecl0')"><a name="destructorDecl0Anchor">destructorDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>>...</td></tr> 183<tr><td colspan="4" class="doc" id="destructorDecl0"><pre>Matches explicit C++ destructor declarations. 184 185Example matches Foo::~Foo() 186 class Foo { 187 public: 188 virtual ~Foo(); 189 }; 190</pre></td></tr> 191 192 193<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumConstantDecl0')"><a name="enumConstantDecl0Anchor">enumConstantDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>>...</td></tr> 194<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants. 195 196Example matches A, B, C 197 enum X { 198 A, B, C 199 }; 200</pre></td></tr> 201 202 203<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumDecl0')"><a name="enumDecl0Anchor">enumDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>>...</td></tr> 204<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations. 205 206Example matches X 207 enum X { 208 A, B, C 209 }; 210</pre></td></tr> 211 212 213<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('fieldDecl0')"><a name="fieldDecl0Anchor">fieldDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>>...</td></tr> 214<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations. 215 216Given 217 class X { int m; }; 218fieldDecl() 219 matches 'm'. 220</pre></td></tr> 221 222 223<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('friendDecl0')"><a name="friendDecl0Anchor">friendDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>...</td></tr> 224<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations. 225 226Given 227 class X { friend void foo(); }; 228friendDecl() 229 matches 'friend void foo()'. 230</pre></td></tr> 231 232 233<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionDecl0')"><a name="functionDecl0Anchor">functionDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>...</td></tr> 234<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations. 235 236Example matches f 237 void f(); 238</pre></td></tr> 239 240 241<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionTemplateDecl0')"><a name="functionTemplateDecl0Anchor">functionTemplateDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>>...</td></tr> 242<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations. 243 244Example matches f 245 template<class T> void f(T t) {} 246</pre></td></tr> 247 248 249<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('methodDecl0')"><a name="methodDecl0Anchor">methodDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>...</td></tr> 250<tr><td colspan="4" class="doc" id="methodDecl0"><pre>Matches method declarations. 251 252Example matches y 253 class X { void y(); }; 254</pre></td></tr> 255 256 257<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namedDecl0')"><a name="namedDecl0Anchor">namedDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>>...</td></tr> 258<tr><td colspan="4" class="doc" id="namedDecl0"><pre>Matches a declaration of anything that could have a name. 259 260Example matches X, S, the anonymous union type, i, and U; 261 typedef int X; 262 struct S { 263 union { 264 int i; 265 } U; 266 }; 267</pre></td></tr> 268 269 270<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namespaceDecl0')"><a name="namespaceDecl0Anchor">namespaceDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>>...</td></tr> 271<tr><td colspan="4" class="doc" id="namespaceDecl0"><pre>Matches a declaration of a namespace. 272 273Given 274 namespace {} 275 namespace test {} 276namespaceDecl() 277 matches "namespace {}" and "namespace test {}" 278</pre></td></tr> 279 280 281<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('parmVarDecl0')"><a name="parmVarDecl0Anchor">parmVarDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>>...</td></tr> 282<tr><td colspan="4" class="doc" id="parmVarDecl0"><pre>Matches parameter variable declarations. 283 284Given 285 void f(int x); 286parmVarDecl() 287 matches int x. 288</pre></td></tr> 289 290 291<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('recordDecl0')"><a name="recordDecl0Anchor">recordDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>...</td></tr> 292<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches C++ class declarations. 293 294Example matches X, Z 295 class X; 296 template<class T> class Z {}; 297</pre></td></tr> 298 299 300<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('unresolvedUsingValueDecl0')"><a name="unresolvedUsingValueDecl0Anchor">unresolvedUsingValueDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingValueDecl.html">UnresolvedUsingValueDecl</a>>...</td></tr> 301<tr><td colspan="4" class="doc" id="unresolvedUsingValueDecl0"><pre>Matches unresolved using value declarations. 302 303Given 304 template<typename X> 305 class C : private X { 306 using X::x; 307 }; 308unresolvedUsingValueDecl() 309 matches using X::x </pre></td></tr> 310 311 312<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingDecl0')"><a name="usingDecl0Anchor">usingDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>>...</td></tr> 313<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations. 314 315Given 316 namespace X { int x; } 317 using X::x; 318usingDecl() 319 matches using X::x </pre></td></tr> 320 321 322<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('varDecl0')"><a name="varDecl0Anchor">varDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>...</td></tr> 323<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations. 324 325Note: this does not match declarations of member variables, which are 326"field" declarations in Clang parlance. 327 328Example matches a 329 int a; 330</pre></td></tr> 331 332 333<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('nestedNameSpecifierLoc0')"><a name="nestedNameSpecifierLoc0Anchor">nestedNameSpecifierLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>>...</td></tr> 334<tr><td colspan="4" class="doc" id="nestedNameSpecifierLoc0"><pre>Same as nestedNameSpecifier but matches NestedNameSpecifierLoc. 335</pre></td></tr> 336 337 338<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('nestedNameSpecifier0')"><a name="nestedNameSpecifier0Anchor">nestedNameSpecifier</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>>...</td></tr> 339<tr><td colspan="4" class="doc" id="nestedNameSpecifier0"><pre>Matches nested name specifiers. 340 341Given 342 namespace ns { 343 struct A { static void f(); }; 344 void A::f() {} 345 void g() { A::f(); } 346 } 347 ns::A a; 348nestedNameSpecifier() 349 matches "ns::" and both "A::" 350</pre></td></tr> 351 352 353<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('qualType0')"><a name="qualType0Anchor">qualType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>...</td></tr> 354<tr><td colspan="4" class="doc" id="qualType0"><pre>Matches QualTypes in the clang AST. 355</pre></td></tr> 356 357 358<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('arraySubscriptExpr0')"><a name="arraySubscriptExpr0Anchor">arraySubscriptExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>>...</td></tr> 359<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions. 360 361Given 362 int i = a[1]; 363arraySubscriptExpr() 364 matches "a[1]" 365</pre></td></tr> 366 367 368<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('asmStmt0')"><a name="asmStmt0Anchor">asmStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AsmStmt.html">AsmStmt</a>>...</td></tr> 369<tr><td colspan="4" class="doc" id="asmStmt0"><pre>Matches asm statements. 370 371 int i = 100; 372 __asm("mov al, 2"); 373asmStmt() 374 matches '__asm("mov al, 2")' 375</pre></td></tr> 376 377 378<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('binaryOperator0')"><a name="binaryOperator0Anchor">binaryOperator</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>>...</td></tr> 379<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions. 380 381Example matches a || b 382 !(a || b) 383</pre></td></tr> 384 385 386<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('bindTemporaryExpr0')"><a name="bindTemporaryExpr0Anchor">bindTemporaryExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>>...</td></tr> 387<tr><td colspan="4" class="doc" id="bindTemporaryExpr0"><pre>Matches nodes where temporaries are created. 388 389Example matches FunctionTakesString(GetStringByValue()) 390 (matcher = bindTemporaryExpr()) 391 FunctionTakesString(GetStringByValue()); 392 FunctionTakesStringByPointer(GetStringPointer()); 393</pre></td></tr> 394 395 396<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('boolLiteral0')"><a name="boolLiteral0Anchor">boolLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>...</td></tr> 397<tr><td colspan="4" class="doc" id="boolLiteral0"><pre>Matches bool literals. 398 399Example matches true 400 true 401</pre></td></tr> 402 403 404<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('breakStmt0')"><a name="breakStmt0Anchor">breakStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html">BreakStmt</a>>...</td></tr> 405<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements. 406 407Given 408 while (true) { break; } 409breakStmt() 410 matches 'break' 411</pre></td></tr> 412 413 414<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cStyleCastExpr0')"><a name="cStyleCastExpr0Anchor">cStyleCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CStyleCastExpr.html">CStyleCastExpr</a>>...</td></tr> 415<tr><td colspan="4" class="doc" id="cStyleCastExpr0"><pre>Matches a C-style cast expression. 416 417Example: Matches (int*) 2.2f in 418 int i = (int) 2.2f; 419</pre></td></tr> 420 421 422<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('callExpr0')"><a name="callExpr0Anchor">callExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>...</td></tr> 423<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions. 424 425Example matches x.y() and y() 426 X x; 427 x.y(); 428 y(); 429</pre></td></tr> 430 431 432<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('caseStmt0')"><a name="caseStmt0Anchor">caseStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>>...</td></tr> 433<tr><td colspan="4" class="doc" id="caseStmt0"><pre>Matches case statements inside switch statements. 434 435Given 436 switch(a) { case 42: break; default: break; } 437caseStmt() 438 matches 'case 42: break;'. 439</pre></td></tr> 440 441 442<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('castExpr0')"><a name="castExpr0Anchor">castExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>>...</td></tr> 443<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST. 444 445Example: castExpr() matches each of the following: 446 (int) 3; 447 const_cast<Expr *>(SubExpr); 448 char c = 0; 449but does not match 450 int i = (0); 451 int k = 0; 452</pre></td></tr> 453 454 455<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('catchStmt0')"><a name="catchStmt0Anchor">catchStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>>...</td></tr> 456<tr><td colspan="4" class="doc" id="catchStmt0"><pre>Matches catch statements. 457 458 try {} catch(int i) {} 459catchStmt() 460 matches 'catch(int i)' 461</pre></td></tr> 462 463 464<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('characterLiteral0')"><a name="characterLiteral0Anchor">characterLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>...</td></tr> 465<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t). 466 467Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), 468though. 469 470Example matches 'a', L'a' 471 char ch = 'a'; wchar_t chw = L'a'; 472</pre></td></tr> 473 474 475<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundLiteralExpr0')"><a name="compoundLiteralExpr0Anchor">compoundLiteralExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>...</td></tr> 476<tr><td colspan="4" class="doc" id="compoundLiteralExpr0"><pre>Matches compound (i.e. non-scalar) literals 477 478Example match: {1}, (1, 2) 479 int array[4] = {1}; vector int myvec = (vector int)(1, 2); 480</pre></td></tr> 481 482 483<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundStmt0')"><a name="compoundStmt0Anchor">compoundStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>>...</td></tr> 484<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements. 485 486Example matches '{}' and '{{}}'in 'for (;;) {{}}' 487 for (;;) {{}} 488</pre></td></tr> 489 490 491<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('conditionalOperator0')"><a name="conditionalOperator0Anchor">conditionalOperator</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>>...</td></tr> 492<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions. 493 494Example matches a ? b : c 495 (a ? b : c) + 42 496</pre></td></tr> 497 498 499<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('constCastExpr0')"><a name="constCastExpr0Anchor">constCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>>...</td></tr> 500<tr><td colspan="4" class="doc" id="constCastExpr0"><pre>Matches a const_cast expression. 501 502Example: Matches const_cast<int*>(&r) in 503 int n = 42; 504 const int &r(n); 505 int* p = const_cast<int*>(&r); 506</pre></td></tr> 507 508 509<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('constructExpr0')"><a name="constructExpr0Anchor">constructExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>...</td></tr> 510<tr><td colspan="4" class="doc" id="constructExpr0"><pre>Matches constructor call expressions (including implicit ones). 511 512Example matches string(ptr, n) and ptr within arguments of f 513 (matcher = constructExpr()) 514 void f(const string &a, const string &b); 515 char *ptr; 516 int n; 517 f(string(ptr, n), ptr); 518</pre></td></tr> 519 520 521<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('continueStmt0')"><a name="continueStmt0Anchor">continueStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ContinueStmt.html">ContinueStmt</a>>...</td></tr> 522<tr><td colspan="4" class="doc" id="continueStmt0"><pre>Matches continue statements. 523 524Given 525 while (true) { continue; } 526continueStmt() 527 matches 'continue' 528</pre></td></tr> 529 530 531<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declRefExpr0')"><a name="declRefExpr0Anchor">declRefExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>...</td></tr> 532<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations. 533 534Example matches x in if (x) 535 bool x; 536 if (x) {} 537</pre></td></tr> 538 539 540<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declStmt0')"><a name="declStmt0Anchor">declStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>>...</td></tr> 541<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements. 542 543Given 544 int a; 545declStmt() 546 matches 'int a'. 547</pre></td></tr> 548 549 550<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('defaultArgExpr0')"><a name="defaultArgExpr0Anchor">defaultArgExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>>...</td></tr> 551<tr><td colspan="4" class="doc" id="defaultArgExpr0"><pre>Matches the value of a default argument at the call site. 552 553Example matches the CXXDefaultArgExpr placeholder inserted for the 554 default value of the second parameter in the call expression f(42) 555 (matcher = defaultArgExpr()) 556 void f(int x, int y = 0); 557 f(42); 558</pre></td></tr> 559 560 561<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('defaultStmt0')"><a name="defaultStmt0Anchor">defaultStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DefaultStmt.html">DefaultStmt</a>>...</td></tr> 562<tr><td colspan="4" class="doc" id="defaultStmt0"><pre>Matches default statements inside switch statements. 563 564Given 565 switch(a) { case 42: break; default: break; } 566defaultStmt() 567 matches 'default: break;'. 568</pre></td></tr> 569 570 571<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('deleteExpr0')"><a name="deleteExpr0Anchor">deleteExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>>...</td></tr> 572<tr><td colspan="4" class="doc" id="deleteExpr0"><pre>Matches delete expressions. 573 574Given 575 delete X; 576deleteExpr() 577 matches 'delete X'. 578</pre></td></tr> 579 580 581<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('doStmt0')"><a name="doStmt0Anchor">doStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>>...</td></tr> 582<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements. 583 584Given 585 do {} while (true); 586doStmt() 587 matches 'do {} while(true)' 588</pre></td></tr> 589 590 591<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('dynamicCastExpr0')"><a name="dynamicCastExpr0Anchor">dynamicCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>>...</td></tr> 592<tr><td colspan="4" class="doc" id="dynamicCastExpr0"><pre>Matches a dynamic_cast expression. 593 594Example: 595 dynamicCastExpr() 596matches 597 dynamic_cast<D*>(&b); 598in 599 struct B { virtual ~B() {} }; struct D : B {}; 600 B b; 601 D* p = dynamic_cast<D*>(&b); 602</pre></td></tr> 603 604 605<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('explicitCastExpr0')"><a name="explicitCastExpr0Anchor">explicitCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>...</td></tr> 606<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions. 607 608Matches any cast expression written in user code, whether it be a 609C-style cast, a functional-style cast, or a keyword cast. 610 611Does not match implicit conversions. 612 613Note: the name "explicitCast" is chosen to match Clang's terminology, as 614Clang uses the term "cast" to apply to implicit conversions as well as to 615actual cast expressions. 616 617hasDestinationType. 618 619Example: matches all five of the casts in 620 int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) 621but does not match the implicit conversion in 622 long ell = 42; 623</pre></td></tr> 624 625 626<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('expr0')"><a name="expr0Anchor">expr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>...</td></tr> 627<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions. 628 629Example matches x() 630 void f() { x(); } 631</pre></td></tr> 632 633 634<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('floatLiteral0')"><a name="floatLiteral0Anchor">floatLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>...</td></tr> 635<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes encodings, e.g. 6361.0, 1.0f, 1.0L and 1e10. 637 638Does not match implicit conversions such as 639 float a = 10; 640</pre></td></tr> 641 642 643<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forRangeStmt0')"><a name="forRangeStmt0Anchor">forRangeStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>>...</td></tr> 644<tr><td colspan="4" class="doc" id="forRangeStmt0"><pre>Matches range-based for statements. 645 646forRangeStmt() matches 'for (auto a : i)' 647 int i[] = {1, 2, 3}; for (auto a : i); 648 for(int j = 0; j < 5; ++j); 649</pre></td></tr> 650 651 652<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forStmt0')"><a name="forStmt0Anchor">forStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>>...</td></tr> 653<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements. 654 655Example matches 'for (;;) {}' 656 for (;;) {} 657 int i[] = {1, 2, 3}; for (auto a : i); 658</pre></td></tr> 659 660 661<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('functionalCastExpr0')"><a name="functionalCastExpr0Anchor">functionalCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>...</td></tr> 662<tr><td colspan="4" class="doc" id="functionalCastExpr0"><pre>Matches functional cast expressions 663 664Example: Matches Foo(bar); 665 Foo f = bar; 666 Foo g = (Foo) bar; 667 Foo h = Foo(bar); 668</pre></td></tr> 669 670 671<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('gotoStmt0')"><a name="gotoStmt0Anchor">gotoStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1GotoStmt.html">GotoStmt</a>>...</td></tr> 672<tr><td colspan="4" class="doc" id="gotoStmt0"><pre>Matches goto statements. 673 674Given 675 goto FOO; 676 FOO: bar(); 677gotoStmt() 678 matches 'goto FOO' 679</pre></td></tr> 680 681 682<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('ifStmt0')"><a name="ifStmt0Anchor">ifStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>>...</td></tr> 683<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements. 684 685Example matches 'if (x) {}' 686 if (x) {} 687</pre></td></tr> 688 689 690<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('implicitCastExpr0')"><a name="implicitCastExpr0Anchor">implicitCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>>...</td></tr> 691<tr><td colspan="4" class="doc" id="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST. 692 693This matches many different places, including function call return value 694eliding, as well as any type conversions. 695</pre></td></tr> 696 697 698<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('initListExpr0')"><a name="initListExpr0Anchor">initListExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>>...</td></tr> 699<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions. 700 701Given 702 int a[] = { 1, 2 }; 703 struct B { int x, y; }; 704 B b = { 5, 6 }; 705initList() 706 matches "{ 1, 2 }" and "{ 5, 6 }" 707</pre></td></tr> 708 709 710<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('integerLiteral0')"><a name="integerLiteral0Anchor">integerLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>...</td></tr> 711<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings, e.g. 7121, 1L, 0x1 and 1U. 713 714Does not match character-encoded integers such as L'a'. 715</pre></td></tr> 716 717 718<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('labelStmt0')"><a name="labelStmt0Anchor">labelStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>...</td></tr> 719<tr><td colspan="4" class="doc" id="labelStmt0"><pre>Matches label statements. 720 721Given 722 goto FOO; 723 FOO: bar(); 724labelStmt() 725 matches 'FOO:' 726</pre></td></tr> 727 728 729<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('lambdaExpr0')"><a name="lambdaExpr0Anchor">lambdaExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>>...</td></tr> 730<tr><td colspan="4" class="doc" id="lambdaExpr0"><pre>Matches lambda expressions. 731 732Example matches [&](){return 5;} 733 [&](){return 5;} 734</pre></td></tr> 735 736 737<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('materializeTemporaryExpr0')"><a name="materializeTemporaryExpr0Anchor">materializeTemporaryExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>>...</td></tr> 738<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized. 739 740Example: Given 741 struct T {void func()}; 742 T f(); 743 void g(T); 744materializeTemporaryExpr() matches 'f()' in these statements 745 T u(f()); 746 g(f()); 747but does not match 748 f(); 749 f().func(); 750</pre></td></tr> 751 752 753<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('memberCallExpr0')"><a name="memberCallExpr0Anchor">memberCallExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>>...</td></tr> 754<tr><td colspan="4" class="doc" id="memberCallExpr0"><pre>Matches member call expressions. 755 756Example matches x.y() 757 X x; 758 x.y(); 759</pre></td></tr> 760 761 762<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('memberExpr0')"><a name="memberExpr0Anchor">memberExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>...</td></tr> 763<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions. 764 765Given 766 class Y { 767 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 768 int a; static int b; 769 }; 770memberExpr() 771 matches this->x, x, y.x, a, this->b 772</pre></td></tr> 773 774 775<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('newExpr0')"><a name="newExpr0Anchor">newExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>...</td></tr> 776<tr><td colspan="4" class="doc" id="newExpr0"><pre>Matches new expressions. 777 778Given 779 new X; 780newExpr() 781 matches 'new X'. 782</pre></td></tr> 783 784 785<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('nullPtrLiteralExpr0')"><a name="nullPtrLiteralExpr0Anchor">nullPtrLiteralExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html">CXXNullPtrLiteralExpr</a>>...</td></tr> 786<tr><td colspan="4" class="doc" id="nullPtrLiteralExpr0"><pre>Matches nullptr literal. 787</pre></td></tr> 788 789 790<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('nullStmt0')"><a name="nullStmt0Anchor">nullStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NullStmt.html">NullStmt</a>>...</td></tr> 791<tr><td colspan="4" class="doc" id="nullStmt0"><pre>Matches null statements. 792 793 foo();; 794nullStmt() 795 matches the second ';' 796</pre></td></tr> 797 798 799<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('operatorCallExpr0')"><a name="operatorCallExpr0Anchor">operatorCallExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>...</td></tr> 800<tr><td colspan="4" class="doc" id="operatorCallExpr0"><pre>Matches overloaded operator calls. 801 802Note that if an operator isn't overloaded, it won't match. Instead, use 803binaryOperator matcher. 804Currently it does not match operators such as new delete. 805FIXME: figure out why these do not match? 806 807Example matches both operator<<((o << b), c) and operator<<(o, b) 808 (matcher = operatorCallExpr()) 809 ostream &operator<< (ostream &out, int i) { }; 810 ostream &o; int b = 1, c = 1; 811 o << b << c; 812</pre></td></tr> 813 814 815<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('reinterpretCastExpr0')"><a name="reinterpretCastExpr0Anchor">reinterpretCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>>...</td></tr> 816<tr><td colspan="4" class="doc" id="reinterpretCastExpr0"><pre>Matches a reinterpret_cast expression. 817 818Either the source expression or the destination type can be matched 819using has(), but hasDestinationType() is more specific and can be 820more readable. 821 822Example matches reinterpret_cast<char*>(&p) in 823 void* p = reinterpret_cast<char*>(&p); 824</pre></td></tr> 825 826 827<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('returnStmt0')"><a name="returnStmt0Anchor">returnStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>>...</td></tr> 828<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements. 829 830Given 831 return 1; 832returnStmt() 833 matches 'return 1' 834</pre></td></tr> 835 836 837<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('staticCastExpr0')"><a name="staticCastExpr0Anchor">staticCastExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>>...</td></tr> 838<tr><td colspan="4" class="doc" id="staticCastExpr0"><pre>Matches a C++ static_cast expression. 839 840hasDestinationType 841reinterpretCast 842 843Example: 844 staticCastExpr() 845matches 846 static_cast<long>(8) 847in 848 long eight(static_cast<long>(8)); 849</pre></td></tr> 850 851 852<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stmt0')"><a name="stmt0Anchor">stmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>...</td></tr> 853<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements. 854 855Given 856 { ++a; } 857stmt() 858 matches both the compound statement '{ ++a; }' and '++a'. 859</pre></td></tr> 860 861 862<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stringLiteral0')"><a name="stringLiteral0Anchor">stringLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>>...</td></tr> 863<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals). 864 865Example matches "abcd", L"abcd" 866 char *s = "abcd"; wchar_t *ws = L"abcd" 867</pre></td></tr> 868 869 870<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchCase0')"><a name="switchCase0Anchor">switchCase</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>>...</td></tr> 871<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements. 872 873Given 874 switch(a) { case 42: break; default: break; } 875switchCase() 876 matches 'case 42: break;' and 'default: break;'. 877</pre></td></tr> 878 879 880<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchStmt0')"><a name="switchStmt0Anchor">switchStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>>...</td></tr> 881<tr><td colspan="4" class="doc" id="switchStmt0"><pre>Matches switch statements. 882 883Given 884 switch(a) { case 42: break; default: break; } 885switchStmt() 886 matches 'switch(a)'. 887</pre></td></tr> 888 889 890<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('temporaryObjectExpr0')"><a name="temporaryObjectExpr0Anchor">temporaryObjectExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>...</td></tr> 891<tr><td colspan="4" class="doc" id="temporaryObjectExpr0"><pre>Matches functional cast expressions having N != 1 arguments 892 893Example: Matches Foo(bar, bar) 894 Foo h = Foo(bar, bar); 895</pre></td></tr> 896 897 898<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('thisExpr0')"><a name="thisExpr0Anchor">thisExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html">CXXThisExpr</a>>...</td></tr> 899<tr><td colspan="4" class="doc" id="thisExpr0"><pre>Matches implicit and explicit this expressions. 900 901Example matches the implicit this expression in "return i". 902 (matcher = thisExpr()) 903struct foo { 904 int i; 905 int f() { return i; } 906}; 907</pre></td></tr> 908 909 910<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('throwExpr0')"><a name="throwExpr0Anchor">throwExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXThrowExpr.html">CXXThrowExpr</a>>...</td></tr> 911<tr><td colspan="4" class="doc" id="throwExpr0"><pre>Matches throw expressions. 912 913 try { throw 5; } catch(int i) {} 914throwExpr() 915 matches 'throw 5' 916</pre></td></tr> 917 918 919<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('tryStmt0')"><a name="tryStmt0Anchor">tryStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html">CXXTryStmt</a>>...</td></tr> 920<tr><td colspan="4" class="doc" id="tryStmt0"><pre>Matches try statements. 921 922 try {} catch(int i) {} 923tryStmt() 924 matches 'try {}' 925</pre></td></tr> 926 927 928<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryExprOrTypeTraitExpr0')"><a name="unaryExprOrTypeTraitExpr0Anchor">unaryExprOrTypeTraitExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>>...</td></tr> 929<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) 930 931Given 932 Foo x = bar; 933 int y = sizeof(x) + alignof(x); 934unaryExprOrTypeTraitExpr() 935 matches sizeof(x) and alignof(x) 936</pre></td></tr> 937 938 939<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryOperator0')"><a name="unaryOperator0Anchor">unaryOperator</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>>...</td></tr> 940<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions. 941 942Example matches !a 943 !a || b 944</pre></td></tr> 945 946 947<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unresolvedConstructExpr0')"><a name="unresolvedConstructExpr0Anchor">unresolvedConstructExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>...</td></tr> 948<tr><td colspan="4" class="doc" id="unresolvedConstructExpr0"><pre>Matches unresolved constructor call expressions. 949 950Example matches T(t) in return statement of f 951 (matcher = unresolvedConstructExpr()) 952 template <typename T> 953 void f(const T& t) { return T(t); } 954</pre></td></tr> 955 956 957<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('userDefinedLiteral0')"><a name="userDefinedLiteral0Anchor">userDefinedLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UserDefinedLiteral.html">UserDefinedLiteral</a>>...</td></tr> 958<tr><td colspan="4" class="doc" id="userDefinedLiteral0"><pre>Matches user defined literal operator call. 959 960Example match: "foo"_suffix 961</pre></td></tr> 962 963 964<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('whileStmt0')"><a name="whileStmt0Anchor">whileStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>>...</td></tr> 965<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements. 966 967Given 968 while (true) {} 969whileStmt() 970 matches 'while (true) {}'. 971</pre></td></tr> 972 973 974<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('typeLoc0')"><a name="typeLoc0Anchor">typeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>...</td></tr> 975<tr><td colspan="4" class="doc" id="typeLoc0"><pre>Matches TypeLocs in the clang AST. 976</pre></td></tr> 977 978 979<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('arrayType0')"><a name="arrayType0Anchor">arrayType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>...</td></tr> 980<tr><td colspan="4" class="doc" id="arrayType0"><pre>Matches all kinds of arrays. 981 982Given 983 int a[] = { 2, 3 }; 984 int b[4]; 985 void f() { int c[a[0]]; } 986arrayType() 987 matches "int a[]", "int b[4]" and "int c[a[0]]"; 988</pre></td></tr> 989 990 991<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('atomicType0')"><a name="atomicType0Anchor">atomicType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>>...</td></tr> 992<tr><td colspan="4" class="doc" id="atomicType0"><pre>Matches atomic types. 993 994Given 995 _Atomic(int) i; 996atomicType() 997 matches "_Atomic(int) i" 998</pre></td></tr> 999 1000 1001<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('autoType0')"><a name="autoType0Anchor">autoType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>>...</td></tr> 1002<tr><td colspan="4" class="doc" id="autoType0"><pre>Matches types nodes representing C++11 auto types. 1003 1004Given: 1005 auto n = 4; 1006 int v[] = { 2, 3 } 1007 for (auto i : v) { } 1008autoType() 1009 matches "auto n" and "auto i" 1010</pre></td></tr> 1011 1012 1013<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('blockPointerType0')"><a name="blockPointerType0Anchor">blockPointerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>...</td></tr> 1014<tr><td colspan="4" class="doc" id="blockPointerType0"><pre>Matches block pointer types, i.e. types syntactically represented as 1015"void (^)(int)". 1016 1017The pointee is always required to be a FunctionType. 1018</pre></td></tr> 1019 1020 1021<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('builtinType0')"><a name="builtinType0Anchor">builtinType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BuiltinType.html">BuiltinType</a>>...</td></tr> 1022<tr><td colspan="4" class="doc" id="builtinType0"><pre>Matches builtin Types. 1023 1024Given 1025 struct A {}; 1026 A a; 1027 int b; 1028 float c; 1029 bool d; 1030builtinType() 1031 matches "int b", "float c" and "bool d" 1032</pre></td></tr> 1033 1034 1035<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('complexType0')"><a name="complexType0Anchor">complexType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>...</td></tr> 1036<tr><td colspan="4" class="doc" id="complexType0"><pre>Matches C99 complex types. 1037 1038Given 1039 _Complex float f; 1040complexType() 1041 matches "_Complex float f" 1042</pre></td></tr> 1043 1044 1045<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('constantArrayType0')"><a name="constantArrayType0Anchor">constantArrayType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>>...</td></tr> 1046<tr><td colspan="4" class="doc" id="constantArrayType0"><pre>Matches C arrays with a specified constant size. 1047 1048Given 1049 void() { 1050 int a[2]; 1051 int b[] = { 2, 3 }; 1052 int c[b[0]]; 1053 } 1054constantArrayType() 1055 matches "int a[2]" 1056</pre></td></tr> 1057 1058 1059<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('dependentSizedArrayType0')"><a name="dependentSizedArrayType0Anchor">dependentSizedArrayType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DependentSizedArrayType.html">DependentSizedArrayType</a>>...</td></tr> 1060<tr><td colspan="4" class="doc" id="dependentSizedArrayType0"><pre>Matches C++ arrays whose size is a value-dependent expression. 1061 1062Given 1063 template<typename T, int Size> 1064 class array { 1065 T data[Size]; 1066 }; 1067dependentSizedArrayType 1068 matches "T data[Size]" 1069</pre></td></tr> 1070 1071 1072<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('elaboratedType0')"><a name="elaboratedType0Anchor">elaboratedType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>>...</td></tr> 1073<tr><td colspan="4" class="doc" id="elaboratedType0"><pre>Matches types specified with an elaborated type keyword or with a 1074qualified name. 1075 1076Given 1077 namespace N { 1078 namespace M { 1079 class D {}; 1080 } 1081 } 1082 class C {}; 1083 1084 class C c; 1085 N::M::D d; 1086 1087elaboratedType() matches the type of the variable declarations of both 1088c and d. 1089</pre></td></tr> 1090 1091 1092<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('functionType0')"><a name="functionType0Anchor">functionType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html">FunctionType</a>>...</td></tr> 1093<tr><td colspan="4" class="doc" id="functionType0"><pre>Matches FunctionType nodes. 1094 1095Given 1096 int (*f)(int); 1097 void g(); 1098functionType() 1099 matches "int (*f)(int)" and the type of "g". 1100</pre></td></tr> 1101 1102 1103<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('incompleteArrayType0')"><a name="incompleteArrayType0Anchor">incompleteArrayType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IncompleteArrayType.html">IncompleteArrayType</a>>...</td></tr> 1104<tr><td colspan="4" class="doc" id="incompleteArrayType0"><pre>Matches C arrays with unspecified size. 1105 1106Given 1107 int a[] = { 2, 3 }; 1108 int b[42]; 1109 void f(int c[]) { int d[a[0]]; }; 1110incompleteArrayType() 1111 matches "int a[]" and "int c[]" 1112</pre></td></tr> 1113 1114 1115<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('lValueReferenceType0')"><a name="lValueReferenceType0Anchor">lValueReferenceType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LValueReferenceType.html">LValueReferenceType</a>>...</td></tr> 1116<tr><td colspan="4" class="doc" id="lValueReferenceType0"><pre>Matches lvalue reference types. 1117 1118Given: 1119 int *a; 1120 int &b = *a; 1121 int &&c = 1; 1122 auto &d = b; 1123 auto &&e = c; 1124 auto &&f = 2; 1125 int g = 5; 1126 1127lValueReferenceType() matches the types of b, d, and e. e is 1128matched since the type is deduced as int& by reference collapsing rules. 1129</pre></td></tr> 1130 1131 1132<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('memberPointerType0')"><a name="memberPointerType0Anchor">memberPointerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>...</td></tr> 1133<tr><td colspan="4" class="doc" id="memberPointerType0"><pre>Matches member pointer types. 1134Given 1135 struct A { int i; } 1136 A::* ptr = A::i; 1137memberPointerType() 1138 matches "A::* ptr" 1139</pre></td></tr> 1140 1141 1142<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('parenType0')"><a name="parenType0Anchor">parenType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>>...</td></tr> 1143<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType nodes. 1144 1145Given 1146 int (*ptr_to_array)[4]; 1147 int *array_of_ptrs[4]; 1148 1149varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not 1150array_of_ptrs. 1151</pre></td></tr> 1152 1153 1154<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('pointerType0')"><a name="pointerType0Anchor">pointerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>...</td></tr> 1155<tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer types. 1156 1157Given 1158 int *a; 1159 int &b = *a; 1160 int c = 5; 1161pointerType() 1162 matches "int *a" 1163</pre></td></tr> 1164 1165 1166<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('rValueReferenceType0')"><a name="rValueReferenceType0Anchor">rValueReferenceType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RValueReferenceType.html">RValueReferenceType</a>>...</td></tr> 1167<tr><td colspan="4" class="doc" id="rValueReferenceType0"><pre>Matches rvalue reference types. 1168 1169Given: 1170 int *a; 1171 int &b = *a; 1172 int &&c = 1; 1173 auto &d = b; 1174 auto &&e = c; 1175 auto &&f = 2; 1176 int g = 5; 1177 1178rValueReferenceType() matches the types of c and f. e is not 1179matched as it is deduced to int& by reference collapsing rules. 1180</pre></td></tr> 1181 1182 1183<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('recordType0')"><a name="recordType0Anchor">recordType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>...</td></tr> 1184<tr><td colspan="4" class="doc" id="recordType0"><pre>Matches record types (e.g. structs, classes). 1185 1186Given 1187 class C {}; 1188 struct S {}; 1189 1190 C c; 1191 S s; 1192 1193recordType() matches the type of the variable declarations of both c 1194and s. 1195</pre></td></tr> 1196 1197 1198<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('referenceType0')"><a name="referenceType0Anchor">referenceType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>...</td></tr> 1199<tr><td colspan="4" class="doc" id="referenceType0"><pre>Matches both lvalue and rvalue reference types. 1200 1201Given 1202 int *a; 1203 int &b = *a; 1204 int &&c = 1; 1205 auto &d = b; 1206 auto &&e = c; 1207 auto &&f = 2; 1208 int g = 5; 1209 1210referenceType() matches the types of b, c, d, e, and f. 1211</pre></td></tr> 1212 1213 1214<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('templateSpecializationType0')"><a name="templateSpecializationType0Anchor">templateSpecializationType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>...</td></tr> 1215<tr><td colspan="4" class="doc" id="templateSpecializationType0"><pre>Matches template specialization types. 1216 1217Given 1218 template <typename T> 1219 class C { }; 1220 1221 template class C<int>; A 1222 C<char> var; B 1223 1224templateSpecializationType() matches the type of the explicit 1225instantiation in A and the type of the variable declaration in B. 1226</pre></td></tr> 1227 1228 1229<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('type0')"><a name="type0Anchor">type</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>>...</td></tr> 1230<tr><td colspan="4" class="doc" id="type0"><pre>Matches Types in the clang AST. 1231</pre></td></tr> 1232 1233 1234<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('typedefType0')"><a name="typedefType0Anchor">typedefType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>...</td></tr> 1235<tr><td colspan="4" class="doc" id="typedefType0"><pre>Matches typedef types. 1236 1237Given 1238 typedef int X; 1239typedefType() 1240 matches "typedef int X" 1241</pre></td></tr> 1242 1243 1244<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('unaryTransformType0')"><a name="unaryTransformType0Anchor">unaryTransformType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryTransformType.html">UnaryTransformType</a>>...</td></tr> 1245<tr><td colspan="4" class="doc" id="unaryTransformType0"><pre>Matches types nodes representing unary type transformations. 1246 1247Given: 1248 typedef __underlying_type(T) type; 1249unaryTransformType() 1250 matches "__underlying_type(T)" 1251</pre></td></tr> 1252 1253 1254<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('variableArrayType0')"><a name="variableArrayType0Anchor">variableArrayType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>>...</td></tr> 1255<tr><td colspan="4" class="doc" id="variableArrayType0"><pre>Matches C arrays with a specified size that is not an 1256integer-constant-expression. 1257 1258Given 1259 void f() { 1260 int a[] = { 2, 3 } 1261 int b[42]; 1262 int c[a[0]]; 1263variableArrayType() 1264 matches "int c[a[0]]" 1265</pre></td></tr> 1266 1267<!--END_DECL_MATCHERS --> 1268</table> 1269 1270<!-- ======================================================================= --> 1271<h2 id="narrowing-matchers">Narrowing Matchers</h2> 1272<!-- ======================================================================= --> 1273 1274<p>Narrowing matchers match certain attributes on the current node, thus 1275narrowing down the set of nodes of the current type to match on.</p> 1276 1277<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless) 1278which allow users to create more powerful match expressions.</p> 1279 1280<table> 1281<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 1282<!-- START_NARROWING_MATCHERS --> 1283 1284<tr><td>Matcher<*></td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 1285<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match. 1286 1287Usable as: Any Matcher 1288</pre></td></tr> 1289 1290 1291<tr><td>Matcher<*></td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 1292<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches. 1293 1294Usable as: Any Matcher 1295</pre></td></tr> 1296 1297 1298<tr><td>Matcher<*></td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr> 1299<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node. 1300 1301Useful when another matcher requires a child matcher, but there's no 1302additional constraint. This will often be used with an explicit conversion 1303to an internal::Matcher<> type such as TypeMatcher. 1304 1305Example: DeclarationMatcher(anything()) matches all declarations, e.g., 1306"int* p" and "void f()" in 1307 int* p; 1308 void f(); 1309 1310Usable as: Any Matcher 1311</pre></td></tr> 1312 1313 1314<tr><td>Matcher<*></td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher<*></td></tr> 1315<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match. 1316 1317Example matches Y (matcher = recordDecl(unless(hasName("X")))) 1318 class X {}; 1319 class Y {}; 1320 1321Usable as: Any Matcher 1322</pre></td></tr> 1323 1324 1325<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName0')"><a name="hasOperatorName0Anchor">hasOperatorName</a></td><td>std::string Name</td></tr> 1326<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or 1327unary). 1328 1329Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 1330 !(a || b) 1331</pre></td></tr> 1332 1333 1334<tr><td>Matcher<CXXBoolLiteral></td><td class="name" onclick="toggle('equals2')"><a name="equals2Anchor">equals</a></td><td>ValueT Value</td></tr> 1335<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value. 1336 1337Example matches true (matcher = boolLiteral(equals(true))) 1338 true 1339 1340Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 1341 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 1342</pre></td></tr> 1343 1344 1345<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountIs1')"><a name="argumentCountIs1Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 1346<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has 1347a specific number of arguments (including absent default arguments). 1348 1349Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 1350 void f(int x, int y); 1351 f(0, 0); 1352</pre></td></tr> 1353 1354 1355<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('isListInitialization0')"><a name="isListInitialization0Anchor">isListInitialization</a></td><td></td></tr> 1356<tr><td colspan="4" class="doc" id="isListInitialization0"><pre>Matches a constructor call expression which uses list initialization. 1357</pre></td></tr> 1358 1359 1360<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isImplicit0')"><a name="isImplicit0Anchor">isImplicit</a></td><td></td></tr> 1361<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a constructor declaration that has been implicitly added 1362by the compiler (eg. implicit defaultcopy constructors). 1363</pre></td></tr> 1364 1365 1366<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isWritten0')"><a name="isWritten0Anchor">isWritten</a></td><td></td></tr> 1367<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in 1368code (as opposed to implicitly added by the compiler). 1369 1370Given 1371 struct Foo { 1372 Foo() { } 1373 Foo(int) : foo_("A") { } 1374 string foo_; 1375 }; 1376constructorDecl(hasAnyConstructorInitializer(isWritten())) 1377 will match Foo(int), but not Foo() 1378</pre></td></tr> 1379 1380 1381<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName0')"><a name="hasOverloadedOperatorName0Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr> 1382<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names. 1383 1384Matches overloaded operator names specified in strings without the 1385"operator" prefix: e.g. "<<". 1386 1387Given: 1388 class A { int operator*(); }; 1389 const A &operator<<(const A &a, const A &b); 1390 A a; 1391 a << a; <-- This matches 1392 1393operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified 1394line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches 1395the declaration of A. 1396 1397Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> 1398</pre></td></tr> 1399 1400 1401<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isConst0')"><a name="isConst0Anchor">isConst</a></td><td></td></tr> 1402<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const. 1403 1404Given 1405struct A { 1406 void foo() const; 1407 void bar(); 1408}; 1409 1410methodDecl(isConst()) matches A::foo() but not A::bar() 1411</pre></td></tr> 1412 1413 1414<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isOverride0')"><a name="isOverride0Anchor">isOverride</a></td><td></td></tr> 1415<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method. 1416 1417Given 1418 class A { 1419 public: 1420 virtual void x(); 1421 }; 1422 class B : public A { 1423 public: 1424 virtual void x(); 1425 }; 1426 matches B::x 1427</pre></td></tr> 1428 1429 1430<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isPure0')"><a name="isPure0Anchor">isPure</a></td><td></td></tr> 1431<tr><td colspan="4" class="doc" id="isPure0"><pre>Matches if the given method declaration is pure. 1432 1433Given 1434 class A { 1435 public: 1436 virtual void x() = 0; 1437 }; 1438 matches A::x 1439</pre></td></tr> 1440 1441 1442<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isVirtual0')"><a name="isVirtual0Anchor">isVirtual</a></td><td></td></tr> 1443<tr><td colspan="4" class="doc" id="isVirtual0"><pre>Matches if the given method declaration is virtual. 1444 1445Given 1446 class A { 1447 public: 1448 virtual void x(); 1449 }; 1450 matches A::x 1451</pre></td></tr> 1452 1453 1454<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName1')"><a name="hasOverloadedOperatorName1Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr> 1455<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName1"><pre>Matches overloaded operator names. 1456 1457Matches overloaded operator names specified in strings without the 1458"operator" prefix: e.g. "<<". 1459 1460Given: 1461 class A { int operator*(); }; 1462 const A &operator<<(const A &a, const A &b); 1463 A a; 1464 a << a; <-- This matches 1465 1466operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified 1467line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches 1468the declaration of A. 1469 1470Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> 1471</pre></td></tr> 1472 1473 1474<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>StringRef BaseName</td></tr> 1475<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). 1476</pre></td></tr> 1477 1478 1479<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization2')"><a name="isExplicitTemplateSpecialization2Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr> 1480<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or 1481static member variable template instantiations. 1482 1483Given 1484 template<typename T> void A(T t) { } 1485 template<> void A(int N) { } 1486functionDecl(isExplicitTemplateSpecialization()) 1487 matches the specialization A<int>(). 1488 1489Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 1490</pre></td></tr> 1491 1492 1493<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>StringRef BaseName</td></tr> 1494<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Overloaded method as shortcut for 1495isSameOrDerivedFrom(hasName(...)). 1496</pre></td></tr> 1497 1498 1499<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation2')"><a name="isTemplateInstantiation2Anchor">isTemplateInstantiation</a></td><td></td></tr> 1500<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static 1501member variable template instantiations. 1502 1503Given 1504 template <typename T> class X {}; class A {}; X<A> x; 1505or 1506 template <typename T> class X {}; class A {}; template class X<A>; 1507recordDecl(hasName("::X"), isTemplateInstantiation()) 1508 matches the template instantiation of X<A>. 1509 1510But given 1511 template <typename T> class X {}; class A {}; 1512 template <> class X<A> {}; X<A> x; 1513recordDecl(hasName("::X"), isTemplateInstantiation()) 1514 does not match, as X<A> is an explicit template specialization. 1515 1516Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 1517</pre></td></tr> 1518 1519 1520<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('argumentCountIs0')"><a name="argumentCountIs0Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 1521<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has 1522a specific number of arguments (including absent default arguments). 1523 1524Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 1525 void f(int x, int y); 1526 f(0, 0); 1527</pre></td></tr> 1528 1529 1530<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals3')"><a name="equals3Anchor">equals</a></td><td>ValueT Value</td></tr> 1531<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value. 1532 1533Example matches true (matcher = boolLiteral(equals(true))) 1534 true 1535 1536Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 1537 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 1538</pre></td></tr> 1539 1540 1541<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>></td><td class="name" onclick="toggle('statementCountIs0')"><a name="statementCountIs0Anchor">statementCountIs</a></td><td>unsigned N</td></tr> 1542<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of 1543child statements. 1544 1545Example: Given 1546 { for (;;) {} } 1547compoundStmt(statementCountIs(0))) 1548 matches '{}' 1549 but does not match the outer compound statement. 1550</pre></td></tr> 1551 1552 1553<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>></td><td class="name" onclick="toggle('hasSize0')"><a name="hasSize0Anchor">hasSize</a></td><td>unsigned N</td></tr> 1554<tr><td colspan="4" class="doc" id="hasSize0"><pre>Matches ConstantArrayType nodes that have the specified size. 1555 1556Given 1557 int a[42]; 1558 int b[2 * 21]; 1559 int c[41], d[43]; 1560constantArrayType(hasSize(42)) 1561 matches "int a[42]" and "int b[2 * 21]" 1562</pre></td></tr> 1563 1564 1565<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('declCountIs0')"><a name="declCountIs0Anchor">declCountIs</a></td><td>unsigned N</td></tr> 1566<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of 1567declarations. 1568 1569Example: Given 1570 int a, b; 1571 int c; 1572 int d = 2, e; 1573declCountIs(2) 1574 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. 1575</pre></td></tr> 1576 1577 1578<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsBoundNode1')"><a name="equalsBoundNode1Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 1579<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node. 1580 1581Matches a node if it equals the node previously bound to ID. 1582 1583Given 1584 class X { int a; int b; }; 1585recordDecl( 1586 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 1587 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 1588 matches the class X, as a and b have the same type. 1589 1590Note that when multiple matches are involved via forEach* matchers, 1591equalsBoundNodes acts as a filter. 1592For example: 1593compoundStmt( 1594 forEachDescendant(varDecl().bind("d")), 1595 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 1596will trigger a match for each combination of variable declaration 1597and reference to that variable declaration within a compound statement. 1598</pre></td></tr> 1599 1600 1601<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsNode0')"><a name="equalsNode0Anchor">equalsNode</a></td><td>Decl* Other</td></tr> 1602<tr><td colspan="4" class="doc" id="equalsNode0"><pre>Matches if a node equals another node. 1603 1604Decl has pointer identity in the AST. 1605</pre></td></tr> 1606 1607 1608<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPrivate0')"><a name="isPrivate0Anchor">isPrivate</a></td><td></td></tr> 1609<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations. 1610 1611Given 1612 class C { 1613 public: int a; 1614 protected: int b; 1615 private: int c; 1616 }; 1617fieldDecl(isPrivate()) 1618 matches 'int c;' 1619</pre></td></tr> 1620 1621 1622<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isProtected0')"><a name="isProtected0Anchor">isProtected</a></td><td></td></tr> 1623<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations. 1624 1625Given 1626 class C { 1627 public: int a; 1628 protected: int b; 1629 private: int c; 1630 }; 1631fieldDecl(isProtected()) 1632 matches 'int b;' 1633</pre></td></tr> 1634 1635 1636<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPublic0')"><a name="isPublic0Anchor">isPublic</a></td><td></td></tr> 1637<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations. 1638 1639Given 1640 class C { 1641 public: int a; 1642 protected: int b; 1643 private: int c; 1644 }; 1645fieldDecl(isPublic()) 1646 matches 'int a;' 1647</pre></td></tr> 1648 1649 1650<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals1')"><a name="equals1Anchor">equals</a></td><td>ValueT Value</td></tr> 1651<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value. 1652 1653Example matches true (matcher = boolLiteral(equals(true))) 1654 true 1655 1656Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 1657 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 1658</pre></td></tr> 1659 1660 1661<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefinition2')"><a name="isDefinition2Anchor">isDefinition</a></td><td></td></tr> 1662<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached. 1663 1664Example matches A, va, fa 1665 class A {}; 1666 class B; Doesn't match, as it has no body. 1667 int va; 1668 extern int vb; Doesn't match, as it doesn't define the variable. 1669 void fa() {} 1670 void fb(); Doesn't match, as it has no body. 1671 1672Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 1673</pre></td></tr> 1674 1675 1676<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization0')"><a name="isExplicitTemplateSpecialization0Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr> 1677<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or 1678static member variable template instantiations. 1679 1680Given 1681 template<typename T> void A(T t) { } 1682 template<> void A(int N) { } 1683functionDecl(isExplicitTemplateSpecialization()) 1684 matches the specialization A<int>(). 1685 1686Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 1687</pre></td></tr> 1688 1689 1690<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExternC0')"><a name="isExternC0Anchor">isExternC</a></td><td></td></tr> 1691<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function declarations. 1692 1693Given: 1694 extern "C" void f() {} 1695 extern "C" { void g() {} } 1696 void h() {} 1697functionDecl(isExternC()) 1698 matches the declaration of f and g, but not the declaration h 1699</pre></td></tr> 1700 1701 1702<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation0')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr> 1703<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static 1704member variable template instantiations. 1705 1706Given 1707 template <typename T> class X {}; class A {}; X<A> x; 1708or 1709 template <typename T> class X {}; class A {}; template class X<A>; 1710recordDecl(hasName("::X"), isTemplateInstantiation()) 1711 matches the template instantiation of X<A>. 1712 1713But given 1714 template <typename T> class X {}; class A {}; 1715 template <> class X<A> {}; X<A> x; 1716recordDecl(hasName("::X"), isTemplateInstantiation()) 1717 does not match, as X<A> is an explicit template specialization. 1718 1719Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 1720</pre></td></tr> 1721 1722 1723<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr> 1724<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls that have a specific parameter count. 1725 1726Given 1727 void f(int i) {} 1728 void g(int i, int j) {} 1729functionDecl(parameterCountIs(2)) 1730 matches g(int i, int j) {} 1731</pre></td></tr> 1732 1733 1734<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals0')"><a name="equals0Anchor">equals</a></td><td>ValueT Value</td></tr> 1735<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value. 1736 1737Example matches true (matcher = boolLiteral(equals(true))) 1738 true 1739 1740Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 1741 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 1742</pre></td></tr> 1743 1744 1745<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('isArrow0')"><a name="isArrow0Anchor">isArrow</a></td><td></td></tr> 1746<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed 1747to '.'. 1748 1749Member calls on the implicit this pointer match as called with '->'. 1750 1751Given 1752 class Y { 1753 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 1754 int a; 1755 static int b; 1756 }; 1757memberExpr(isArrow()) 1758 matches this->x, x, y.x, a, this->b 1759</pre></td></tr> 1760 1761 1762<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr> 1763<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. 1764 1765Supports specifying enclosing namespaces or classes by prefixing the name 1766with '<enclosing>::'. 1767Does not match typedefs of an underlying type with the given name. 1768 1769Example matches X (Name == "X") 1770 class X; 1771 1772Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") 1773 namespace a { namespace b { class X; } } 1774</pre></td></tr> 1775 1776 1777<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('matchesName0')"><a name="matchesName0Anchor">matchesName</a></td><td>std::string RegExp</td></tr> 1778<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain 1779a substring matched by the given RegExp. 1780 1781Supports specifying enclosing namespaces or classes by 1782prefixing the name with '<enclosing>::'. Does not match typedefs 1783of an underlying type with the given name. 1784 1785Example matches X (regexp == "::X") 1786 class X; 1787 1788Example matches X (regexp is one of "::X", "^foo::.*X", among others) 1789 namespace foo { namespace bar { class X; } } 1790</pre></td></tr> 1791 1792 1793<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('asString0')"><a name="asString0Anchor">asString</a></td><td>std::string Name</td></tr> 1794<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string. 1795 1796Given 1797 class Y { public: void x(); }; 1798 void z() { Y* y; y->x(); } 1799callExpr(on(hasType(asString("class Y *")))) 1800 matches y->x() 1801</pre></td></tr> 1802 1803 1804<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('equalsBoundNode3')"><a name="equalsBoundNode3Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 1805<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node. 1806 1807Matches a node if it equals the node previously bound to ID. 1808 1809Given 1810 class X { int a; int b; }; 1811recordDecl( 1812 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 1813 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 1814 matches the class X, as a and b have the same type. 1815 1816Note that when multiple matches are involved via forEach* matchers, 1817equalsBoundNodes acts as a filter. 1818For example: 1819compoundStmt( 1820 forEachDescendant(varDecl().bind("d")), 1821 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 1822will trigger a match for each combination of variable declaration 1823and reference to that variable declaration within a compound statement. 1824</pre></td></tr> 1825 1826 1827<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasLocalQualifiers0')"><a name="hasLocalQualifiers0Anchor">hasLocalQualifiers</a></td><td></td></tr> 1828<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to 1829the node, not hidden within a typedef. 1830 1831Given 1832 typedef const int const_int; 1833 const_int i; 1834 int *const j; 1835 int *volatile k; 1836 int m; 1837varDecl(hasType(hasLocalQualifiers())) matches only j and k. 1838i is const-qualified but the qualifier is not local. 1839</pre></td></tr> 1840 1841 1842<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isConstQualified0')"><a name="isConstQualified0Anchor">isConstQualified</a></td><td></td></tr> 1843<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that 1844include "top-level" const. 1845 1846Given 1847 void a(int); 1848 void b(int const); 1849 void c(const int); 1850 void d(const int*); 1851 void e(int const) {}; 1852functionDecl(hasAnyParameter(hasType(isConstQualified()))) 1853 matches "void b(int const)", "void c(const int)" and 1854 "void e(int const) {}". It does not match d as there 1855 is no top-level const on the parameter type "const int *". 1856</pre></td></tr> 1857 1858 1859<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isInteger0')"><a name="isInteger0Anchor">isInteger</a></td><td></td></tr> 1860<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type. 1861 1862Given 1863 void a(int); 1864 void b(long); 1865 void c(double); 1866functionDecl(hasAnyParameter(hasType(isInteger()))) 1867matches "a(int)", "b(long)", but not "c(double)". 1868</pre></td></tr> 1869 1870 1871<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('equalsBoundNode0')"><a name="equalsBoundNode0Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 1872<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node. 1873 1874Matches a node if it equals the node previously bound to ID. 1875 1876Given 1877 class X { int a; int b; }; 1878recordDecl( 1879 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 1880 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 1881 matches the class X, as a and b have the same type. 1882 1883Note that when multiple matches are involved via forEach* matchers, 1884equalsBoundNodes acts as a filter. 1885For example: 1886compoundStmt( 1887 forEachDescendant(varDecl().bind("d")), 1888 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 1889will trigger a match for each combination of variable declaration 1890and reference to that variable declaration within a compound statement. 1891</pre></td></tr> 1892 1893 1894<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('equalsNode1')"><a name="equalsNode1Anchor">equalsNode</a></td><td>Stmt* Other</td></tr> 1895<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node. 1896 1897Stmt has pointer identity in the AST. 1898 1899</pre></td></tr> 1900 1901 1902<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isDefinition0')"><a name="isDefinition0Anchor">isDefinition</a></td><td></td></tr> 1903<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached. 1904 1905Example matches A, va, fa 1906 class A {}; 1907 class B; Doesn't match, as it has no body. 1908 int va; 1909 extern int vb; Doesn't match, as it doesn't define the variable. 1910 void fa() {} 1911 void fb(); Doesn't match, as it has no body. 1912 1913Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 1914</pre></td></tr> 1915 1916 1917<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('equalsBoundNode2')"><a name="equalsBoundNode2Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 1918<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node. 1919 1920Matches a node if it equals the node previously bound to ID. 1921 1922Given 1923 class X { int a; int b; }; 1924recordDecl( 1925 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 1926 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 1927 matches the class X, as a and b have the same type. 1928 1929Note that when multiple matches are involved via forEach* matchers, 1930equalsBoundNodes acts as a filter. 1931For example: 1932compoundStmt( 1933 forEachDescendant(varDecl().bind("d")), 1934 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 1935will trigger a match for each combination of variable declaration 1936and reference to that variable declaration within a compound statement. 1937</pre></td></tr> 1938 1939 1940<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>></td><td class="name" onclick="toggle('ofKind0')"><a name="ofKind0Anchor">ofKind</a></td><td>UnaryExprOrTypeTrait Kind</td></tr> 1941<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind. 1942 1943Given 1944 int x; 1945 int s = sizeof(x) + alignof(x) 1946unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) 1947 matches sizeof(x) 1948</pre></td></tr> 1949 1950 1951<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName1')"><a name="hasOperatorName1Anchor">hasOperatorName</a></td><td>std::string Name</td></tr> 1952<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or 1953unary). 1954 1955Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 1956 !(a || b) 1957</pre></td></tr> 1958 1959 1960<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isDefinition1')"><a name="isDefinition1Anchor">isDefinition</a></td><td></td></tr> 1961<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached. 1962 1963Example matches A, va, fa 1964 class A {}; 1965 class B; Doesn't match, as it has no body. 1966 int va; 1967 extern int vb; Doesn't match, as it doesn't define the variable. 1968 void fa() {} 1969 void fb(); Doesn't match, as it has no body. 1970 1971Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 1972</pre></td></tr> 1973 1974 1975<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization1')"><a name="isExplicitTemplateSpecialization1Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr> 1976<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or 1977static member variable template instantiations. 1978 1979Given 1980 template<typename T> void A(T t) { } 1981 template<> void A(int N) { } 1982functionDecl(isExplicitTemplateSpecialization()) 1983 matches the specialization A<int>(). 1984 1985Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 1986</pre></td></tr> 1987 1988 1989<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation1')"><a name="isTemplateInstantiation1Anchor">isTemplateInstantiation</a></td><td></td></tr> 1990<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static 1991member variable template instantiations. 1992 1993Given 1994 template <typename T> class X {}; class A {}; X<A> x; 1995or 1996 template <typename T> class X {}; class A {}; template class X<A>; 1997recordDecl(hasName("::X"), isTemplateInstantiation()) 1998 matches the template instantiation of X<A>. 1999 2000But given 2001 template <typename T> class X {}; class A {}; 2002 template <> class X<A> {}; X<A> x; 2003recordDecl(hasName("::X"), isTemplateInstantiation()) 2004 does not match, as X<A> is an explicit template specialization. 2005 2006Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2007</pre></td></tr> 2008 2009<!--END_NARROWING_MATCHERS --> 2010</table> 2011 2012<!-- ======================================================================= --> 2013<h2 id="traversal-matchers">AST Traversal Matchers</h2> 2014<!-- ======================================================================= --> 2015 2016<p>Traversal matchers specify the relationship to other nodes that are 2017reachable from the current node.</p> 2018 2019<p>Note that there are special traversal matchers (has, hasDescendant, forEach and 2020forEachDescendant) which work on all nodes and allow users to write more generic 2021match expressions.</p> 2022 2023<table> 2024<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 2025<!-- START_TRAVERSAL_MATCHERS --> 2026 2027<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 2028<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches. 2029 2030Unlike anyOf, eachOf will generate a match result for each 2031matching submatcher. 2032 2033For example, in: 2034 class A { int a; int b; }; 2035The matcher: 2036 recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), 2037 has(fieldDecl(hasName("b")).bind("v")))) 2038will generate two results binding "v", the first of which binds 2039the field declaration of a, the second the field declaration of 2040b. 2041 2042Usable as: Any Matcher 2043</pre></td></tr> 2044 2045 2046<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr> 2047<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 2048provided matcher. 2049 2050Example matches X, A, B, C 2051 (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X"))))) 2052 class X {}; Matches X, because X::X is a class of name X inside X. 2053 class A { class X {}; }; 2054 class B { class C { class X {}; }; }; 2055 2056DescendantT must be an AST base type. 2057 2058As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for 2059each result that matches instead of only on the first one. 2060 2061Note: Recursively combined ForEachDescendant can cause many matches: 2062 recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl())))) 2063will match 10 times (plus injected class name matches) on: 2064 class A { class B { class C { class D { class E {}; }; }; }; }; 2065 2066Usable as: Any Matcher 2067</pre></td></tr> 2068 2069 2070<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr> 2071<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the 2072provided matcher. 2073 2074Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X"))) 2075 class X {}; Matches X, because X::X is a class of name X inside X. 2076 class Y { class X {}; }; 2077 class Z { class Y { class X {}; }; }; Does not match Z. 2078 2079ChildT must be an AST base type. 2080 2081As opposed to 'has', 'forEach' will cause a match for each result that 2082matches instead of only on the first one. 2083 2084Usable as: Any Matcher 2085</pre></td></tr> 2086 2087 2088<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr> 2089<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided 2090matcher. 2091 2092Given 2093void f() { if (true) { int x = 42; } } 2094void g() { for (;;) { int x = 43; } } 2095expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. 2096 2097Usable as: Any Matcher 2098</pre></td></tr> 2099 2100 2101<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr> 2102<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 2103provided matcher. 2104 2105Example matches X, Y, Z 2106 (matcher = recordDecl(hasDescendant(recordDecl(hasName("X"))))) 2107 class X {}; Matches X, because X::X is a class of name X inside X. 2108 class Y { class X {}; }; 2109 class Z { class Y { class X {}; }; }; 2110 2111DescendantT must be an AST base type. 2112 2113Usable as: Any Matcher 2114</pre></td></tr> 2115 2116 2117<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr> 2118<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the 2119provided matcher. 2120 2121Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X"))) 2122 class X {}; Matches X, because X::X is a class of name X inside X. 2123 class Y { class X {}; }; 2124 class Z { class Y { class X {}; }; }; Does not match Z. 2125 2126ChildT must be an AST base type. 2127 2128Usable as: Any Matcher 2129</pre></td></tr> 2130 2131 2132<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr> 2133<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided 2134matcher. 2135 2136Given 2137void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } 2138compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". 2139 2140Usable as: Any Matcher 2141</pre></td></tr> 2142 2143 2144<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasBase0')"><a name="hasBase0Anchor">hasBase</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2145<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression. 2146 2147Given 2148 int i[5]; 2149 void f() { i[1] = 42; } 2150arraySubscriptExpression(hasBase(implicitCastExpr( 2151 hasSourceExpression(declRefExpr())))) 2152 matches i[1] with the declRefExpr() matching i 2153</pre></td></tr> 2154 2155 2156<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasIndex0')"><a name="hasIndex0Anchor">hasIndex</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2157<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression. 2158 2159Given 2160 int i[5]; 2161 void f() { i[1] = 42; } 2162arraySubscriptExpression(hasIndex(integerLiteral())) 2163 matches i[1] with the integerLiteral() matching 1 2164</pre></td></tr> 2165 2166 2167<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayTypeLoc.html">ArrayTypeLoc</a>></td><td class="name" onclick="toggle('hasElementTypeLoc0')"><a name="hasElementTypeLoc0Anchor">hasElementTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 2168<tr><td colspan="4" class="doc" id="hasElementTypeLoc0"><pre>Matches arrays and C99 complex types that have a specific element 2169type. 2170 2171Given 2172 struct A {}; 2173 A a[7]; 2174 int b[7]; 2175arrayType(hasElementType(builtinType())) 2176 matches "int b[7]" 2177 2178Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 2179</pre></td></tr> 2180 2181 2182<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>></td><td class="name" onclick="toggle('hasElementType0')"><a name="hasElementType0Anchor">hasElementType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 2183<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element 2184type. 2185 2186Given 2187 struct A {}; 2188 A a[7]; 2189 int b[7]; 2190arrayType(hasElementType(builtinType())) 2191 matches "int b[7]" 2192 2193Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 2194</pre></td></tr> 2195 2196 2197<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicTypeLoc.html">AtomicTypeLoc</a>></td><td class="name" onclick="toggle('hasValueTypeLoc0')"><a name="hasValueTypeLoc0Anchor">hasValueTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 2198<tr><td colspan="4" class="doc" id="hasValueTypeLoc0"><pre>Matches atomic types with a specific value type. 2199 2200Given 2201 _Atomic(int) i; 2202 _Atomic(float) f; 2203atomicType(hasValueType(isInteger())) 2204 matches "_Atomic(int) i" 2205 2206Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 2207</pre></td></tr> 2208 2209 2210<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>></td><td class="name" onclick="toggle('hasValueType0')"><a name="hasValueType0Anchor">hasValueType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 2211<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type. 2212 2213Given 2214 _Atomic(int) i; 2215 _Atomic(float) f; 2216atomicType(hasValueType(isInteger())) 2217 matches "_Atomic(int) i" 2218 2219Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 2220</pre></td></tr> 2221 2222 2223<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>></td><td class="name" onclick="toggle('hasDeducedType0')"><a name="hasDeducedType0Anchor">hasDeducedType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 2224<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type. 2225 2226Note: There is no TypeLoc for the deduced type and thus no 2227getDeducedLoc() matcher. 2228 2229Given 2230 auto a = 1; 2231 auto b = 2.0; 2232autoType(hasDeducedType(isInteger())) 2233 matches "auto a" 2234 2235Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>> 2236</pre></td></tr> 2237 2238 2239<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasEitherOperand0')"><a name="hasEitherOperand0Anchor">hasEitherOperand</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2240<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a 2241binary operator matches. 2242</pre></td></tr> 2243 2244 2245<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasLHS0')"><a name="hasLHS0Anchor">hasLHS</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2246<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions. 2247 2248Example matches a (matcher = binaryOperator(hasLHS())) 2249 a || b 2250</pre></td></tr> 2251 2252 2253<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasRHS0')"><a name="hasRHS0Anchor">hasRHS</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2254<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions. 2255 2256Example matches b (matcher = binaryOperator(hasRHS())) 2257 a || b 2258</pre></td></tr> 2259 2260 2261<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerTypeLoc.html">BlockPointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc0')"><a name="pointeeLoc0Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 2262<tr><td colspan="4" class="doc" id="pointeeLoc0"><pre>Narrows PointerType (and similar) matchers to those where the 2263pointee matches a given matcher. 2264 2265Given 2266 int *a; 2267 int const *b; 2268 float const *f; 2269pointerType(pointee(isConstQualified(), isInteger())) 2270 matches "int const *b" 2271 2272Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 2273 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 2274</pre></td></tr> 2275 2276 2277<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>></td><td class="name" onclick="toggle('pointee0')"><a name="pointee0Anchor">pointee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 2278<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the 2279pointee matches a given matcher. 2280 2281Given 2282 int *a; 2283 int const *b; 2284 float const *f; 2285pointerType(pointee(isConstQualified(), isInteger())) 2286 matches "int const *b" 2287 2288Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 2289 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 2290</pre></td></tr> 2291 2292 2293<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument1')"><a name="hasAnyArgument1Anchor">hasAnyArgument</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2294<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call 2295expression. 2296 2297Given 2298 void x(int, int, int) { int y; x(1, y, 42); } 2299callExpr(hasAnyArgument(declRefExpr())) 2300 matches x(1, y, 42) 2301with hasAnyArgument(...) 2302 matching y 2303 2304FIXME: Currently this will ignore parentheses and implicit casts on 2305the argument before applying the inner matcher. We'll want to remove 2306this to allow for greater control by the user once ignoreImplicit() 2307has been implemented. 2308</pre></td></tr> 2309 2310 2311<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasArgument1')"><a name="hasArgument1Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2312<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor 2313call expression. 2314 2315Example matches y in x(y) 2316 (matcher = callExpr(hasArgument(0, declRefExpr()))) 2317 void x(int) { int y; x(y); } 2318</pre></td></tr> 2319 2320 2321<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasDeclaration12')"><a name="hasDeclaration12Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2322<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node 2323matches the given matcher. 2324 2325The associated declaration is: 2326- for type nodes, the declaration of the underlying type 2327- for CallExpr, the declaration of the callee 2328- for MemberExpr, the declaration of the referenced member 2329- for CXXConstructExpr, the declaration of the constructor 2330 2331Also usable as Matcher<T> for any T supporting the getDecl() member 2332function. e.g. various subtypes of clang::Type and various expressions. 2333 2334Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 2335 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 2336 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 2337 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 2338 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 2339 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 2340</pre></td></tr> 2341 2342 2343<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('forEachConstructorInitializer0')"><a name="forEachConstructorInitializer0Anchor">forEachConstructorInitializer</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr> 2344<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition. 2345 2346Given 2347 class A { A() : i(42), j(42) {} int i; int j; }; 2348constructorDecl(forEachConstructorInitializer(forField(decl().bind("x")))) 2349 will trigger two matches, binding for 'i' and 'j' respectively. 2350</pre></td></tr> 2351 2352 2353<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('hasAnyConstructorInitializer0')"><a name="hasAnyConstructorInitializer0Anchor">hasAnyConstructorInitializer</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr> 2354<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer. 2355 2356Given 2357 struct Foo { 2358 Foo() : foo_(1) { } 2359 int foo_; 2360 }; 2361recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything())))) 2362 record matches Foo, hasAnyConstructorInitializer matches foo_(1) 2363</pre></td></tr> 2364 2365 2366<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('forField0')"><a name="forField0Anchor">forField</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>> InnerMatcher</td></tr> 2367<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer. 2368 2369Given 2370 struct Foo { 2371 Foo() : foo_(1) { } 2372 int foo_; 2373 }; 2374recordDecl(has(constructorDecl(hasAnyConstructorInitializer( 2375 forField(hasName("foo_")))))) 2376 matches Foo 2377with forField matching foo_ 2378</pre></td></tr> 2379 2380 2381<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('withInitializer0')"><a name="withInitializer0Anchor">withInitializer</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2382<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer. 2383 2384Given 2385 struct Foo { 2386 Foo() : foo_(1) { } 2387 int foo_; 2388 }; 2389recordDecl(has(constructorDecl(hasAnyConstructorInitializer( 2390 withInitializer(integerLiteral(equals(1))))))) 2391 matches Foo 2392with withInitializer matching (1) 2393</pre></td></tr> 2394 2395 2396<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>></td><td class="name" onclick="toggle('hasLoopVariable0')"><a name="hasLoopVariable0Anchor">hasLoopVariable</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>> InnerMatcher</td></tr> 2397<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop. 2398 2399Example: 2400 forStmt(hasLoopVariable(anything())) 2401matches 'int x' in 2402 for (int x : a) { } 2403</pre></td></tr> 2404 2405 2406<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('onImplicitObjectArgument0')"><a name="onImplicitObjectArgument0Anchor">onImplicitObjectArgument</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2407<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre></pre></td></tr> 2408 2409 2410<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('on0')"><a name="on0Anchor">on</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2411<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression. 2412 2413Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y")))))) 2414 class Y { public: void x(); }; 2415 void z() { Y y; y.x(); }", 2416 2417FIXME: Overload to allow directly matching types? 2418</pre></td></tr> 2419 2420 2421<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('thisPointerType1')"><a name="thisPointerType1Anchor">thisPointerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2422<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration. 2423</pre></td></tr> 2424 2425 2426<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('thisPointerType0')"><a name="thisPointerType0Anchor">thisPointerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 2427<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the expression's type either matches the specified 2428matcher, or is a pointer to a type that matches the InnerMatcher. 2429</pre></td></tr> 2430 2431 2432<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('ofClass0')"><a name="ofClass0Anchor">ofClass</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> InnerMatcher</td></tr> 2433<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration 2434belongs to. 2435 2436FIXME: Generalize this for other kinds of declarations. 2437FIXME: What other kind of declarations would we need to generalize 2438this to? 2439 2440Example matches A() in the last line 2441 (matcher = constructExpr(hasDeclaration(methodDecl( 2442 ofClass(hasName("A")))))) 2443 class A { 2444 public: 2445 A(); 2446 }; 2447 A a = A(); 2448</pre></td></tr> 2449 2450 2451<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasMethod0')"><a name="hasMethod0Anchor">hasMethod</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr> 2452<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher. 2453 2454Given: 2455 class A { void func(); }; 2456 class B { void member(); }; 2457 2458recordDecl(hasMethod(hasName("func"))) matches the declaration of A 2459but not B. 2460</pre></td></tr> 2461 2462 2463<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom0')"><a name="isDerivedFrom0Anchor">isDerivedFrom</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> 2464<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from 2465a class matching Base. 2466 2467Note that a class is not considered to be derived from itself. 2468 2469Example matches Y, Z, C (Base == hasName("X")) 2470 class X; 2471 class Y : public X {}; directly derived 2472 class Z : public Y {}; indirectly derived 2473 typedef X A; 2474 typedef A B; 2475 class C : public B {}; derived from a typedef of X 2476 2477In the following example, Bar matches isDerivedFrom(hasName("X")): 2478 class Foo; 2479 typedef Foo X; 2480 class Bar : public Foo {}; derived from a type that X is a typedef of 2481</pre></td></tr> 2482 2483 2484<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom0')"><a name="isSameOrDerivedFrom0Anchor">isSameOrDerivedFrom</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> 2485<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly 2486match Base. 2487</pre></td></tr> 2488 2489 2490<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('callee1')"><a name="callee1Anchor">callee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2491<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the 2492given matcher. 2493 2494Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x"))))) 2495 class Y { public: void x(); }; 2496 void z() { Y y; y.x(); 2497</pre></td></tr> 2498 2499 2500<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('callee0')"><a name="callee0Anchor">callee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 2501<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call expression's callee expression matches. 2502 2503Given 2504 class Y { void x() { this->x(); x(); Y y; y.x(); } }; 2505 void f() { f(); } 2506callExpr(callee(expr())) 2507 matches this->x(), x(), y.x(), f() 2508with callee(...) 2509 matching this->x, x, y.x, f respectively 2510 2511Note: Callee cannot take the more general internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> 2512because this introduces ambiguous overloads with calls to Callee taking a 2513internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely 2514implemented in terms of implicit casts. 2515</pre></td></tr> 2516 2517 2518<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument0')"><a name="hasAnyArgument0Anchor">hasAnyArgument</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2519<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call 2520expression. 2521 2522Given 2523 void x(int, int, int) { int y; x(1, y, 42); } 2524callExpr(hasAnyArgument(declRefExpr())) 2525 matches x(1, y, 42) 2526with hasAnyArgument(...) 2527 matching y 2528 2529FIXME: Currently this will ignore parentheses and implicit casts on 2530the argument before applying the inner matcher. We'll want to remove 2531this to allow for greater control by the user once ignoreImplicit() 2532has been implemented. 2533</pre></td></tr> 2534 2535 2536<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasArgument0')"><a name="hasArgument0Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2537<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor 2538call expression. 2539 2540Example matches y in x(y) 2541 (matcher = callExpr(hasArgument(0, declRefExpr()))) 2542 void x(int) { int y; x(y); } 2543</pre></td></tr> 2544 2545 2546<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasDeclaration13')"><a name="hasDeclaration13Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2547<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node 2548matches the given matcher. 2549 2550The associated declaration is: 2551- for type nodes, the declaration of the underlying type 2552- for CallExpr, the declaration of the callee 2553- for MemberExpr, the declaration of the referenced member 2554- for CXXConstructExpr, the declaration of the constructor 2555 2556Also usable as Matcher<T> for any T supporting the getDecl() member 2557function. e.g. various subtypes of clang::Type and various expressions. 2558 2559Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 2560 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 2561 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 2562 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 2563 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 2564 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 2565</pre></td></tr> 2566 2567 2568<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>></td><td class="name" onclick="toggle('hasCaseConstant0')"><a name="hasCaseConstant0Anchor">hasCaseConstant</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2569<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range 2570extension, matches the constant given in the statement. 2571 2572Given 2573 switch (1) { case 1: case 1+1: case 3 ... 4: ; } 2574caseStmt(hasCaseConstant(integerLiteral())) 2575 matches "case 1:" 2576</pre></td></tr> 2577 2578 2579<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>></td><td class="name" onclick="toggle('hasSourceExpression0')"><a name="hasSourceExpression0Anchor">hasSourceExpression</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2580<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression matches the given matcher. 2581 2582Example: matches "a string" (matcher = 2583 hasSourceExpression(constructExpr())) 2584class URL { URL(string); }; 2585URL url = "a string"; 2586</pre></td></tr> 2587 2588 2589<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument0')"><a name="hasAnyTemplateArgument0Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 2590<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations that have at least one 2591TemplateArgument matching the given InnerMatcher. 2592 2593Given 2594 template<typename T> class A {}; 2595 template<> class A<double> {}; 2596 A<int> a; 2597classTemplateSpecializationDecl(hasAnyTemplateArgument( 2598 refersToType(asString("int")))) 2599 matches the specialization A<int> 2600</pre></td></tr> 2601 2602 2603<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument0')"><a name="hasTemplateArgument0Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 2604<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument 2605matches the given InnerMatcher. 2606 2607Given 2608 template<typename T, typename U> class A {}; 2609 A<bool, int> b; 2610 A<int, bool> c; 2611classTemplateSpecializationDecl(hasTemplateArgument( 2612 1, refersToType(asString("int")))) 2613 matches the specialization A<bool, int> 2614</pre></td></tr> 2615 2616 2617<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexTypeLoc.html">ComplexTypeLoc</a>></td><td class="name" onclick="toggle('hasElementTypeLoc1')"><a name="hasElementTypeLoc1Anchor">hasElementTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 2618<tr><td colspan="4" class="doc" id="hasElementTypeLoc1"><pre>Matches arrays and C99 complex types that have a specific element 2619type. 2620 2621Given 2622 struct A {}; 2623 A a[7]; 2624 int b[7]; 2625arrayType(hasElementType(builtinType())) 2626 matches "int b[7]" 2627 2628Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 2629</pre></td></tr> 2630 2631 2632<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>></td><td class="name" onclick="toggle('hasElementType1')"><a name="hasElementType1Anchor">hasElementType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 2633<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element 2634type. 2635 2636Given 2637 struct A {}; 2638 A a[7]; 2639 int b[7]; 2640arrayType(hasElementType(builtinType())) 2641 matches "int b[7]" 2642 2643Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 2644</pre></td></tr> 2645 2646 2647<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>></td><td class="name" onclick="toggle('hasAnySubstatement0')"><a name="hasAnySubstatement0Anchor">hasAnySubstatement</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 2648<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches 2649a given matcher. 2650 2651Given 2652 { {}; 1+2; } 2653hasAnySubstatement(compoundStmt()) 2654 matches '{ {}; 1+2; }' 2655with compoundStmt() 2656 matching '{}' 2657</pre></td></tr> 2658 2659 2660<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>></td><td class="name" onclick="toggle('hasCondition4')"><a name="hasCondition4Anchor">hasCondition</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2661<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, 2662or conditional operator. 2663 2664Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) 2665 if (true) {} 2666</pre></td></tr> 2667 2668 2669<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>></td><td class="name" onclick="toggle('hasFalseExpression0')"><a name="hasFalseExpression0Anchor">hasFalseExpression</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2670<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator. 2671 2672Example matches b 2673 condition ? a : b 2674</pre></td></tr> 2675 2676 2677<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>></td><td class="name" onclick="toggle('hasTrueExpression0')"><a name="hasTrueExpression0Anchor">hasTrueExpression</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2678<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator. 2679 2680Example matches a 2681 condition ? a : b 2682</pre></td></tr> 2683 2684 2685<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('hasDeclaration11')"><a name="hasDeclaration11Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2686<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node 2687matches the given matcher. 2688 2689The associated declaration is: 2690- for type nodes, the declaration of the underlying type 2691- for CallExpr, the declaration of the callee 2692- for MemberExpr, the declaration of the referenced member 2693- for CXXConstructExpr, the declaration of the constructor 2694 2695Also usable as Matcher<T> for any T supporting the getDecl() member 2696function. e.g. various subtypes of clang::Type and various expressions. 2697 2698Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 2699 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 2700 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 2701 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 2702 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 2703 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 2704</pre></td></tr> 2705 2706 2707<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('throughUsingDecl0')"><a name="throughUsingDecl0Anchor">throughUsingDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> InnerMatcher</td></tr> 2708<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a 2709specific using shadow declaration. 2710 2711FIXME: This currently only works for functions. Fix. 2712 2713Given 2714 namespace a { void f() {} } 2715 using a::f; 2716 void g() { 2717 f(); Matches this .. 2718 a::f(); .. but not this. 2719 } 2720declRefExpr(throughUsingDeclaration(anything())) 2721 matches f() 2722</pre></td></tr> 2723 2724 2725<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('to0')"><a name="to0Anchor">to</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2726<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the 2727specified matcher. 2728 2729Example matches x in if(x) 2730 (matcher = declRefExpr(to(varDecl(hasName("x"))))) 2731 bool x; 2732 if (x) {} 2733</pre></td></tr> 2734 2735 2736<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('containsDeclaration0')"><a name="containsDeclaration0Anchor">containsDeclaration</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2737<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement. 2738 2739Note that this does not work for global declarations because the AST 2740breaks up multiple-declaration DeclStmt's into multiple single-declaration 2741DeclStmt's. 2742Example: Given non-global declarations 2743 int a, b = 0; 2744 int c; 2745 int d = 2, e; 2746declStmt(containsDeclaration( 2747 0, varDecl(hasInitializer(anything())))) 2748 matches only 'int d = 2, e;', and 2749declStmt(containsDeclaration(1, varDecl())) 2750 matches 'int a, b = 0' as well as 'int d = 2, e;' 2751 but 'int c;' is not matched. 2752</pre></td></tr> 2753 2754 2755<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('hasSingleDecl0')"><a name="hasSingleDecl0Anchor">hasSingleDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2756<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration. 2757 2758Given 2759 int a, b; 2760 int c; 2761declStmt(hasSingleDecl(anything())) 2762 matches 'int c;' but not 'int a, b;'. 2763</pre></td></tr> 2764 2765 2766<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>></td><td class="name" onclick="toggle('hasTypeLoc0')"><a name="hasTypeLoc0Anchor">hasTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr> 2767<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of the declarator decl's type matches 2768the inner matcher. 2769 2770Given 2771 int x; 2772declaratorDecl(hasTypeLoc(loc(asString("int")))) 2773 matches int x 2774</pre></td></tr> 2775 2776 2777<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('hasDeclContext0')"><a name="hasDeclContext0Anchor">hasDeclContext</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2778<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a 2779Decl, matches InnerMatcher. 2780 2781Given 2782 namespace N { 2783 namespace M { 2784 class D {}; 2785 } 2786 } 2787 2788recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the 2789declaration of class D. 2790</pre></td></tr> 2791 2792 2793<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>></td><td class="name" onclick="toggle('hasBody0')"><a name="hasBody0Anchor">hasBody</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 2794<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', or 'do while' statement that has 2795a given body. 2796 2797Given 2798 for (;;) {} 2799hasBody(compoundStmt()) 2800 matches 'for (;;) {}' 2801with compoundStmt() 2802 matching '{}' 2803</pre></td></tr> 2804 2805 2806<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>></td><td class="name" onclick="toggle('hasCondition3')"><a name="hasCondition3Anchor">hasCondition</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2807<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, 2808or conditional operator. 2809 2810Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) 2811 if (true) {} 2812</pre></td></tr> 2813 2814 2815<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>></td><td class="name" onclick="toggle('hasQualifier0')"><a name="hasQualifier0Anchor">hasQualifier</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 2816<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, 2817matches InnerMatcher if the qualifier exists. 2818 2819Given 2820 namespace N { 2821 namespace M { 2822 class D {}; 2823 } 2824 } 2825 N::M::D d; 2826 2827elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) 2828matches the type of the variable declaration of d. 2829</pre></td></tr> 2830 2831 2832<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>></td><td class="name" onclick="toggle('namesType0')"><a name="namesType0Anchor">namesType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 2833<tr><td colspan="4" class="doc" id="namesType0"><pre>Matches ElaboratedTypes whose named type matches InnerMatcher. 2834 2835Given 2836 namespace N { 2837 namespace M { 2838 class D {}; 2839 } 2840 } 2841 N::M::D d; 2842 2843elaboratedType(namesType(recordType( 2844hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable 2845declaration of d. 2846</pre></td></tr> 2847 2848 2849<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>></td><td class="name" onclick="toggle('hasDeclaration10')"><a name="hasDeclaration10Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2850<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node 2851matches the given matcher. 2852 2853The associated declaration is: 2854- for type nodes, the declaration of the underlying type 2855- for CallExpr, the declaration of the callee 2856- for MemberExpr, the declaration of the referenced member 2857- for CXXConstructExpr, the declaration of the constructor 2858 2859Also usable as Matcher<T> for any T supporting the getDecl() member 2860function. e.g. various subtypes of clang::Type and various expressions. 2861 2862Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 2863 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 2864 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 2865 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 2866 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 2867 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 2868</pre></td></tr> 2869 2870 2871<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>></td><td class="name" onclick="toggle('hasDestinationType0')"><a name="hasDestinationType0Anchor">hasDestinationType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 2872<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher. 2873 2874(Note: Clang's AST refers to other conversions as "casts" too, and calls 2875actual casts "explicit" casts.) 2876</pre></td></tr> 2877 2878 2879<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('hasType2')"><a name="hasType2Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 2880<tr><td colspan="4" class="doc" id="hasType2"><pre>Overloaded to match the declaration of the expression's or value 2881declaration's type. 2882 2883In case of a value declaration (for example a variable declaration), 2884this resolves one layer of indirection. For example, in the value 2885declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, 2886while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration 2887of x." 2888 2889Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) 2890 and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) 2891 class X {}; 2892 void y(X &x) { x; X z; } 2893 2894Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> 2895</pre></td></tr> 2896 2897 2898<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('hasType0')"><a name="hasType0Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 2899<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type 2900matcher. 2901 2902Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) 2903 and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) 2904 class X {}; 2905 void y(X &x) { x; X z; } 2906</pre></td></tr> 2907 2908 2909<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringImpCasts0')"><a name="ignoringImpCasts0Anchor">ignoringImpCasts</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2910<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts 2911are stripped off. 2912 2913Parentheses and explicit casts are not discarded. 2914Given 2915 int arr[5]; 2916 int a = 0; 2917 char b = 0; 2918 const int c = a; 2919 int *d = arr; 2920 long e = (long) 0l; 2921The matchers 2922 varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) 2923 varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) 2924would match the declarations for a, b, c, and d, but not e. 2925While 2926 varDecl(hasInitializer(integerLiteral())) 2927 varDecl(hasInitializer(declRefExpr())) 2928only match the declarations for b, c, and d. 2929</pre></td></tr> 2930 2931 2932<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParenCasts0')"><a name="ignoringParenCasts0Anchor">ignoringParenCasts</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2933<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and 2934casts are stripped off. 2935 2936Implicit and non-C Style casts are also discarded. 2937Given 2938 int a = 0; 2939 char b = (0); 2940 void* c = reinterpret_cast<char*>(0); 2941 char d = char(0); 2942The matcher 2943 varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) 2944would match the declarations for a, b, c, and d. 2945while 2946 varDecl(hasInitializer(integerLiteral())) 2947only match the declaration for a. 2948</pre></td></tr> 2949 2950 2951<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParenImpCasts0')"><a name="ignoringParenImpCasts0Anchor">ignoringParenImpCasts</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2952<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and 2953parentheses are stripped off. 2954 2955Explicit casts are not discarded. 2956Given 2957 int arr[5]; 2958 int a = 0; 2959 char b = (0); 2960 const int c = a; 2961 int *d = (arr); 2962 long e = ((long) 0l); 2963The matchers 2964 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) 2965 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) 2966would match the declarations for a, b, c, and d, but not e. 2967while 2968 varDecl(hasInitializer(integerLiteral())) 2969 varDecl(hasInitializer(declRefExpr())) 2970would only match the declaration for a. 2971</pre></td></tr> 2972 2973 2974<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasBody1')"><a name="hasBody1Anchor">hasBody</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 2975<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', or 'do while' statement that has 2976a given body. 2977 2978Given 2979 for (;;) {} 2980hasBody(compoundStmt()) 2981 matches 'for (;;) {}' 2982with compoundStmt() 2983 matching '{}' 2984</pre></td></tr> 2985 2986 2987<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasCondition1')"><a name="hasCondition1Anchor">hasCondition</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 2988<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, 2989or conditional operator. 2990 2991Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) 2992 if (true) {} 2993</pre></td></tr> 2994 2995 2996<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasIncrement0')"><a name="hasIncrement0Anchor">hasIncrement</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 2997<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop. 2998 2999Example: 3000 forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) 3001matches '++x' in 3002 for (x; x < N; ++x) { } 3003</pre></td></tr> 3004 3005 3006<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasLoopInit0')"><a name="hasLoopInit0Anchor">hasLoopInit</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 3007<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop. 3008 3009Example: 3010 forStmt(hasLoopInit(declStmt())) 3011matches 'int x = 0' in 3012 for (int x = 0; x < N; ++x) { } 3013</pre></td></tr> 3014 3015 3016<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyParameter0')"><a name="hasAnyParameter0Anchor">hasAnyParameter</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr> 3017<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function declaration. 3018 3019Does not match the 'this' parameter of a method. 3020 3021Given 3022 class X { void f(int x, int y, int z) {} }; 3023methodDecl(hasAnyParameter(hasName("y"))) 3024 matches f(int x, int y, int z) {} 3025with hasAnyParameter(...) 3026 matching int y 3027</pre></td></tr> 3028 3029 3030<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasParameter0')"><a name="hasParameter0Anchor">hasParameter</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr> 3031<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function declaration. 3032 3033Given 3034 class X { void f(int x) {} }; 3035methodDecl(hasParameter(0, hasType(varDecl()))) 3036 matches f(int x) {} 3037with hasParameter(...) 3038 matching int x 3039</pre></td></tr> 3040 3041 3042<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('returns0')"><a name="returns0Anchor">returns</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3043<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration. 3044 3045Given: 3046 class X { int f() { return 1; } }; 3047methodDecl(returns(asString("int"))) 3048 matches int f() { return 1; } 3049</pre></td></tr> 3050 3051 3052<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasCondition0')"><a name="hasCondition0Anchor">hasCondition</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3053<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, 3054or conditional operator. 3055 3056Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) 3057 if (true) {} 3058</pre></td></tr> 3059 3060 3061<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasConditionVariableStatement0')"><a name="hasConditionVariableStatement0Anchor">hasConditionVariableStatement</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr> 3062<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement. 3063 3064Given 3065 if (A* a = GetAPointer()) {} 3066hasConditionVariableStatement(...) 3067 matches 'A* a = GetAPointer()'. 3068</pre></td></tr> 3069 3070 3071<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>></td><td class="name" onclick="toggle('hasImplicitDestinationType0')"><a name="hasImplicitDestinationType0Anchor">hasImplicitDestinationType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3072<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given 3073matcher. 3074 3075FIXME: Unit test this matcher 3076</pre></td></tr> 3077 3078 3079<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>></td><td class="name" onclick="toggle('hasDeclaration9')"><a name="hasDeclaration9Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3080<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node 3081matches the given matcher. 3082 3083The associated declaration is: 3084- for type nodes, the declaration of the underlying type 3085- for CallExpr, the declaration of the callee 3086- for MemberExpr, the declaration of the referenced member 3087- for CXXConstructExpr, the declaration of the constructor 3088 3089Also usable as Matcher<T> for any T supporting the getDecl() member 3090function. e.g. various subtypes of clang::Type and various expressions. 3091 3092Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3093 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3094 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3095 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3096 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3097 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3098</pre></td></tr> 3099 3100 3101<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>></td><td class="name" onclick="toggle('hasDeclaration8')"><a name="hasDeclaration8Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3102<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node 3103matches the given matcher. 3104 3105The associated declaration is: 3106- for type nodes, the declaration of the underlying type 3107- for CallExpr, the declaration of the callee 3108- for MemberExpr, the declaration of the referenced member 3109- for CXXConstructExpr, the declaration of the constructor 3110 3111Also usable as Matcher<T> for any T supporting the getDecl() member 3112function. e.g. various subtypes of clang::Type and various expressions. 3113 3114Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3115 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3116 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3117 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3118 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3119 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3120</pre></td></tr> 3121 3122 3123<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('hasDeclaration7')"><a name="hasDeclaration7Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3124<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node 3125matches the given matcher. 3126 3127The associated declaration is: 3128- for type nodes, the declaration of the underlying type 3129- for CallExpr, the declaration of the callee 3130- for MemberExpr, the declaration of the referenced member 3131- for CXXConstructExpr, the declaration of the constructor 3132 3133Also usable as Matcher<T> for any T supporting the getDecl() member 3134function. e.g. various subtypes of clang::Type and various expressions. 3135 3136Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3137 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3138 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3139 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3140 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3141 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3142</pre></td></tr> 3143 3144 3145<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('hasObjectExpression0')"><a name="hasObjectExpression0Anchor">hasObjectExpression</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3146<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is 3147matched by a given matcher. 3148 3149Given 3150 struct X { int m; }; 3151 void f(X x) { x.m; m; } 3152memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))) 3153 matches "x.m" and "m" 3154with hasObjectExpression(...) 3155 matching "x" and the implicit object expression of "m" which has type X*. 3156</pre></td></tr> 3157 3158 3159<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('member0')"><a name="member0Anchor">member</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> InnerMatcher</td></tr> 3160<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a 3161given matcher. 3162 3163Given 3164 struct { int first, second; } first, second; 3165 int i(second.first); 3166 int j(first.second); 3167memberExpr(member(hasName("first"))) 3168 matches second.first 3169 but not first.second (because the member name there is "second"). 3170</pre></td></tr> 3171 3172 3173<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerTypeLoc.html">MemberPointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc1')"><a name="pointeeLoc1Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3174<tr><td colspan="4" class="doc" id="pointeeLoc1"><pre>Narrows PointerType (and similar) matchers to those where the 3175pointee matches a given matcher. 3176 3177Given 3178 int *a; 3179 int const *b; 3180 float const *f; 3181pointerType(pointee(isConstQualified(), isInteger())) 3182 matches "int const *b" 3183 3184Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3185 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3186</pre></td></tr> 3187 3188 3189<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>></td><td class="name" onclick="toggle('pointee1')"><a name="pointee1Anchor">pointee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3190<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the 3191pointee matches a given matcher. 3192 3193Given 3194 int *a; 3195 int const *b; 3196 float const *f; 3197pointerType(pointee(isConstQualified(), isInteger())) 3198 matches "int const *b" 3199 3200Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3201 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3202</pre></td></tr> 3203 3204 3205<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('hasPrefix1')"><a name="hasPrefix1Anchor">hasPrefix</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>> InnerMatcher</td></tr> 3206<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc. 3207 3208Given 3209 struct A { struct B { struct C {}; }; }; 3210 A::B::C c; 3211nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) 3212 matches "A::" 3213</pre></td></tr> 3214 3215 3216<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('specifiesTypeLoc0')"><a name="specifiesTypeLoc0Anchor">specifiesTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> InnerMatcher</td></tr> 3217<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the 3218given TypeLoc. 3219 3220Given 3221 struct A { struct B { struct C {}; }; }; 3222 A::B::C c; 3223nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( 3224 hasDeclaration(recordDecl(hasName("A"))))))) 3225 matches "A::" 3226</pre></td></tr> 3227 3228 3229<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('hasPrefix0')"><a name="hasPrefix0Anchor">hasPrefix</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 3230<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier. 3231 3232Given 3233 struct A { struct B { struct C {}; }; }; 3234 A::B::C c; 3235nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and 3236 matches "A::" 3237</pre></td></tr> 3238 3239 3240<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('specifiesNamespace0')"><a name="specifiesNamespace0Anchor">specifiesNamespace</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>> InnerMatcher</td></tr> 3241<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the 3242given namespace matcher. 3243 3244Given 3245 namespace ns { struct A {}; } 3246 ns::A a; 3247nestedNameSpecifier(specifiesNamespace(hasName("ns"))) 3248 matches "ns::" 3249</pre></td></tr> 3250 3251 3252<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('specifiesType0')"><a name="specifiesType0Anchor">specifiesType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3253<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the 3254given QualType matcher without qualifiers. 3255 3256Given 3257 struct A { struct B { struct C {}; }; }; 3258 A::B::C c; 3259nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A"))))) 3260 matches "A::" 3261</pre></td></tr> 3262 3263 3264<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>></td><td class="name" onclick="toggle('innerType0')"><a name="innerType0Anchor">innerType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3265<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type. 3266 3267Given 3268 int (*ptr_to_array)[4]; 3269 int (*ptr_to_func)(int); 3270 3271varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches 3272ptr_to_func but not ptr_to_array. 3273 3274Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>> 3275</pre></td></tr> 3276 3277 3278<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html">PointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc2')"><a name="pointeeLoc2Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3279<tr><td colspan="4" class="doc" id="pointeeLoc2"><pre>Narrows PointerType (and similar) matchers to those where the 3280pointee matches a given matcher. 3281 3282Given 3283 int *a; 3284 int const *b; 3285 float const *f; 3286pointerType(pointee(isConstQualified(), isInteger())) 3287 matches "int const *b" 3288 3289Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3290 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3291</pre></td></tr> 3292 3293 3294<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>></td><td class="name" onclick="toggle('pointee2')"><a name="pointee2Anchor">pointee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3295<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the 3296pointee matches a given matcher. 3297 3298Given 3299 int *a; 3300 int const *b; 3301 float const *f; 3302pointerType(pointee(isConstQualified(), isInteger())) 3303 matches "int const *b" 3304 3305Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3306 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3307</pre></td></tr> 3308 3309 3310<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasCanonicalType0')"><a name="hasCanonicalType0Anchor">hasCanonicalType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3311<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher. 3312 3313Given: 3314 typedef int &int_ref; 3315 int a; 3316 int_ref b = a; 3317 3318varDecl(hasType(qualType(referenceType()))))) will not match the 3319declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. 3320</pre></td></tr> 3321 3322 3323<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasDeclaration6')"><a name="hasDeclaration6Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3324<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node 3325matches the given matcher. 3326 3327The associated declaration is: 3328- for type nodes, the declaration of the underlying type 3329- for CallExpr, the declaration of the callee 3330- for MemberExpr, the declaration of the referenced member 3331- for CXXConstructExpr, the declaration of the constructor 3332 3333Also usable as Matcher<T> for any T supporting the getDecl() member 3334function. e.g. various subtypes of clang::Type and various expressions. 3335 3336Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3337 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3338 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3339 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3340 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3341 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3342</pre></td></tr> 3343 3344 3345<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('pointsTo1')"><a name="pointsTo1Anchor">pointsTo</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3346<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration. 3347</pre></td></tr> 3348 3349 3350<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('pointsTo0')"><a name="pointsTo0Anchor">pointsTo</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3351<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type 3352matches the specified matcher. 3353 3354Example matches y->x() 3355 (matcher = callExpr(on(hasType(pointsTo(recordDecl(hasName("Y"))))))) 3356 class Y { public: void x(); }; 3357 void z() { Y *y; y->x(); } 3358</pre></td></tr> 3359 3360 3361<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('references1')"><a name="references1Anchor">references</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3362<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration. 3363</pre></td></tr> 3364 3365 3366<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('references0')"><a name="references0Anchor">references</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3367<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced 3368type matches the specified matcher. 3369 3370Example matches X &x and const X &y 3371 (matcher = varDecl(hasType(references(recordDecl(hasName("X")))))) 3372 class X { 3373 void a(X b) { 3374 X &x = b; 3375 const X &y = b; 3376 }; 3377</pre></td></tr> 3378 3379 3380<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>></td><td class="name" onclick="toggle('hasDeclaration5')"><a name="hasDeclaration5Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3381<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node 3382matches the given matcher. 3383 3384The associated declaration is: 3385- for type nodes, the declaration of the underlying type 3386- for CallExpr, the declaration of the callee 3387- for MemberExpr, the declaration of the referenced member 3388- for CXXConstructExpr, the declaration of the constructor 3389 3390Also usable as Matcher<T> for any T supporting the getDecl() member 3391function. e.g. various subtypes of clang::Type and various expressions. 3392 3393Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3394 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3395 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3396 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3397 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3398 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3399</pre></td></tr> 3400 3401 3402<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceTypeLoc.html">ReferenceTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc3')"><a name="pointeeLoc3Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3403<tr><td colspan="4" class="doc" id="pointeeLoc3"><pre>Narrows PointerType (and similar) matchers to those where the 3404pointee matches a given matcher. 3405 3406Given 3407 int *a; 3408 int const *b; 3409 float const *f; 3410pointerType(pointee(isConstQualified(), isInteger())) 3411 matches "int const *b" 3412 3413Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3414 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3415</pre></td></tr> 3416 3417 3418<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>></td><td class="name" onclick="toggle('pointee3')"><a name="pointee3Anchor">pointee</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3419<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the 3420pointee matches a given matcher. 3421 3422Given 3423 int *a; 3424 int const *b; 3425 float const *f; 3426pointerType(pointee(isConstQualified(), isInteger())) 3427 matches "int const *b" 3428 3429Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3430 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3431</pre></td></tr> 3432 3433 3434<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('alignOfExpr0')"><a name="alignOfExpr0Anchor">alignOfExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr> 3435<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 3436alignof. 3437</pre></td></tr> 3438 3439 3440<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('sizeOfExpr0')"><a name="sizeOfExpr0Anchor">sizeOfExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr> 3441<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 3442sizeof. 3443</pre></td></tr> 3444 3445 3446<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('forEachSwitchCase0')"><a name="forEachSwitchCase0Anchor">forEachSwitchCase</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>> InnerMatcher</td></tr> 3447<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch 3448statement. This matcher may produce multiple matches. 3449 3450Given 3451 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } 3452switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") 3453 matches four times, with "c" binding each of "case 1:", "case 2:", 3454"case 3:" and "case 4:", and "s" respectively binding "switch (1)", 3455"switch (1)", "switch (2)" and "switch (2)". 3456</pre></td></tr> 3457 3458 3459<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>></td><td class="name" onclick="toggle('hasDeclaration4')"><a name="hasDeclaration4Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3460<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node 3461matches the given matcher. 3462 3463The associated declaration is: 3464- for type nodes, the declaration of the underlying type 3465- for CallExpr, the declaration of the callee 3466- for MemberExpr, the declaration of the referenced member 3467- for CXXConstructExpr, the declaration of the constructor 3468 3469Also usable as Matcher<T> for any T supporting the getDecl() member 3470function. e.g. various subtypes of clang::Type and various expressions. 3471 3472Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3473 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3474 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3475 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3476 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3477 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3478</pre></td></tr> 3479 3480 3481<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('isExpr0')"><a name="isExpr0Anchor">isExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3482<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression. 3483 3484Given 3485 template<typename T> struct A {}; 3486 struct B { B* next; }; 3487 A<&B::next> a; 3488templateSpecializationType(hasAnyTemplateArgument( 3489 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) 3490 matches the specialization A<&B::next> with fieldDecl(...) matching 3491 B::next 3492</pre></td></tr> 3493 3494 3495<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToDeclaration0')"><a name="refersToDeclaration0Anchor">refersToDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3496<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain 3497declaration. 3498 3499Given 3500 template<typename T> struct A {}; 3501 struct B { B* next; }; 3502 A<&B::next> a; 3503classTemplateSpecializationDecl(hasAnyTemplateArgument( 3504 refersToDeclaration(fieldDecl(hasName("next")))) 3505 matches the specialization A<&B::next> with fieldDecl(...) matching 3506 B::next 3507</pre></td></tr> 3508 3509 3510<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToType0')"><a name="refersToType0Anchor">refersToType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3511<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type. 3512 3513Given 3514 struct X {}; 3515 template<typename T> struct A {}; 3516 A<X> a; 3517classTemplateSpecializationDecl(hasAnyTemplateArgument( 3518 refersToType(class(hasName("X"))))) 3519 matches the specialization A<X> 3520</pre></td></tr> 3521 3522 3523<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument1')"><a name="hasAnyTemplateArgument1Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 3524<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations that have at least one 3525TemplateArgument matching the given InnerMatcher. 3526 3527Given 3528 template<typename T> class A {}; 3529 template<> class A<double> {}; 3530 A<int> a; 3531classTemplateSpecializationDecl(hasAnyTemplateArgument( 3532 refersToType(asString("int")))) 3533 matches the specialization A<int> 3534</pre></td></tr> 3535 3536 3537<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasDeclaration3')"><a name="hasDeclaration3Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3538<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node 3539matches the given matcher. 3540 3541The associated declaration is: 3542- for type nodes, the declaration of the underlying type 3543- for CallExpr, the declaration of the callee 3544- for MemberExpr, the declaration of the referenced member 3545- for CXXConstructExpr, the declaration of the constructor 3546 3547Also usable as Matcher<T> for any T supporting the getDecl() member 3548function. e.g. various subtypes of clang::Type and various expressions. 3549 3550Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3551 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3552 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3553 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3554 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3555 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3556</pre></td></tr> 3557 3558 3559<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasTemplateArgument1')"><a name="hasTemplateArgument1Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 3560<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument 3561matches the given InnerMatcher. 3562 3563Given 3564 template<typename T, typename U> class A {}; 3565 A<bool, int> b; 3566 A<int, bool> c; 3567classTemplateSpecializationDecl(hasTemplateArgument( 3568 1, refersToType(asString("int")))) 3569 matches the specialization A<bool, int> 3570</pre></td></tr> 3571 3572 3573<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>></td><td class="name" onclick="toggle('hasDeclaration2')"><a name="hasDeclaration2Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3574<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node 3575matches the given matcher. 3576 3577The associated declaration is: 3578- for type nodes, the declaration of the underlying type 3579- for CallExpr, the declaration of the callee 3580- for MemberExpr, the declaration of the referenced member 3581- for CXXConstructExpr, the declaration of the constructor 3582 3583Also usable as Matcher<T> for any T supporting the getDecl() member 3584function. e.g. various subtypes of clang::Type and various expressions. 3585 3586Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3587 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3588 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3589 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3590 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3591 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3592</pre></td></tr> 3593 3594 3595<tr><td>Matcher<T></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>Matcher<T> Matcher</td></tr> 3596<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches. 3597 3598Generates results for each match. 3599 3600For example, in: 3601 class A { class B {}; class C {}; }; 3602The matcher: 3603 recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m"))) 3604will generate results for A, B and C. 3605 3606Usable as: Any Matcher 3607</pre></td></tr> 3608 3609 3610<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>></td><td class="name" onclick="toggle('hasDeclaration1')"><a name="hasDeclaration1Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3611<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node 3612matches the given matcher. 3613 3614The associated declaration is: 3615- for type nodes, the declaration of the underlying type 3616- for CallExpr, the declaration of the callee 3617- for MemberExpr, the declaration of the referenced member 3618- for CXXConstructExpr, the declaration of the constructor 3619 3620Also usable as Matcher<T> for any T supporting the getDecl() member 3621function. e.g. various subtypes of clang::Type and various expressions. 3622 3623Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3624 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3625 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3626 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3627 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3628 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3629</pre></td></tr> 3630 3631 3632<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>></td><td class="name" onclick="toggle('hasArgumentOfType0')"><a name="hasArgumentOfType0Anchor">hasArgumentOfType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3633<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument. 3634 3635Given 3636 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); 3637unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) 3638 matches sizeof(a) and alignof(c) 3639</pre></td></tr> 3640 3641 3642<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasUnaryOperand0')"><a name="hasUnaryOperand0Anchor">hasUnaryOperand</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3643<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches. 3644 3645Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true)))) 3646 !true 3647</pre></td></tr> 3648 3649 3650<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>></td><td class="name" onclick="toggle('hasDeclaration0')"><a name="hasDeclaration0Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3651<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node 3652matches the given matcher. 3653 3654The associated declaration is: 3655- for type nodes, the declaration of the underlying type 3656- for CallExpr, the declaration of the callee 3657- for MemberExpr, the declaration of the referenced member 3658- for CXXConstructExpr, the declaration of the constructor 3659 3660Also usable as Matcher<T> for any T supporting the getDecl() member 3661function. e.g. various subtypes of clang::Type and various expressions. 3662 3663Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3664 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3665 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, 3666 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3667 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3668 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3669</pre></td></tr> 3670 3671 3672<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>></td><td class="name" onclick="toggle('hasAnyUsingShadowDecl0')"><a name="hasAnyUsingShadowDecl0Anchor">hasAnyUsingShadowDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> InnerMatcher</td></tr> 3673<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration. 3674 3675Given 3676 namespace X { void b(); } 3677 using X::b; 3678usingDecl(hasAnyUsingShadowDecl(hasName("b")))) 3679 matches using X::b </pre></td></tr> 3680 3681 3682<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>></td><td class="name" onclick="toggle('hasTargetDecl0')"><a name="hasTargetDecl0Anchor">hasTargetDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> InnerMatcher</td></tr> 3683<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is 3684matched by the given matcher. 3685 3686Given 3687 namespace X { int a; void b(); } 3688 using X::a; 3689 using X::b; 3690usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) 3691 matches using X::b but not using X::a </pre></td></tr> 3692 3693 3694<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType3')"><a name="hasType3Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3695<tr><td colspan="4" class="doc" id="hasType3"><pre>Overloaded to match the declaration of the expression's or value 3696declaration's type. 3697 3698In case of a value declaration (for example a variable declaration), 3699this resolves one layer of indirection. For example, in the value 3700declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, 3701while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration 3702of x." 3703 3704Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) 3705 and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) 3706 class X {}; 3707 void y(X &x) { x; X z; } 3708 3709Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> 3710</pre></td></tr> 3711 3712 3713<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType1')"><a name="hasType1Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3714<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type 3715matcher. 3716 3717Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) 3718 and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) 3719 class X {}; 3720 void y(X &x) { x; X z; } 3721</pre></td></tr> 3722 3723 3724<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasInitializer0')"><a name="hasInitializer0Anchor">hasInitializer</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3725<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression 3726that matches the given matcher. 3727 3728Example matches x (matcher = varDecl(hasInitializer(callExpr()))) 3729 bool y() { return true; } 3730 bool x = y(); 3731</pre></td></tr> 3732 3733 3734<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>></td><td class="name" onclick="toggle('hasSizeExpr0')"><a name="hasSizeExpr0Anchor">hasSizeExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3735<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size 3736expression. 3737 3738Given 3739 void f(int b) { 3740 int a[b]; 3741 } 3742variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( 3743 varDecl(hasName("b"))))))) 3744 matches "int a[b]" 3745</pre></td></tr> 3746 3747 3748<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>></td><td class="name" onclick="toggle('hasBody2')"><a name="hasBody2Anchor">hasBody</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 3749<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', or 'do while' statement that has 3750a given body. 3751 3752Given 3753 for (;;) {} 3754hasBody(compoundStmt()) 3755 matches 'for (;;) {}' 3756with compoundStmt() 3757 matching '{}' 3758</pre></td></tr> 3759 3760 3761<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>></td><td class="name" onclick="toggle('hasCondition2')"><a name="hasCondition2Anchor">hasCondition</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3762<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, 3763or conditional operator. 3764 3765Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) 3766 if (true) {} 3767</pre></td></tr> 3768 3769 3770<tr><td>Matcher<internal::BindableMatcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>>></td><td class="name" onclick="toggle('loc1')"><a name="loc1Anchor">loc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 3771<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner 3772NestedNameSpecifier-matcher matches. 3773</pre></td></tr> 3774 3775 3776<tr><td>Matcher<internal::BindableMatcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>></td><td class="name" onclick="toggle('loc0')"><a name="loc0Anchor">loc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 3777<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner 3778QualType-matcher matches. 3779</pre></td></tr> 3780 3781<!--END_TRAVERSAL_MATCHERS --> 3782</table> 3783 3784</div> 3785</body> 3786</html> 3787 3788 3789