2012-08-21 04:54:03 +08:00
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
< html >
< head >
< title > AST Matcher Reference< / title >
< link type = "text/css" rel = "stylesheet" href = "../menu.css" / >
< link type = "text/css" rel = "stylesheet" href = "../content.css" / >
< style type = "text/css" >
td {
padding: .33em;
}
td.doc {
display: none;
border-bottom: 1px solid black;
}
td.name:hover {
color: blue;
cursor: pointer;
}
< / style >
< script type = "text/javascript" >
function toggle(id) {
2012-09-07 21:10:32 +08:00
if (!id) return;
2012-08-21 04:54:03 +08:00
row = document.getElementById(id);
if (row.style.display != 'table-cell')
row.style.display = 'table-cell';
else
row.style.display = 'none';
}
< / script >
< / head >
2012-09-07 21:10:32 +08:00
< body onLoad = "toggle(location.hash.substring(1, location.hash.length - 6))" >
2012-08-21 04:54:03 +08:00
<!-- #include virtual="../menu.html.incl" -->
< div id = "content" >
< h1 > AST Matcher Reference< / h1 >
< p > This document shows all currently implemented matchers. The matchers are grouped
by category and node type they match. You can click on matcher names to show the
matcher's source documentation.< / p >
< p > There are three different basic categories of matchers:
< ul >
< li > < a href = "#decl-matchers" > Node Matchers:< / a > Matchers that match a specific type of AST node.< / li >
< li > < a href = "#narrowing-matchers" > Narrowing Matchers:< / a > Matchers that match attributes on AST nodes.< / li >
< li > < a href = "#traversal-matchers" > Traversal Matchers:< / a > Matchers that allow traversal between AST nodes.< / li >
< / ul >
< / p >
< p > Within each category the matchers are ordered by node type they match on.
Note that if a matcher can match multiple node types, it will it will appear
multiple times. This means that by searching for Matcher< Stmt> you can
find all matchers that can be used to match on Stmt nodes.< / p >
< p > The exception to that rule are matchers that can match on any node. Those
are marked with a * and are listed in the beginning of each category.< / p >
<!-- ======================================================================= -->
< h2 id = "decl-matchers" > Node Matchers< / h2 >
<!-- ======================================================================= -->
< p > Node matchers are at the core of matcher expressions - they specify the type
of node that is expected. Every match expression starts with a node matcher,
which can then be further refined with a narrowing or traversal matcher. All
traversal matchers take node matchers as their arguments.< / p >
< p > For convenience, all node matchers take an arbitrary number of arguments
and implicitly act as allOf matchers.< / p >
< p > Node matchers are the only matchers that support the bind("id") call to
bind the matched node to the given string, to be later retrieved from the
match callback.< / p >
< table >
< tr style = "text-align:left" > < th > Return type< / th > < th > Name< / th > < th > Parameters< / th > < / tr >
<!-- START_DECL_MATCHERS -->
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('classTemplateDecl0')" > < a name = "classTemplateDecl0Anchor" > classTemplateDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html" > ClassTemplateDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "classTemplateDecl0" > < pre > Matches C++ class template declarations.
2012-08-21 04:54:03 +08:00
Example matches Z
template< class T> class Z {};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('classTemplateSpecializationDecl0')" > < a name = "classTemplateSpecializationDecl0Anchor" > classTemplateSpecializationDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html" > ClassTemplateSpecializationDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "classTemplateSpecializationDecl0" > < pre > Matches C++ class template specializations.
2012-08-21 04:54:03 +08:00
Given
template< typename T> class A {};
template< > class A< double> {};
A< int> a;
2012-08-27 07:55:24 +08:00
classTemplateSpecializationDecl()
2012-08-21 04:54:03 +08:00
matches the specializations A< int> and A< double>
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('constructorDecl0')" > < a name = "constructorDecl0Anchor" > constructorDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html" > CXXConstructorDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "constructorDecl0" > < pre > Matches C++ constructor declarations.
2012-08-21 04:54:03 +08:00
Example matches Foo::Foo() and Foo::Foo(int)
class Foo {
public:
Foo();
Foo(int);
int DoSomething();
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('decl0')" > < a name = "decl0Anchor" > decl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "decl0" > < pre > Matches declarations.
Examples matches X, C, and the friend declaration inside C;
void X();
class C {
friend X;
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('destructorDecl0')" > < a name = "destructorDecl0Anchor" > destructorDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html" > CXXDestructorDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "destructorDecl0" > < pre > Matches explicit C++ destructor declarations.
2012-08-21 04:54:03 +08:00
Example matches Foo::~Foo()
class Foo {
public:
virtual ~Foo();
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('enumConstantDecl0')" > < a name = "enumConstantDecl0Anchor" > enumConstantDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html" > EnumConstantDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "enumConstantDecl0" > < pre > Matches enum constants.
2012-08-21 04:54:03 +08:00
Example matches A, B, C
enum X {
A, B, C
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('enumDecl0')" > < a name = "enumDecl0Anchor" > enumDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html" > EnumDecl< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "enumDecl0" > < pre > Matches enum declarations.
Example matches X
enum X {
A, B, C
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('fieldDecl0')" > < a name = "fieldDecl0Anchor" > fieldDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html" > FieldDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "fieldDecl0" > < pre > Matches field declarations.
2012-08-21 04:54:03 +08:00
Given
class X { int m; };
2012-08-27 07:55:24 +08:00
fieldDecl()
2012-08-21 04:54:03 +08:00
matches 'm'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('functionDecl0')" > < a name = "functionDecl0Anchor" > functionDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "functionDecl0" > < pre > Matches function declarations.
2012-08-21 04:54:03 +08:00
Example matches f
void f();
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('functionTemplateDecl0')" > < a name = "functionTemplateDecl0Anchor" > functionTemplateDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html" > FunctionTemplateDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "functionTemplateDecl0" > < pre > Matches C++ function template declarations.
2012-08-21 04:54:03 +08:00
Example matches f
template< class T> void f(T t) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('methodDecl0')" > < a name = "methodDecl0Anchor" > methodDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html" > CXXMethodDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "methodDecl0" > < pre > Matches method declarations.
2012-08-21 04:54:03 +08:00
Example matches y
class X { void y() };
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('namedDecl0')" > < a name = "namedDecl0Anchor" > namedDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "namedDecl0" > < pre > Matches a declaration of anything that could have a name.
2012-08-21 04:54:03 +08:00
Example matches X, S, the anonymous union type, i, and U;
typedef int X;
struct S {
union {
int i;
} U;
};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('recordDecl0')" > < a name = "recordDecl0Anchor" > recordDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "recordDecl0" > < pre > Matches C++ class declarations.
2012-08-21 04:54:03 +08:00
Example matches X, Z
class X;
template< class T> class Z {};
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('usingDecl0')" > < a name = "usingDecl0Anchor" > usingDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html" > UsingDecl< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "usingDecl0" > < pre > Matches using declarations.
Given
namespace X { int x; }
using X::x;
usingDecl()
matches using X::x < / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > < / td > < td class = "name" onclick = "toggle('varDecl0')" > < a name = "varDecl0Anchor" > varDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "varDecl0" > < pre > Matches variable declarations.
2012-08-21 04:54:03 +08:00
Note: this does not match declarations of member variables, which are
"field" declarations in Clang parlance.
Example matches a
int a;
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('arraySubscriptExpr0')" > < a name = "arraySubscriptExpr0Anchor" > arraySubscriptExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html" > ArraySubscriptExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "arraySubscriptExpr0" > < pre > Matches array subscript expressions.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Given
int i = a[1];
arraySubscriptExpr()
matches "a[1]"
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('asmStmt0')" > < a name = "asmStmt0Anchor" > asmStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1AsmStmt.html" > AsmStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "asmStmt0" > < pre > Matches asm statements.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
int i = 100;
__asm("mov al, 2");
asmStmt()
matches '__asm("mov al, 2")'
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('binaryOperator0')" > < a name = "binaryOperator0Anchor" > binaryOperator< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html" > BinaryOperator< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "binaryOperator0" > < pre > Matches binary operator expressions.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example matches a || b
!(a || b)
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('bindTemporaryExpr0')" > < a name = "bindTemporaryExpr0Anchor" > bindTemporaryExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html" > CXXBindTemporaryExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "bindTemporaryExpr0" > < pre > Matches nodes where temporaries are created.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example matches FunctionTakesString(GetStringByValue())
(matcher = bindTemporaryExpr())
FunctionTakesString(GetStringByValue());
FunctionTakesStringByPointer(GetStringPointer());
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('boolLiteral0')" > < a name = "boolLiteral0Anchor" > boolLiteral< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html" > CXXBoolLiteralExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "boolLiteral0" > < pre > Matches bool literals.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example matches true
true
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('breakStmt0')" > < a name = "breakStmt0Anchor" > breakStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html" > BreakStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "breakStmt0" > < pre > Matches break statements.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Given
while (true) { break; }
breakStmt()
matches 'break'
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('cStyleCastExpr0')" > < a name = "cStyleCastExpr0Anchor" > cStyleCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CStyleCastExpr.html" > CStyleCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "cStyleCastExpr0" > < pre > Matches a C-style cast expression.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example: Matches (int*) 2.2f in
int i = (int) 2.2f;
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('callExpr0')" > < a name = "callExpr0Anchor" > callExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "callExpr0" > < pre > Matches call expressions.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example matches x.y() and y()
X x;
x.y();
y();
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('castExpr0')" > < a name = "castExpr0Anchor" > castExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html" > CastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "castExpr0" > < pre > Matches any cast nodes of Clang's AST.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example: castExpr() matches each of the following:
(int) 3;
const_cast< Expr *> (SubExpr);
char c = 0;
but does not match
int i = (0);
int k = 0;
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('catchStmt0')" > < a name = "catchStmt0Anchor" > catchStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html" > CXXCatchStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "catchStmt0" > < pre > Matches catch statements.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
try {} catch(int i) {}
catchStmt()
matches 'catch(int i)'
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('characterLiteral0')" > < a name = "characterLiteral0Anchor" > characterLiteral< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "characterLiteral0" > < pre > Matches character literals (also matches wchar_t).
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
though.
2012-08-21 04:54:03 +08:00
2012-12-04 20:08:08 +08:00
Example matches 'a', L'a'
char ch = 'a'; wchar_t chw = L'a';
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('compoundStmt0')" > < a name = "compoundStmt0Anchor" > compoundStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html" > CompoundStmt< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "compoundStmt0" > < pre > Matches compound statements.
2012-08-21 04:54:03 +08:00
Example matches '{}' and '{{}}'in 'for (;;) {{}}'
for (;;) {{}}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('conditionalOperator0')" > < a name = "conditionalOperator0Anchor" > conditionalOperator< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html" > ConditionalOperator< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "conditionalOperator0" > < pre > Matches conditional operator expressions.
Example matches a ? b : c
(a ? b : c) + 42
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('constCastExpr0')" > < a name = "constCastExpr0Anchor" > constCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html" > CXXConstCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "constCastExpr0" > < pre > Matches a const_cast expression.
Example: Matches const_cast< int*> (& r) in
int n = 42;
const int & r(n);
int* p = const_cast< int*> (& r);
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('constructExpr0')" > < a name = "constructExpr0Anchor" > constructExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "constructExpr0" > < pre > Matches constructor call expressions (including implicit ones).
2012-08-21 04:54:03 +08:00
Example matches string(ptr, n) and ptr within arguments of f
2012-08-27 07:55:24 +08:00
(matcher = constructExpr())
2012-08-21 04:54:03 +08:00
void f(const string & a, const string & b);
char *ptr;
int n;
f(string(ptr, n), ptr);
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('continueStmt0')" > < a name = "continueStmt0Anchor" > continueStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ContinueStmt.html" > ContinueStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "continueStmt0" > < pre > Matches continue statements.
Given
while (true) { continue; }
continueStmt()
matches 'continue'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('declRefExpr0')" > < a name = "declRefExpr0Anchor" > declRefExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html" > DeclRefExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "declRefExpr0" > < pre > Matches expressions that refer to declarations.
2012-08-21 04:54:03 +08:00
Example matches x in if (x)
bool x;
if (x) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('declStmt0')" > < a name = "declStmt0Anchor" > declStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html" > DeclStmt< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "declStmt0" > < pre > Matches declaration statements.
2012-08-21 04:54:03 +08:00
Given
int a;
2012-08-27 07:55:24 +08:00
declStmt()
2012-08-21 04:54:03 +08:00
matches 'int a'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('defaultArgExpr0')" > < a name = "defaultArgExpr0Anchor" > defaultArgExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html" > CXXDefaultArgExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "defaultArgExpr0" > < pre > Matches the value of a default argument at the call site.
2012-08-21 04:54:03 +08:00
Example matches the CXXDefaultArgExpr placeholder inserted for the
default value of the second parameter in the call expression f(42)
2012-08-27 07:55:24 +08:00
(matcher = defaultArgExpr())
2012-08-21 04:54:03 +08:00
void f(int x, int y = 0);
f(42);
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('deleteExpr0')" > < a name = "deleteExpr0Anchor" > deleteExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html" > CXXDeleteExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "deleteExpr0" > < pre > Matches delete expressions.
2012-08-21 04:54:03 +08:00
Given
delete X;
2012-08-27 07:55:24 +08:00
deleteExpr()
2012-08-21 04:54:03 +08:00
matches 'delete X'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('doStmt0')" > < a name = "doStmt0Anchor" > doStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html" > DoStmt< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "doStmt0" > < pre > Matches do statements.
Given
do {} while (true);
doStmt()
matches 'do {} while(true)'
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('dynamicCastExpr0')" > < a name = "dynamicCastExpr0Anchor" > dynamicCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html" > CXXDynamicCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "dynamicCastExpr0" > < pre > Matches a dynamic_cast expression.
Example:
dynamicCastExpr()
matches
dynamic_cast< D*> (& b);
in
struct B { virtual ~B() {} }; struct D : B {};
B b;
D* p = dynamic_cast< D*> (& b);
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('explicitCastExpr0')" > < a name = "explicitCastExpr0Anchor" > explicitCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html" > ExplicitCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "explicitCastExpr0" > < pre > Matches explicit cast expressions.
Matches any cast expression written in user code, whether it be a
C-style cast, a functional-style cast, or a keyword cast.
Does not match implicit conversions.
Note: the name "explicitCast" is chosen to match Clang's terminology, as
Clang uses the term "cast" to apply to implicit conversions as well as to
actual cast expressions.
hasDestinationType.
Example: matches all five of the casts in
int((int)(reinterpret_cast< int> (static_cast< int> (const_cast< int> (42)))))
but does not match the implicit conversion in
long ell = 42;
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('expr0')" > < a name = "expr0Anchor" > expr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "expr0" > < pre > Matches expressions.
2012-08-21 04:54:03 +08:00
Example matches x()
void f() { x(); }
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('forRangeStmt0')" > < a name = "forRangeStmt0Anchor" > forRangeStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html" > CXXForRangeStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "forRangeStmt0" > < pre > Matches range-based for statements.
forRangeStmt() matches 'for (auto a : i)'
int i[] = {1, 2, 3}; for (auto a : i);
for(int j = 0; j < 5; ++j);
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('forStmt0')" > < a name = "forStmt0Anchor" > forStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html" > ForStmt< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "forStmt0" > < pre > Matches for statements.
Example matches 'for (;;) {}'
for (;;) {}
2012-12-04 20:08:08 +08:00
int i[] = {1, 2, 3}; for (auto a : i);
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('functionalCastExpr0')" > < a name = "functionalCastExpr0Anchor" > functionalCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html" > CXXFunctionalCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "functionalCastExpr0" > < pre > Matches functional cast expressions
Example: Matches Foo(bar);
Foo f = bar;
Foo g = (Foo) bar;
Foo h = Foo(bar);
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('gotoStmt0')" > < a name = "gotoStmt0Anchor" > gotoStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1GotoStmt.html" > GotoStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "gotoStmt0" > < pre > Matches goto statements.
Given
goto FOO;
FOO: bar();
gotoStmt()
matches 'goto FOO'
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('ifStmt0')" > < a name = "ifStmt0Anchor" > ifStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html" > IfStmt< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ifStmt0" > < pre > Matches if statements.
Example matches 'if (x) {}'
if (x) {}
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('implicitCastExpr0')" > < a name = "implicitCastExpr0Anchor" > implicitCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html" > ImplicitCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "implicitCastExpr0" > < pre > Matches the implicit cast nodes of Clang's AST.
This matches many different places, including function call return value
eliding, as well as any type conversions.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('initListExpr0')" > < a name = "initListExpr0Anchor" > initListExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html" > InitListExpr< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "initListExpr0" > < pre > Matches init list expressions.
Given
int a[] = { 1, 2 };
struct B { int x, y; };
B b = { 5, 6 };
initList()
matches "{ 1, 2 }" and "{ 5, 6 }"
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('integerLiteral0')" > < a name = "integerLiteral0Anchor" > integerLiteral< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "integerLiteral0" > < pre > Matches integer literals of all sizes encodings.
Not matching character-encoded integers such as L'a'.
Example matches 1, 1L, 0x1, 1U
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('labelStmt0')" > < a name = "labelStmt0Anchor" > labelStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html" > LabelStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "labelStmt0" > < pre > Matches label statements.
Given
goto FOO;
FOO: bar();
labelStmt()
matches 'FOO:'
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('lambdaExpr0')" > < a name = "lambdaExpr0Anchor" > lambdaExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html" > LambdaExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "lambdaExpr0" > < pre > Matches lambda expressions.
Example matches [& ](){return 5;}
[& ](){return 5;}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('materializeTemporaryExpr0')" > < a name = "materializeTemporaryExpr0Anchor" > materializeTemporaryExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html" > MaterializeTemporaryExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "materializeTemporaryExpr0" > < pre > Matches nodes where temporaries are materialized.
Example: Given
struct T {void func()};
T f();
void g(T);
materializeTemporaryExpr() matches 'f()' in these statements
T u(f());
g(f());
but does not match
f();
f().func();
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('memberCallExpr0')" > < a name = "memberCallExpr0Anchor" > memberCallExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html" > CXXMemberCallExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "memberCallExpr0" > < pre > Matches member call expressions.
2012-08-21 04:54:03 +08:00
Example matches x.y()
X x;
x.y();
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('memberExpr0')" > < a name = "memberExpr0Anchor" > memberExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "memberExpr0" > < pre > Matches member expressions.
2012-08-21 04:54:03 +08:00
Given
class Y {
void x() { this-> x(); x(); Y y; y.x(); a; this-> b; Y::b; }
int a; static int b;
};
2012-08-27 07:55:24 +08:00
memberExpr()
2012-08-21 04:54:03 +08:00
matches this-> x, x, y.x, a, this-> b
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('newExpr0')" > < a name = "newExpr0Anchor" > newExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html" > CXXNewExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "newExpr0" > < pre > Matches new expressions.
2012-08-21 04:54:03 +08:00
Given
new X;
2012-08-27 07:55:24 +08:00
newExpr()
2012-08-21 04:54:03 +08:00
matches 'new X'.
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('nullPtrLiteralExpr0')" > < a name = "nullPtrLiteralExpr0Anchor" > nullPtrLiteralExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html" > CXXNullPtrLiteralExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "nullPtrLiteralExpr0" > < pre > Matches nullptr literal.
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('nullStmt0')" > < a name = "nullStmt0Anchor" > nullStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NullStmt.html" > NullStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "nullStmt0" > < pre > Matches null statements.
foo();;
nullStmt()
matches the second ';'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('operatorCallExpr0')" > < a name = "operatorCallExpr0Anchor" > operatorCallExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html" > CXXOperatorCallExpr< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "operatorCallExpr0" > < pre > Matches overloaded operator calls.
2012-08-21 04:54:03 +08:00
Note that if an operator isn't overloaded, it won't match. Instead, use
binaryOperator matcher.
Currently it does not match operators such as new delete.
FIXME: figure out why these do not match?
Example matches both operator< < ((o < < b), c) and operator< < (o, b)
2012-08-27 07:55:24 +08:00
(matcher = operatorCallExpr())
2012-08-21 04:54:03 +08:00
ostream & operator< < (ostream & out, int i) { };
ostream & o; int b = 1, c = 1;
o < < b < < c;
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('reinterpretCastExpr0')" > < a name = "reinterpretCastExpr0Anchor" > reinterpretCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html" > CXXReinterpretCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "reinterpretCastExpr0" > < pre > Matches a reinterpret_cast expression.
Either the source expression or the destination type can be matched
using has(), but hasDestinationType() is more specific and can be
more readable.
Example matches reinterpret_cast< char*> (& p) in
void* p = reinterpret_cast< char*> (& p);
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('returnStmt0')" > < a name = "returnStmt0Anchor" > returnStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html" > ReturnStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "returnStmt0" > < pre > Matches return statements.
Given
return 1;
returnStmt()
matches 'return 1'
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('staticCastExpr0')" > < a name = "staticCastExpr0Anchor" > staticCastExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html" > CXXStaticCastExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "staticCastExpr0" > < pre > Matches a C++ static_cast expression.
hasDestinationType
reinterpretCast
Example:
staticCastExpr()
matches
static_cast< long> (8)
in
long eight(static_cast< long> (8));
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('stmt0')" > < a name = "stmt0Anchor" > stmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > ...< / td > < / tr >
2012-08-27 07:55:24 +08:00
< tr > < td colspan = "4" class = "doc" id = "stmt0" > < pre > Matches statements.
2012-08-21 04:54:03 +08:00
Given
{ ++a; }
2012-08-27 07:55:24 +08:00
stmt()
2012-08-21 04:54:03 +08:00
matches both the compound statement '{ ++a; }' and '++a'.
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('stringLiteral0')" > < a name = "stringLiteral0Anchor" > stringLiteral< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html" > StringLiteral< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "stringLiteral0" > < pre > Matches string literals (also matches wide string literals).
Example matches "abcd", L"abcd"
char *s = "abcd"; wchar_t *ws = L"abcd"
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('switchCase0')" > < a name = "switchCase0Anchor" > switchCase< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html" > SwitchCase< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "switchCase0" > < pre > Matches case and default statements inside switch statements.
Given
switch(a) { case 42: break; default: break; }
switchCase()
matches 'case 42: break;' and 'default: break;'.
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('switchStmt0')" > < a name = "switchStmt0Anchor" > switchStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html" > SwitchStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "switchStmt0" > < pre > Matches switch statements.
Given
switch(a) { case 42: break; default: break; }
switchStmt()
matches 'switch(a)'.
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('thisExpr0')" > < a name = "thisExpr0Anchor" > thisExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html" > CXXThisExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "thisExpr0" > < pre > Matches implicit and explicit this expressions.
Example matches the implicit this expression in "return i".
(matcher = thisExpr())
struct foo {
int i;
int f() { return i; }
};
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('throwExpr0')" > < a name = "throwExpr0Anchor" > throwExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXThrowExpr.html" > CXXThrowExpr< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "throwExpr0" > < pre > Matches throw expressions.
try { throw 5; } catch(int i) {}
throwExpr()
matches 'throw 5'
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('tryStmt0')" > < a name = "tryStmt0Anchor" > tryStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html" > CXXTryStmt< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "tryStmt0" > < pre > Matches try statements.
try {} catch(int i) {}
tryStmt()
matches 'try {}'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('unaryExprOrTypeTraitExpr0')" > < a name = "unaryExprOrTypeTraitExpr0Anchor" > unaryExprOrTypeTraitExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html" > UnaryExprOrTypeTraitExpr< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "unaryExprOrTypeTraitExpr0" > < pre > Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
Given
Foo x = bar;
int y = sizeof(x) + alignof(x);
unaryExprOrTypeTraitExpr()
matches sizeof(x) and alignof(x)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('unaryOperator0')" > < a name = "unaryOperator0Anchor" > unaryOperator< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html" > UnaryOperator< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "unaryOperator0" > < pre > Matches unary operator expressions.
Example matches !a
!a || b
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('userDefinedLiteral0')" > < a name = "userDefinedLiteral0Anchor" > userDefinedLiteral< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UserDefinedLiteral.html" > UserDefinedLiteral< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "userDefinedLiteral0" > < pre > Matches user defined literal operator call.
Example match: "foo"_suffix
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('whileStmt0')" > < a name = "whileStmt0Anchor" > whileStmt< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html" > WhileStmt< / a > > ...< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "whileStmt0" > < pre > Matches while statements.
Given
while (true) {}
whileStmt()
matches 'while (true) {}'.
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html" > TypeLoc< / a > > < / td > < td class = "name" onclick = "toggle('typeLoc0')" > < a name = "typeLoc0Anchor" > typeLoc< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html" > TypeLoc< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "typeLoc0" > < pre > Matches TypeLocs in the clang AST.
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Type.html" > Type< / a > > < / td > < td class = "name" onclick = "toggle('type0')" > < a name = "type0Anchor" > type< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Type.html" > Type< / a > > ...< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "type0" > < pre > Matches Types in the clang AST.
< / pre > < / td > < / tr >
2012-08-21 04:54:03 +08:00
<!-- END_DECL_MATCHERS -->
< / table >
<!-- ======================================================================= -->
< h2 id = "narrowing-matchers" > Narrowing Matchers< / h2 >
<!-- ======================================================================= -->
< p > Narrowing matchers match certain attributes on the current node, thus
narrowing down the set of nodes of the current type to match on.< / p >
< p > There are special logical narrowing matchers (allOf, anyOf, anything and unless)
which allow users to create more powerful match expressions.< / p >
< table >
< tr style = "text-align:left" > < th > Return type< / th > < th > Name< / th > < th > Parameters< / th > < / tr >
<!-- START_NARROWING_MATCHERS -->
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('allOf0')" > < a name = "allOf0Anchor" > allOf< / a > < / td > < td > Matcher< *> P1, Matcher< *> P2< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "allOf0" > < pre > Matches if all given matchers match.
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('anyOf0')" > < a name = "anyOf0Anchor" > anyOf< / a > < / td > < td > Matcher< *> P1, Matcher< *> P2< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "anyOf0" > < pre > Matches if any of the given matchers matches.
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('anything0')" > < a name = "anything0Anchor" > anything< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "anything0" > < pre > Matches any node.
Useful when another matcher requires a child matcher, but there's no
additional constraint. This will often be used with an explicit conversion
to an internal::Matcher< > type such as TypeMatcher.
Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
"int* p" and "void f()" in
int* p;
void f();
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('unless0')" > < a name = "unless0Anchor" > unless< / a > < / td > < td > Matcher< *> InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "unless0" > < pre > Matches if the provided matcher does not match.
2012-08-27 07:55:24 +08:00
Example matches Y (matcher = recordDecl(unless(hasName("X"))))
2012-08-21 04:54:03 +08:00
class X {};
class Y {};
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html" > BinaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasOperatorName0')" > < a name = "hasOperatorName0Anchor" > hasOperatorName< / a > < / td > < td > std::string Name< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasOperatorName0" > < pre > Matches the operator Name of operator expressions (binary or
unary).
Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
!(a || b)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< CXXBoolLiteral> < / td > < td class = "name" onclick = "toggle('equals2')" > < a name = "equals2Anchor" > equals< / a > < / td > < td > ValueT Value< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "equals2" > < pre > Matches literals that are equal to the given value.
Example matches true (matcher = boolLiteral(equals(true)))
true
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > , Matcher< CXXBoolLiteral> ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html" > FloatingLiteral< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html" > CXXConstructorDecl< / a > > < / td > < td class = "name" onclick = "toggle('isImplicit0')" > < a name = "isImplicit0Anchor" > isImplicit< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isImplicit0" > < pre > Matches a constructor declaration that has been implicitly added
by the compiler (eg. implicit defaultcopy constructors).
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html" > CXXCtorInitializer< / a > > < / td > < td class = "name" onclick = "toggle('isWritten0')" > < a name = "isWritten0Anchor" > isWritten< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isWritten0" > < pre > Matches a contructor initializer if it is explicitly written in
code (as opposed to implicitly added by the compiler).
Given
struct Foo {
Foo() { }
Foo(int) : foo_("A") { }
string foo_;
};
2012-08-27 07:55:24 +08:00
constructorDecl(hasAnyConstructorInitializer(isWritten()))
2012-08-21 04:54:03 +08:00
will match Foo(int), but not Foo()
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html" > CXXOperatorCallExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasOverloadedOperatorName0')" > < a name = "hasOverloadedOperatorName0Anchor" > hasOverloadedOperatorName< / a > < / td > < td > std::string Name< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasOverloadedOperatorName0" > < pre > Matches overloaded operator names.
Matches overloaded operator names specified in strings without the
"operator" prefix, such as "< < ", for OverloadedOperatorCall's.
Example matches a < < b
2012-08-27 07:55:24 +08:00
(matcher == operatorCallExpr(hasOverloadedOperatorName("< < ")))
2012-08-21 04:54:03 +08:00
a < < b;
c & & d; assuming both operator< <
and operator& & are overloaded somewhere.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isDerivedFrom1')" > < a name = "isDerivedFrom1Anchor" > isDerivedFrom< / a > < / td > < td > StringRef BaseName< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isDerivedFrom1" > < pre > Overloaded method as shortcut for isDerivedFrom(hasName(...)).
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isExplicitTemplateSpecialization0')" > < a name = "isExplicitTemplateSpecialization0Anchor" > isExplicitTemplateSpecialization< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isExplicitTemplateSpecialization0" > < pre > Matches explicit template specializations of function, class, or
static member variable template instantiations.
Given
template< typename T> void A(T t) { }
template< > void A(int N) { }
2012-08-27 07:55:24 +08:00
functionDecl(isExplicitTemplateSpecialization())
2012-08-21 04:54:03 +08:00
matches the specialization A< int> ().
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isSameOrDerivedFrom1')" > < a name = "isSameOrDerivedFrom1Anchor" > isSameOrDerivedFrom< / a > < / td > < td > StringRef BaseName< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "isSameOrDerivedFrom1" > < pre > Overloaded method as shortcut for
isSameOrDerivedFrom(hasName(...)).
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isTemplateInstantiation0')" > < a name = "isTemplateInstantiation0Anchor" > isTemplateInstantiation< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isTemplateInstantiation0" > < pre > Matches template instantiations of function, class, or static
member variable template instantiations.
Given
template < typename T> class X {}; class A {}; X< A> x;
or
template < typename T> class X {}; class A {}; template class X< A> ;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
matches the template instantiation of X< A> .
But given
template < typename T> class X {}; class A {};
template < > class X< A> {}; X< A> x;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
does not match, as X< A> is an explicit template specialization.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > < / td > < td class = "name" onclick = "toggle('argumentCountIs0')" > < a name = "argumentCountIs0Anchor" > argumentCountIs< / a > < / td > < td > unsigned N< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "argumentCountIs0" > < pre > Checks that a call expression or a constructor call expression has
a specific number of arguments (including absent default arguments).
2012-08-27 07:55:24 +08:00
Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
2012-08-21 04:54:03 +08:00
void f(int x, int y);
f(0, 0);
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > < / td > < td class = "name" onclick = "toggle('equals3')" > < a name = "equals3Anchor" > equals< / a > < / td > < td > ValueT Value< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "equals3" > < pre > Matches literals that are equal to the given value.
Example matches true (matcher = boolLiteral(equals(true)))
true
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > , Matcher< CXXBoolLiteral> ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html" > FloatingLiteral< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html" > CompoundStmt< / a > > < / td > < td class = "name" onclick = "toggle('statementCountIs0')" > < a name = "statementCountIs0Anchor" > statementCountIs< / a > < / td > < td > unsigned N< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "statementCountIs0" > < pre > Checks that a compound statement contains a specific number of
child statements.
Example: Given
{ for (;;) {} }
2012-08-27 07:55:24 +08:00
compoundStmt(statementCountIs(0)))
2012-08-21 04:54:03 +08:00
matches '{}'
but does not match the outer compound statement.
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html" > ConstantArrayType< / a > > < / td > < td class = "name" onclick = "toggle('hasSize0')" > < a name = "hasSize0Anchor" > hasSize< / a > < / td > < td > unsigned N< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasSize0" > < pre > Matches ConstantArrayType nodes that have the specified size.
Given
int a[42];
int b[2 * 21];
int c[41], d[43];
constantArrayType(hasSize(42))
matches "int a[42]" and "int b[2 * 21]"
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html" > DeclStmt< / a > > < / td > < td class = "name" onclick = "toggle('declCountIs0')" > < a name = "declCountIs0Anchor" > declCountIs< / a > < / td > < td > unsigned N< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "declCountIs0" > < pre > Matches declaration statements that contain a specific number of
declarations.
Example: Given
int a, b;
int c;
int d = 2, e;
declCountIs(2)
matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html" > FloatingLiteral< / a > > < / td > < td class = "name" onclick = "toggle('equals1')" > < a name = "equals1Anchor" > equals< / a > < / td > < td > ValueT Value< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "equals1" > < pre > Matches literals that are equal to the given value.
Example matches true (matcher = boolLiteral(equals(true)))
true
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > , Matcher< CXXBoolLiteral> ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html" > FloatingLiteral< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('isDefinition0')" > < a name = "isDefinition0Anchor" > isDefinition< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isDefinition0" > < pre > Matches if a declaration has a body attached.
Example matches A, va, fa
class A {};
class B; Doesn't match, as it has no body.
int va;
extern int vb; Doesn't match, as it doesn't define the variable.
void fa() {}
void fb(); Doesn't match, as it has no body.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html" > TagDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('isExplicitTemplateSpecialization2')" > < a name = "isExplicitTemplateSpecialization2Anchor" > isExplicitTemplateSpecialization< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isExplicitTemplateSpecialization2" > < pre > Matches explicit template specializations of function, class, or
static member variable template instantiations.
Given
template< typename T> void A(T t) { }
template< > void A(int N) { }
2012-08-27 07:55:24 +08:00
functionDecl(isExplicitTemplateSpecialization())
2012-08-21 04:54:03 +08:00
matches the specialization A< int> ().
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('isExternC0')" > < a name = "isExternC0Anchor" > isExternC< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isExternC0" > < pre > Matches extern "C" function declarations.
Given:
extern "C" void f() {}
extern "C" { void g() {} }
void h() {}
2012-08-27 07:55:24 +08:00
functionDecl(isExternC())
2012-08-21 04:54:03 +08:00
matches the declaration of f and g, but not the declaration h
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('isTemplateInstantiation2')" > < a name = "isTemplateInstantiation2Anchor" > isTemplateInstantiation< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isTemplateInstantiation2" > < pre > Matches template instantiations of function, class, or static
member variable template instantiations.
Given
template < typename T> class X {}; class A {}; X< A> x;
or
template < typename T> class X {}; class A {}; template class X< A> ;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
matches the template instantiation of X< A> .
But given
template < typename T> class X {}; class A {};
template < > class X< A> {}; X< A> x;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
does not match, as X< A> is an explicit template specialization.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('parameterCountIs0')" > < a name = "parameterCountIs0Anchor" > parameterCountIs< / a > < / td > < td > unsigned N< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "parameterCountIs0" > < pre > Matches FunctionDecls that have a specific parameter count.
Given
void f(int i) {}
void g(int i, int j) {}
functionDecl(parameterCountIs(2))
matches g(int i, int j) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > > < / td > < td class = "name" onclick = "toggle('equals0')" > < a name = "equals0Anchor" > equals< / a > < / td > < td > ValueT Value< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "equals0" > < pre > Matches literals that are equal to the given value.
Example matches true (matcher = boolLiteral(equals(true)))
true
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html" > CharacterLiteral< / a > > , Matcher< CXXBoolLiteral> ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html" > FloatingLiteral< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html" > IntegerLiteral< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > > < / td > < td class = "name" onclick = "toggle('isArrow0')" > < a name = "isArrow0Anchor" > isArrow< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isArrow0" > < pre > Matches member expressions that are called with '-> ' as opposed
to '.'.
Member calls on the implicit this pointer match as called with '-> '.
Given
class Y {
void x() { this-> x(); x(); Y y; y.x(); a; this-> b; Y::b; }
int a;
static int b;
};
2012-08-27 07:55:24 +08:00
memberExpr(isArrow())
2012-08-21 04:54:03 +08:00
matches this-> x, x, y.x, a, this-> b
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasName0')" > < a name = "hasName0Anchor" > hasName< / a > < / td > < td > std::string Name< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasName0" > < pre > Matches NamedDecl nodes that have the specified name.
Supports specifying enclosing namespaces or classes by prefixing the name
with '< enclosing> ::'.
Does not match typedefs of an underlying type with the given name.
Example matches X (Name == "X")
class X;
Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
namespace a { namespace b { class X; } }
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > < / td > < td class = "name" onclick = "toggle('matchesName0')" > < a name = "matchesName0Anchor" > matchesName< / a > < / td > < td > std::string RegExp< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "matchesName0" > < pre > Matches NamedDecl nodes whose full names partially match the
given RegExp.
Supports specifying enclosing namespaces or classes by
prefixing the name with '< enclosing> ::'. Does not match typedefs
of an underlying type with the given name.
Example matches X (regexp == "::X")
class X;
Example matches X (regexp is one of "::X", "^foo::.*X", among others)
namespace foo { namespace bar { class X; } }
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('asString0')" > < a name = "asString0Anchor" > asString< / a > < / td > < td > std::string Name< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "asString0" > < pre > Matches if the matched type is represented by the given string.
Given
class Y { public: void x(); };
void z() { Y* y; y-> x(); }
2012-08-27 07:55:24 +08:00
callExpr(on(hasType(asString("class Y *"))))
2012-08-21 04:54:03 +08:00
matches y-> x()
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('isConstQualified0')" > < a name = "isConstQualified0Anchor" > isConstQualified< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isConstQualified0" > < pre > Matches QualType nodes that are const-qualified, i.e., that
include "top-level" const.
Given
void a(int);
void b(int const);
void c(const int);
void d(const int*);
void e(int const) {};
2012-08-27 07:55:24 +08:00
functionDecl(hasAnyParameter(hasType(isConstQualified())))
2012-08-21 04:54:03 +08:00
matches "void b(int const)", "void c(const int)" and
"void e(int const) {}". It does not match d as there
is no top-level const on the parameter type "const int *".
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('isInteger0')" > < a name = "isInteger0Anchor" > isInteger< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isInteger0" > < pre > Matches QualType nodes that are of integer type.
Given
void a(int);
void b(long);
void c(double);
2012-08-27 07:55:24 +08:00
functionDecl(hasAnyParameter(hasType(isInteger())))
2012-08-21 04:54:03 +08:00
matches "a(int)", "b(long)", but not "c(double)".
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html" > TagDecl< / a > > < / td > < td class = "name" onclick = "toggle('isDefinition2')" > < a name = "isDefinition2Anchor" > isDefinition< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isDefinition2" > < pre > Matches if a declaration has a body attached.
Example matches A, va, fa
class A {};
class B; Doesn't match, as it has no body.
int va;
extern int vb; Doesn't match, as it doesn't define the variable.
void fa() {}
void fb(); Doesn't match, as it has no body.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html" > TagDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html" > UnaryExprOrTypeTraitExpr< / a > > < / td > < td class = "name" onclick = "toggle('ofKind0')" > < a name = "ofKind0Anchor" > ofKind< / a > < / td > < td > UnaryExprOrTypeTrait Kind< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ofKind0" > < pre > Matches unary expressions of a certain kind.
Given
int x;
int s = sizeof(x) + alignof(x)
unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
matches sizeof(x)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html" > UnaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasOperatorName1')" > < a name = "hasOperatorName1Anchor" > hasOperatorName< / a > < / td > < td > std::string Name< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasOperatorName1" > < pre > Matches the operator Name of operator expressions (binary or
unary).
Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
!(a || b)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > < / td > < td class = "name" onclick = "toggle('isDefinition1')" > < a name = "isDefinition1Anchor" > isDefinition< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isDefinition1" > < pre > Matches if a declaration has a body attached.
Example matches A, va, fa
class A {};
class B; Doesn't match, as it has no body.
int va;
extern int vb; Doesn't match, as it doesn't define the variable.
void fa() {}
void fb(); Doesn't match, as it has no body.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html" > TagDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > < / td > < td class = "name" onclick = "toggle('isExplicitTemplateSpecialization1')" > < a name = "isExplicitTemplateSpecialization1Anchor" > isExplicitTemplateSpecialization< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isExplicitTemplateSpecialization1" > < pre > Matches explicit template specializations of function, class, or
static member variable template instantiations.
Given
template< typename T> void A(T t) { }
template< > void A(int N) { }
2012-08-27 07:55:24 +08:00
functionDecl(isExplicitTemplateSpecialization())
2012-08-21 04:54:03 +08:00
matches the specialization A< int> ().
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > < / td > < td class = "name" onclick = "toggle('isTemplateInstantiation1')" > < a name = "isTemplateInstantiation1Anchor" > isTemplateInstantiation< / a > < / td > < td > < / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isTemplateInstantiation1" > < pre > Matches template instantiations of function, class, or static
member variable template instantiations.
Given
template < typename T> class X {}; class A {}; X< A> x;
or
template < typename T> class X {}; class A {}; template class X< A> ;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
matches the template instantiation of X< A> .
But given
template < typename T> class X {}; class A {};
template < > class X< A> {}; X< A> x;
2012-08-27 07:55:24 +08:00
recordDecl(hasName("::X"), isTemplateInstantiation())
2012-08-21 04:54:03 +08:00
does not match, as X< A> is an explicit template specialization.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > >
< / pre > < / td > < / tr >
<!-- END_NARROWING_MATCHERS -->
< / table >
<!-- ======================================================================= -->
< h2 id = "traversal-matchers" > AST Traversal Matchers< / h2 >
<!-- ======================================================================= -->
< p > Traversal matchers specify the relationship to other nodes that are
reachable from the current node.< / p >
< p > Note that there are special traversal matchers (has, hasDescendant, forEach and
forEachDescendant) which work on all nodes and allow users to write more generic
match expressions.< / p >
< table >
< tr style = "text-align:left" > < th > Return type< / th > < th > Name< / th > < th > Parameters< / th > < / tr >
<!-- START_TRAVERSAL_MATCHERS -->
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('forEach0')" > < a name = "forEach0Anchor" > forEach< / a > < / td > < td > Matcher< ChildT> ChildMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "forEach0" > < pre > Matches AST nodes that have child AST nodes that match the
provided matcher.
2012-08-27 07:55:24 +08:00
Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
2012-08-21 04:54:03 +08:00
class X {}; Matches X, because X::X is a class of name X inside X.
class Y { class X {}; };
class Z { class Y { class X {}; }; }; Does not match Z.
ChildT must be an AST base type.
As opposed to 'has', 'forEach' will cause a match for each result that
matches instead of only on the first one.
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('forEachDescendant0')" > < a name = "forEachDescendant0Anchor" > forEachDescendant< / a > < / td > < td > Matcher< DescendantT> DescendantMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "forEachDescendant0" > < pre > Matches AST nodes that have descendant AST nodes that match the
provided matcher.
Example matches X, A, B, C
2012-08-27 07:55:24 +08:00
(matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
2012-08-21 04:54:03 +08:00
class X {}; Matches X, because X::X is a class of name X inside X.
class A { class X {}; };
class B { class C { class X {}; }; };
DescendantT must be an AST base type.
As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
each result that matches instead of only on the first one.
Note: Recursively combined ForEachDescendant can cause many matches:
2012-08-27 07:55:24 +08:00
recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
2012-08-21 04:54:03 +08:00
will match 10 times (plus injected class name matches) on:
class A { class B { class C { class D { class E {}; }; }; }; };
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('has0')" > < a name = "has0Anchor" > has< / a > < / td > < td > Matcher< ChildT> ChildMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "has0" > < pre > Matches AST nodes that have child AST nodes that match the
provided matcher.
2012-08-27 07:55:24 +08:00
Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
2012-08-21 04:54:03 +08:00
class X {}; Matches X, because X::X is a class of name X inside X.
class Y { class X {}; };
class Z { class Y { class X {}; }; }; Does not match Z.
ChildT must be an AST base type.
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('hasAncestor0')" > < a name = "hasAncestor0Anchor" > hasAncestor< / a > < / td > < td > Matcher< AncestorT> AncestorMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasAncestor0" > < pre > Matches AST nodes that have an ancestor that matches the provided
matcher.
Given
void f() { if (true) { int x = 42; } }
void g() { for (;;) { int x = 43; } }
2012-12-04 20:08:08 +08:00
expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43.
2012-09-07 21:10:32 +08:00
Usable as: Any Matcher
< / pre > < / td > < / tr >
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('hasDescendant0')" > < a name = "hasDescendant0Anchor" > hasDescendant< / a > < / td > < td > Matcher< DescendantT> DescendantMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasDescendant0" > < pre > Matches AST nodes that have descendant AST nodes that match the
provided matcher.
Example matches X, Y, Z
2012-08-27 07:55:24 +08:00
(matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
2012-08-21 04:54:03 +08:00
class X {}; Matches X, because X::X is a class of name X inside X.
class Y { class X {}; };
class Z { class Y { class X {}; }; };
DescendantT must be an AST base type.
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher< *> < / td > < td class = "name" onclick = "toggle('hasParent0')" > < a name = "hasParent0Anchor" > hasParent< / a > < / td > < td > Matcher< ParentT> ParentMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasParent0" > < pre > Matches AST nodes that have a parent that matches the provided
matcher.
Given
void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }
compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
Usable as: Any Matcher
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html" > ArraySubscriptExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasBase0')" > < a name = "hasBase0Anchor" > hasBase< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasBase0" > < pre > Matches the base expression of an array subscript expression.
Given
int i[5];
void f() { i[1] = 42; }
2012-08-27 07:55:24 +08:00
arraySubscriptExpression(hasBase(implicitCastExpr(
hasSourceExpression(declRefExpr()))))
matches i[1] with the declRefExpr() matching i
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html" > ArraySubscriptExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasIndex0')" > < a name = "hasIndex0Anchor" > hasIndex< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasIndex0" > < pre > Matches the index expression of an array subscript expression.
Given
int i[5];
void f() { i[1] = 42; }
arraySubscriptExpression(hasIndex(integerLiteral()))
matches i[1] with the integerLiteral() matching 1
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html" > BinaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasEitherOperand0')" > < a name = "hasEitherOperand0Anchor" > hasEitherOperand< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasEitherOperand0" > < pre > Matches if either the left hand side or the right hand side of a
binary operator matches.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html" > BinaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasLHS0')" > < a name = "hasLHS0Anchor" > hasLHS< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasLHS0" > < pre > Matches the left hand side of binary operator expressions.
Example matches a (matcher = binaryOperator(hasLHS()))
a || b
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html" > BinaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasRHS0')" > < a name = "hasRHS0Anchor" > hasRHS< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasRHS0" > < pre > Matches the right hand side of binary operator expressions.
Example matches b (matcher = binaryOperator(hasRHS()))
a || b
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasDeclaration1')" > < a name = "hasDeclaration1Anchor" > hasDeclaration< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasDeclaration1" > < pre > Matches a type if the declaration of the type matches the given
2012-08-21 04:54:03 +08:00
matcher.
2012-12-04 20:08:08 +08:00
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > >
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html" > CXXConstructorDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasAnyConstructorInitializer0')" > < a name = "hasAnyConstructorInitializer0Anchor" > hasAnyConstructorInitializer< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html" > CXXCtorInitializer< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnyConstructorInitializer0" > < pre > Matches a constructor initializer.
Given
struct Foo {
Foo() : foo_(1) { }
int foo_;
};
2012-08-27 07:55:24 +08:00
recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
2012-08-21 04:54:03 +08:00
record matches Foo, hasAnyConstructorInitializer matches foo_(1)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html" > CXXCtorInitializer< / a > > < / td > < td class = "name" onclick = "toggle('forField0')" > < a name = "forField0Anchor" > forField< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html" > FieldDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "forField0" > < pre > Matches the field declaration of a constructor initializer.
Given
struct Foo {
Foo() : foo_(1) { }
int foo_;
};
2012-08-27 07:55:24 +08:00
recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
2012-08-21 04:54:03 +08:00
forField(hasName("foo_"))))))
matches Foo
with forField matching foo_
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html" > CXXCtorInitializer< / a > > < / td > < td class = "name" onclick = "toggle('withInitializer0')" > < a name = "withInitializer0Anchor" > withInitializer< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "withInitializer0" > < pre > Matches the initializer expression of a constructor initializer.
Given
struct Foo {
Foo() : foo_(1) { }
int foo_;
};
2012-08-27 07:55:24 +08:00
recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
2012-08-21 04:54:03 +08:00
withInitializer(integerLiteral(equals(1)))))))
matches Foo
with withInitializer matching (1)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html" > CXXMemberCallExpr< / a > > < / td > < td class = "name" onclick = "toggle('on0')" > < a name = "on0Anchor" > on< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "on0" > < pre > Matches on the implicit object argument of a member call expression.
2012-08-27 07:55:24 +08:00
Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y"))))))
2012-08-21 04:54:03 +08:00
class Y { public: void x(); };
void z() { Y y; y.x(); }",
FIXME: Overload to allow directly matching types?
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html" > CXXMemberCallExpr< / a > > < / td > < td class = "name" onclick = "toggle('onImplicitObjectArgument0')" > < a name = "onImplicitObjectArgument0Anchor" > onImplicitObjectArgument< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "onImplicitObjectArgument0" > < pre > < / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html" > CXXMemberCallExpr< / a > > < / td > < td class = "name" onclick = "toggle('thisPointerType1')" > < a name = "thisPointerType1Anchor" > thisPointerType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "thisPointerType1" > < pre > Overloaded to match the type's declaration.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html" > CXXMethodDecl< / a > > < / td > < td class = "name" onclick = "toggle('ofClass0')" > < a name = "ofClass0Anchor" > ofClass< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ofClass0" > < pre > Matches the class declaration that the given method declaration
belongs to.
FIXME: Generalize this for other kinds of declarations.
FIXME: What other kind of declarations would we need to generalize
this to?
Example matches A() in the last line
2012-08-27 07:55:24 +08:00
(matcher = constructExpr(hasDeclaration(methodDecl(
2012-08-21 04:54:03 +08:00
ofClass(hasName("A"))))))
class A {
public:
A();
};
A a = A();
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isDerivedFrom0')" > < a name = "isDerivedFrom0Anchor" > isDerivedFrom< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > Base< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "isDerivedFrom0" > < pre > Matches C++ classes that are directly or indirectly derived from
a class matching Base.
2012-09-07 21:10:32 +08:00
Note that a class is not considered to be derived from itself.
2012-08-21 04:54:03 +08:00
2012-09-07 21:10:32 +08:00
Example matches Y, Z, C (Base == hasName("X"))
class X;
2012-08-21 04:54:03 +08:00
class Y : public X {}; directly derived
class Z : public Y {}; indirectly derived
typedef X A;
typedef A B;
class C : public B {}; derived from a typedef of X
In the following example, Bar matches isDerivedFrom(hasName("X")):
class Foo;
typedef Foo X;
class Bar : public Foo {}; derived from a type that X is a typedef of
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html" > CXXRecordDecl< / a > > < / td > < td class = "name" onclick = "toggle('isSameOrDerivedFrom0')" > < a name = "isSameOrDerivedFrom0Anchor" > isSameOrDerivedFrom< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > Base< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "isSameOrDerivedFrom0" > < pre > Similar to isDerivedFrom(), but also matches classes that directly
match Base.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > < / td > < td class = "name" onclick = "toggle('callee1')" > < a name = "callee1Anchor" > callee< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "callee1" > < pre > Matches if the call expression's callee's declaration matches the
given matcher.
2012-08-27 07:55:24 +08:00
Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
2012-08-21 04:54:03 +08:00
class Y { public: void x(); };
void z() { Y y; y.x();
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasAnyArgument0')" > < a name = "hasAnyArgument0Anchor" > hasAnyArgument< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnyArgument0" > < pre > Matches any argument of a call expression or a constructor call
expression.
Given
void x(int, int, int) { int y; x(1, y, 42); }
2012-08-27 07:55:24 +08:00
callExpr(hasAnyArgument(declRefExpr()))
2012-08-21 04:54:03 +08:00
matches x(1, y, 42)
with hasAnyArgument(...)
matching y
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasArgument0')" > < a name = "hasArgument0Anchor" > hasArgument< / a > < / td > < td > unsigned N, Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasArgument0" > < pre > Matches the n'th argument of a call expression or a constructor
call expression.
Example matches y in x(y)
2012-08-27 07:55:24 +08:00
(matcher = callExpr(hasArgument(0, declRefExpr())))
2012-08-21 04:54:03 +08:00
void x(int) { int y; x(y); }
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasDeclaration2')" > < a name = "hasDeclaration2Anchor" > hasDeclaration< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasDeclaration2" > < pre > Matches a type if the declaration of the type matches the given
2012-08-21 04:54:03 +08:00
matcher.
2012-12-04 20:08:08 +08:00
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > >
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html" > CastExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasSourceExpression0')" > < a name = "hasSourceExpression0Anchor" > hasSourceExpression< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasSourceExpression0" > < pre > Matches if the cast's source expression matches the given matcher.
Example: matches "a string" (matcher =
2012-08-27 07:55:24 +08:00
hasSourceExpression(constructExpr()))
2012-08-21 04:54:03 +08:00
class URL { URL(string); };
URL url = "a string";
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html" > ClassTemplateSpecializationDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasAnyTemplateArgument0')" > < a name = "hasAnyTemplateArgument0Anchor" > hasAnyTemplateArgument< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" > TemplateArgument< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnyTemplateArgument0" > < pre > Matches classTemplateSpecializations that have at least one
TemplateArgument matching the given InnerMatcher.
Given
template< typename T> class A {};
template< > class A< double> {};
A< int> a;
2012-08-27 07:55:24 +08:00
classTemplateSpecializationDecl(hasAnyTemplateArgument(
2012-08-21 04:54:03 +08:00
refersToType(asString("int"))))
matches the specialization A< int>
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html" > ClassTemplateSpecializationDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasTemplateArgument0')" > < a name = "hasTemplateArgument0Anchor" > hasTemplateArgument< / a > < / td > < td > unsigned N, Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" > TemplateArgument< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasTemplateArgument0" > < pre > Matches classTemplateSpecializations where the n'th TemplateArgument
matches the given InnerMatcher.
Given
template< typename T, typename U> class A {};
A< bool, int> b;
A< int, bool> c;
2012-08-27 07:55:24 +08:00
classTemplateSpecializationDecl(hasTemplateArgument(
2012-08-21 04:54:03 +08:00
1, refersToType(asString("int"))))
matches the specialization A< bool, int>
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html" > CompoundStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasAnySubstatement0')" > < a name = "hasAnySubstatement0Anchor" > hasAnySubstatement< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnySubstatement0" > < pre > Matches compound statements where at least one substatement matches
a given matcher.
Given
{ {}; 1+2; }
2012-08-27 07:55:24 +08:00
hasAnySubstatement(compoundStmt())
2012-08-21 04:54:03 +08:00
matches '{ {}; 1+2; }'
2012-08-27 07:55:24 +08:00
with compoundStmt()
2012-08-21 04:54:03 +08:00
matching '{}'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html" > ConditionalOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasCondition4')" > < a name = "hasCondition4Anchor" > hasCondition< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasCondition4" > < pre > Matches the condition expression of an if statement, for loop,
or conditional operator.
Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
if (true) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html" > ConditionalOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasFalseExpression0')" > < a name = "hasFalseExpression0Anchor" > hasFalseExpression< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasFalseExpression0" > < pre > Matches the false branch expression of a conditional operator.
Example matches b
condition ? a : b
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html" > ConditionalOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasTrueExpression0')" > < a name = "hasTrueExpression0Anchor" > hasTrueExpression< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasTrueExpression0" > < pre > Matches the true branch expression of a conditional operator.
Example matches a
condition ? a : b
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html" > DeclRefExpr< / a > > < / td > < td class = "name" onclick = "toggle('throughUsingDecl0')" > < a name = "throughUsingDecl0Anchor" > throughUsingDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html" > UsingShadowDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "throughUsingDecl0" > < pre > Matches a DeclRefExpr that refers to a declaration through a
specific using shadow declaration.
FIXME: This currently only works for functions. Fix.
Given
namespace a { void f() {} }
using a::f;
void g() {
f(); Matches this ..
a::f(); .. but not this.
}
2012-08-27 07:55:24 +08:00
declRefExpr(throughUsingDeclaration(anything()))
2012-08-21 04:54:03 +08:00
matches f()
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html" > DeclRefExpr< / a > > < / td > < td class = "name" onclick = "toggle('to0')" > < a name = "to0Anchor" > to< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "to0" > < pre > Matches a DeclRefExpr that refers to a declaration that matches the
specified matcher.
Example matches x in if(x)
2012-08-27 07:55:24 +08:00
(matcher = declRefExpr(to(varDecl(hasName("x")))))
2012-08-21 04:54:03 +08:00
bool x;
if (x) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html" > DeclStmt< / a > > < / td > < td class = "name" onclick = "toggle('containsDeclaration0')" > < a name = "containsDeclaration0Anchor" > containsDeclaration< / a > < / td > < td > unsigned N, Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "containsDeclaration0" > < pre > Matches the n'th declaration of a declaration statement.
Note that this does not work for global declarations because the AST
breaks up multiple-declaration DeclStmt's into multiple single-declaration
DeclStmt's.
Example: Given non-global declarations
int a, b = 0;
int c;
int d = 2, e;
2012-08-27 07:55:24 +08:00
declStmt(containsDeclaration(
0, varDecl(hasInitializer(anything()))))
2012-08-21 04:54:03 +08:00
matches only 'int d = 2, e;', and
2012-08-27 07:55:24 +08:00
declStmt(containsDeclaration(1, varDecl()))
2012-08-21 04:54:03 +08:00
matches 'int a, b = 0' as well as 'int d = 2, e;'
but 'int c;' is not matched.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html" > DeclStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasSingleDecl0')" > < a name = "hasSingleDecl0Anchor" > hasSingleDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasSingleDecl0" > < pre > Matches the Decl of a DeclStmt which has a single declaration.
Given
int a, b;
int c;
2012-08-27 07:55:24 +08:00
declStmt(hasSingleDecl(anything()))
2012-08-21 04:54:03 +08:00
matches 'int c;' but not 'int a, b;'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html" > DoStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasBody0')" > < a name = "hasBody0Anchor" > hasBody< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasBody0" > < pre > Matches a 'for', 'while', or 'do while' statement that has
a given body.
Given
for (;;) {}
2012-08-27 07:55:24 +08:00
hasBody(compoundStmt())
2012-08-21 04:54:03 +08:00
matches 'for (;;) {}'
2012-08-27 07:55:24 +08:00
with compoundStmt()
2012-08-21 04:54:03 +08:00
matching '{}'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html" > DoStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasCondition3')" > < a name = "hasCondition3Anchor" > hasCondition< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasCondition3" > < pre > Matches the condition expression of an if statement, for loop,
or conditional operator.
Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
if (true) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html" > ExplicitCastExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasDestinationType0')" > < a name = "hasDestinationType0Anchor" > hasDestinationType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasDestinationType0" > < pre > Matches casts whose destination type matches a given matcher.
(Note: Clang's AST refers to other conversions as "casts" too, and calls
actual casts "explicit" casts.)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > < / td > < td class = "name" onclick = "toggle('hasType3')" > < a name = "hasType3Anchor" > hasType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasType3" > < pre > Overloaded to match the declaration of the expression's or value
declaration's type.
In case of a value declaration (for example a variable declaration),
this resolves one layer of indirection. For example, in the value
2012-08-27 07:55:24 +08:00
declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
2012-08-21 04:54:03 +08:00
of x."
2012-08-27 07:55:24 +08:00
Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
2012-08-21 04:54:03 +08:00
class X {};
void y(X & x) { x; X z; }
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html" > ValueDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > < / td > < td class = "name" onclick = "toggle('ignoringImpCasts0')" > < a name = "ignoringImpCasts0Anchor" > ignoringImpCasts< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ignoringImpCasts0" > < pre > Matches expressions that match InnerMatcher after any implicit casts
are stripped off.
Parentheses and explicit casts are not discarded.
Given
int arr[5];
int a = 0;
char b = 0;
const int c = a;
int *d = arr;
long e = (long) 0l;
The matchers
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
2012-08-21 04:54:03 +08:00
would match the declarations for a, b, c, and d, but not e.
While
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
2012-08-21 04:54:03 +08:00
only match the declarations for b, c, and d.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > < / td > < td class = "name" onclick = "toggle('ignoringParenCasts0')" > < a name = "ignoringParenCasts0Anchor" > ignoringParenCasts< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ignoringParenCasts0" > < pre > Matches expressions that match InnerMatcher after parentheses and
casts are stripped off.
Implicit and non-C Style casts are also discarded.
Given
int a = 0;
char b = (0);
void* c = reinterpret_cast< char*> (0);
char d = char(0);
The matcher
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
2012-08-21 04:54:03 +08:00
would match the declarations for a, b, c, and d.
while
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(integerLiteral()))
2012-08-21 04:54:03 +08:00
only match the declaration for a.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > < / td > < td class = "name" onclick = "toggle('ignoringParenImpCasts0')" > < a name = "ignoringParenImpCasts0Anchor" > ignoringParenImpCasts< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "ignoringParenImpCasts0" > < pre > Matches expressions that match InnerMatcher after implicit casts and
parentheses are stripped off.
Explicit casts are not discarded.
Given
int arr[5];
int a = 0;
char b = (0);
const int c = a;
int *d = (arr);
long e = ((long) 0l);
The matchers
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
2012-08-21 04:54:03 +08:00
would match the declarations for a, b, c, and d, but not e.
while
2012-08-27 07:55:24 +08:00
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
2012-08-21 04:54:03 +08:00
would only match the declaration for a.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html" > ForStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasBody1')" > < a name = "hasBody1Anchor" > hasBody< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasBody1" > < pre > Matches a 'for', 'while', or 'do while' statement that has
a given body.
Given
for (;;) {}
2012-08-27 07:55:24 +08:00
hasBody(compoundStmt())
2012-08-21 04:54:03 +08:00
matches 'for (;;) {}'
2012-08-27 07:55:24 +08:00
with compoundStmt()
2012-08-21 04:54:03 +08:00
matching '{}'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html" > ForStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasCondition1')" > < a name = "hasCondition1Anchor" > hasCondition< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasCondition1" > < pre > Matches the condition expression of an if statement, for loop,
or conditional operator.
Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
if (true) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html" > ForStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasIncrement0')" > < a name = "hasIncrement0Anchor" > hasIncrement< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasIncrement0" > < pre > Matches the increment statement of a for loop.
Example:
forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
matches '++x' in
for (x; x < N; ++x) { }
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html" > ForStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasLoopInit0')" > < a name = "hasLoopInit0Anchor" > hasLoopInit< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasLoopInit0" > < pre > Matches the initialization statement of a for loop.
Example:
2012-08-27 07:55:24 +08:00
forStmt(hasLoopInit(declStmt()))
2012-08-21 04:54:03 +08:00
matches 'int x = 0' in
for (int x = 0; x < N; ++x) { }
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasAnyParameter0')" > < a name = "hasAnyParameter0Anchor" > hasAnyParameter< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html" > ParmVarDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnyParameter0" > < pre > Matches any parameter of a function declaration.
Does not match the 'this' parameter of a method.
Given
class X { void f(int x, int y, int z) {} };
2012-08-27 07:55:24 +08:00
methodDecl(hasAnyParameter(hasName("y")))
2012-08-21 04:54:03 +08:00
matches f(int x, int y, int z) {}
with hasAnyParameter(...)
matching int y
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasParameter0')" > < a name = "hasParameter0Anchor" > hasParameter< / a > < / td > < td > unsigned N, Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html" > ParmVarDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasParameter0" > < pre > Matches the n'th parameter of a function declaration.
Given
class X { void f(int x) {} };
2012-08-27 07:55:24 +08:00
methodDecl(hasParameter(0, hasType(varDecl())))
2012-08-21 04:54:03 +08:00
matches f(int x) {}
with hasParameter(...)
matching int x
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" > FunctionDecl< / a > > < / td > < td class = "name" onclick = "toggle('returns0')" > < a name = "returns0Anchor" > returns< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "returns0" > < pre > Matches the return type of a function declaration.
Given:
class X { int f() { return 1; } };
2012-08-27 07:55:24 +08:00
methodDecl(returns(asString("int")))
2012-08-21 04:54:03 +08:00
matches int f() { return 1; }
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html" > IfStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasCondition0')" > < a name = "hasCondition0Anchor" > hasCondition< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasCondition0" > < pre > Matches the condition expression of an if statement, for loop,
or conditional operator.
Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
if (true) {}
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html" > IfStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasConditionVariableStatement0')" > < a name = "hasConditionVariableStatement0Anchor" > hasConditionVariableStatement< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html" > DeclStmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasConditionVariableStatement0" > < pre > Matches the condition variable statement in an if statement.
Given
if (A* a = GetAPointer()) {}
hasConditionVariableStatment(...)
matches 'A* a = GetAPointer()'.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html" > ImplicitCastExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasImplicitDestinationType0')" > < a name = "hasImplicitDestinationType0Anchor" > hasImplicitDestinationType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasImplicitDestinationType0" > < pre > Matches implicit casts whose destination type matches a given
matcher.
FIXME: Unit test this matcher
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasDeclaration0')" > < a name = "hasDeclaration0Anchor" > hasDeclaration< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasDeclaration0" > < pre > Matches a type if the declaration of the type matches the given
matcher.
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasObjectExpression0')" > < a name = "hasObjectExpression0Anchor" > hasObjectExpression< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasObjectExpression0" > < pre > Matches a member expression where the object expression is
matched by a given matcher.
Given
struct X { int m; };
void f(X x) { x.m; m; }
2012-08-27 07:55:24 +08:00
memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X")))))))
2012-08-21 04:54:03 +08:00
matches "x.m" and "m"
with hasObjectExpression(...)
matching "x" and the implicit object expression of "m" which has type X*.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > > < / td > < td class = "name" onclick = "toggle('member0')" > < a name = "member0Anchor" > member< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html" > ValueDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "member0" > < pre > Matches a member expression where the member is matched by a
given matcher.
Given
struct { int first, second; } first, second;
int i(second.first);
int j(first.second);
2012-08-27 07:55:24 +08:00
memberExpr(member(hasName("first")))
2012-08-21 04:54:03 +08:00
matches second.first
but not first.second (because the member name there is "second").
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html" > NestedNameSpecifierLoc< / a > > < / td > < td class = "name" onclick = "toggle('hasPrefix1')" > < a name = "hasPrefix1Anchor" > hasPrefix< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html" > NestedNameSpecifierLoc< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasPrefix1" > < pre > Matches on the prefix of a NestedNameSpecifierLoc.
Given
struct A { struct B { struct C {}; }; };
A::B::C c;
nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))
matches "A::"
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html" > NestedNameSpecifierLoc< / a > > < / td > < td class = "name" onclick = "toggle('specifiesTypeLoc0')" > < a name = "specifiesTypeLoc0Anchor" > specifiesTypeLoc< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html" > TypeLoc< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "specifiesTypeLoc0" > < pre > Matches nested name specifier locs that specify a type matching the
given TypeLoc.
Given
struct A { struct B { struct C {}; }; };
A::B::C c;
nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(
hasDeclaration(recordDecl(hasName("A")))))))
matches "A::"
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html" > NestedNameSpecifier< / a > > < / td > < td class = "name" onclick = "toggle('hasPrefix0')" > < a name = "hasPrefix0Anchor" > hasPrefix< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html" > NestedNameSpecifier< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasPrefix0" > < pre > Matches on the prefix of a NestedNameSpecifier.
Given
struct A { struct B { struct C {}; }; };
A::B::C c;
nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and
matches "A::"
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html" > NestedNameSpecifier< / a > > < / td > < td class = "name" onclick = "toggle('specifiesNamespace0')" > < a name = "specifiesNamespace0Anchor" > specifiesNamespace< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html" > NamespaceDecl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "specifiesNamespace0" > < pre > Matches nested name specifiers that specify a namespace matching the
given namespace matcher.
Given
namespace ns { struct A {}; }
ns::A a;
nestedNameSpecifier(specifiesNamespace(hasName("ns")))
matches "ns::"
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html" > NestedNameSpecifier< / a > > < / td > < td class = "name" onclick = "toggle('specifiesType0')" > < a name = "specifiesType0Anchor" > specifiesType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "specifiesType0" > < pre > Matches nested name specifiers that specify a type matching the
given QualType matcher without qualifiers.
Given
struct A { struct B { struct C {}; }; };
A::B::C c;
nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A")))))
matches "A::"
< / pre > < / td > < / tr >
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('hasDeclaration3')" > < a name = "hasDeclaration3Anchor" > hasDeclaration< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasDeclaration3" > < pre > Matches a type if the declaration of the type matches the given
2012-08-21 04:54:03 +08:00
matcher.
2012-12-04 20:08:08 +08:00
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html" > CallExpr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html" > CXXConstructExpr< / a > > ,
Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html" > MemberExpr< / a > >
2012-08-21 04:54:03 +08:00
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('pointsTo1')" > < a name = "pointsTo1Anchor" > pointsTo< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "pointsTo1" > < pre > Overloaded to match the pointee type's declaration.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > < / td > < td class = "name" onclick = "toggle('references1')" > < a name = "references1Anchor" > references< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "references1" > < pre > Overloaded to match the referenced type's declaration.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('alignOfExpr0')" > < a name = "alignOfExpr0Anchor" > alignOfExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html" > UnaryExprOrTypeTraitExpr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "alignOfExpr0" > < pre > Same as unaryExprOrTypeTraitExpr, but only matching
alignof.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > < / td > < td class = "name" onclick = "toggle('sizeOfExpr0')" > < a name = "sizeOfExpr0Anchor" > sizeOfExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html" > UnaryExprOrTypeTraitExpr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "sizeOfExpr0" > < pre > Same as unaryExprOrTypeTraitExpr, but only matching
sizeof.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" > TemplateArgument< / a > > < / td > < td class = "name" onclick = "toggle('refersToDeclaration0')" > < a name = "refersToDeclaration0Anchor" > refersToDeclaration< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "refersToDeclaration0" > < pre > Matches a TemplateArgument that refers to a certain declaration.
Given
template< typename T> struct A {};
struct B { B* next; };
A< & B::next> a;
2012-08-27 07:55:24 +08:00
classTemplateSpecializationDecl(hasAnyTemplateArgument(
refersToDeclaration(fieldDecl(hasName("next"))))
matches the specialization A< & B::next> with fieldDecl(...) matching
2012-08-21 04:54:03 +08:00
B::next
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" > TemplateArgument< / a > > < / td > < td class = "name" onclick = "toggle('refersToType0')" > < a name = "refersToType0Anchor" > refersToType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "refersToType0" > < pre > Matches a TemplateArgument that refers to a certain type.
Given
struct X {};
template< typename T> struct A {};
A< X> a;
2012-08-27 07:55:24 +08:00
classTemplateSpecializationDecl(hasAnyTemplateArgument(
2012-08-21 04:54:03 +08:00
refersToType(class(hasName("X")))))
matches the specialization A< X>
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html" > TypedefType< / a > > < / td > < td class = "name" onclick = "toggle('hasDecl0')" > < a name = "hasDecl0Anchor" > hasDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html" > TypedefNameDecl< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasDecl0" > < pre > Matches TypedefTypes referring to a specific
TypedefNameDecl.
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html" > UnaryExprOrTypeTraitExpr< / a > > < / td > < td class = "name" onclick = "toggle('hasArgumentOfType0')" > < a name = "hasArgumentOfType0Anchor" > hasArgumentOfType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1QualType.html" > QualType< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasArgumentOfType0" > < pre > Matches unary expressions that have a specific type of argument.
Given
int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
matches sizeof(a) and alignof(c)
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html" > UnaryOperator< / a > > < / td > < td class = "name" onclick = "toggle('hasUnaryOperand0')" > < a name = "hasUnaryOperand0Anchor" > hasUnaryOperand< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasUnaryOperand0" > < pre > Matches if the operand of a unary operator matches.
2012-12-04 20:08:08 +08:00
Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true))))
2012-08-21 04:54:03 +08:00
!true
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html" > UsingDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasAnyUsingShadowDecl0')" > < a name = "hasAnyUsingShadowDecl0Anchor" > hasAnyUsingShadowDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html" > UsingShadowDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasAnyUsingShadowDecl0" > < pre > Matches any using shadow declaration.
Given
namespace X { void b(); }
using X::b;
usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
matches using X::b < / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html" > UsingShadowDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasTargetDecl0')" > < a name = "hasTargetDecl0Anchor" > hasTargetDecl< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html" > NamedDecl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasTargetDecl0" > < pre > Matches a using shadow declaration where the target declaration is
matched by the given matcher.
Given
namespace X { int a; void b(); }
using X::a;
using X::b;
2012-08-27 07:55:24 +08:00
usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
2012-08-21 04:54:03 +08:00
matches using X::b but not using X::a < / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html" > ValueDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasType2')" > < a name = "hasType2Anchor" > hasType< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Decl.html" > Decl< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasType2" > < pre > Overloaded to match the declaration of the expression's or value
declaration's type.
In case of a value declaration (for example a variable declaration),
this resolves one layer of indirection. For example, in the value
2012-08-27 07:55:24 +08:00
declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
2012-08-21 04:54:03 +08:00
of x."
2012-08-27 07:55:24 +08:00
Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
2012-08-21 04:54:03 +08:00
class X {};
void y(X & x) { x; X z; }
Usable as: Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > , Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html" > ValueDecl< / a > >
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html" > VarDecl< / a > > < / td > < td class = "name" onclick = "toggle('hasInitializer0')" > < a name = "hasInitializer0Anchor" > hasInitializer< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasInitializer0" > < pre > Matches a variable declaration that has an initializer expression
that matches the given matcher.
2012-08-27 07:55:24 +08:00
Example matches x (matcher = varDecl(hasInitializer(callExpr())))
2012-08-21 04:54:03 +08:00
bool y() { return true; }
bool x = y();
< / pre > < / td > < / tr >
2012-12-04 20:08:08 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html" > VariableArrayType< / a > > < / td > < td class = "name" onclick = "toggle('hasSizeExpr0')" > < a name = "hasSizeExpr0Anchor" > hasSizeExpr< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
< tr > < td colspan = "4" class = "doc" id = "hasSizeExpr0" > < pre > Matches VariableArrayType nodes that have a specific size
expression.
Given
void f(int b) {
int a[b];
}
variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to(
varDecl(hasName("b")))))))
matches "int a[b]"
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html" > WhileStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasBody2')" > < a name = "hasBody2Anchor" > hasBody< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" > Stmt< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasBody2" > < pre > Matches a 'for', 'while', or 'do while' statement that has
a given body.
Given
for (;;) {}
2012-08-27 07:55:24 +08:00
hasBody(compoundStmt())
2012-08-21 04:54:03 +08:00
matches 'for (;;) {}'
2012-08-27 07:55:24 +08:00
with compoundStmt()
2012-08-21 04:54:03 +08:00
matching '{}'
< / pre > < / td > < / tr >
2012-09-07 21:10:32 +08:00
< tr > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html" > WhileStmt< / a > > < / td > < td class = "name" onclick = "toggle('hasCondition2')" > < a name = "hasCondition2Anchor" > hasCondition< / a > < / td > < td > Matcher& lt< a href = "http://clang.llvm.org/doxygen/classclang_1_1Expr.html" > Expr< / a > > InnerMatcher< / td > < / tr >
2012-08-21 04:54:03 +08:00
< tr > < td colspan = "4" class = "doc" id = "hasCondition2" > < pre > Matches the condition expression of an if statement, for loop,
or conditional operator.
Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
if (true) {}
< / pre > < / td > < / tr >
<!-- END_TRAVERSAL_MATCHERS -->
< / table >
< / div >
< / body >
< / html >