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