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