diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index ea038e38c83d..ec703d3b7b25 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -229,145 +229,6 @@ Example matches a -
Matches bool literals. - -Example matches true - true -
Matches any cast nodes of Clang's AST. - -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; -
Matches character literals (also matches wchar_t). - -Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), -though. - -Example matches 'a', L'a' - char ch = 'a'; wchar_t chw = L'a'; -
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); -
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); -
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; -
Matches functional cast expressions - -Example: Matches Foo(bar); - Foo f = bar; - Foo g = (Foo) bar; - Foo h = Foo(bar); -
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. -
Matches integer literals of all sizes encodings. - -Not matching character-encoded integers such as L'a'. - -Example matches 1, 1L, 0x1, 1U -
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); -
Matches a C++ static_cast expression. - -hasDestinationType -reinterpretCast - -Example: - staticCastExpr() -matches - static_cast<long>(8) -in - long eight(static_cast<long>(8)); -
Matches string literals (also matches wide string literals). - -Example matches "abcd", L"abcd" - char *s = "abcd"; wchar_t *ws = L"abcd" -
Matches array subscript expressions. @@ -378,6 +239,16 @@ arraySubscriptExpr()
Matches asm statements. + + int i = 100; + __asm("mov al, 2"); +asmStmt() + matches '__asm("mov al, 2")' +
Matches binary operator expressions. @@ -396,6 +267,32 @@ Example matches FunctionTakesString(GetStringByValue())
Matches bool literals. + +Example matches true + true +
Matches break statements. + +Given + while (true) { break; } +breakStmt() + matches 'break' +
Matches a C-style cast expression. + +Example: Matches (int*) 2.2f in + int i = (int) 2.2f; +
Matches call expressions. @@ -406,6 +303,39 @@ Example matches x.y() and y()
Matches any cast nodes of Clang's AST. + +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; +
Matches catch statements. + + try {} catch(int i) {} +catchStmt() + matches 'catch(int i)' +
Matches character literals (also matches wchar_t). + +Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), +though. + +Example matches 'a', L'a' + char ch = 'a'; wchar_t chw = L'a'; +
Matches compound statements. @@ -422,6 +352,16 @@ Example matches a ? b : c
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); +
Matches constructor call expressions (including implicit ones). @@ -434,6 +374,16 @@ Example matches string(ptr, n) and ptr within arguments of f
Matches continue statements. + +Given + while (true) { continue; } +continueStmt() + matches 'continue' +
Matches expressions that refer to declarations. @@ -484,6 +434,41 @@ doStmt()
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); +
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; +
Matches expressions. @@ -492,11 +477,42 @@ Example matches x()
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); +
Matches for statements. Example matches 'for (;;) {}' for (;;) {} + int i[] = {1, 2, 3}; for (auto a : i); +
Matches functional cast expressions + +Example: Matches Foo(bar); + Foo f = bar; + Foo g = (Foo) bar; + Foo h = Foo(bar); +
Matches goto statements. + +Given + goto FOO; + FOO: bar(); +gotoStmt() + matches 'goto FOO'
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. +
Matches init list expressions. @@ -520,6 +544,34 @@ initList()
Matches integer literals of all sizes encodings. + +Not matching character-encoded integers such as L'a'. + +Example matches 1, 1L, 0x1, 1U +
Matches label statements. + +Given + goto FOO; + FOO: bar(); +labelStmt() + matches 'FOO:' +
Matches lambda expressions. + +Example matches [&](){return 5;} + [&](){return 5;} +
Matches nodes where temporaries are materialized. @@ -568,6 +620,20 @@ newExpr()
Matches nullptr literal. +
Matches null statements. + + foo();; +nullStmt() + matches the second ';' +
Matches overloaded operator calls. @@ -584,6 +650,43 @@ Example matches both operator<<((o << b), c) and operator<<(o,
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); +
Matches return statements. + +Given + return 1; +returnStmt() + matches 'return 1' +
Matches a C++ static_cast expression. + +hasDestinationType +reinterpretCast + +Example: + staticCastExpr() +matches + static_cast<long>(8) +in + long eight(static_cast<long>(8)); +
Matches statements. @@ -594,6 +697,14 @@ stmt()
Matches string literals (also matches wide string literals). + +Example matches "abcd", L"abcd" + char *s = "abcd"; wchar_t *ws = L"abcd" +
Matches case and default statements inside switch statements. @@ -604,6 +715,46 @@ switchCase()
Matches switch statements. + +Given + switch(a) { case 42: break; default: break; } +switchStmt() + matches 'switch(a)'. +
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; } +}; +
Matches throw expressions. + + try { throw 5; } catch(int i) {} +throwExpr() + matches 'throw 5' +
Matches try statements. + + try {} catch(int i) {} +tryStmt() + matches 'try {}' +
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) @@ -623,6 +774,13 @@ Example matches !a
Matches user defined literal operator call. + +Example match: "foo"_suffix +
Matches while statements. @@ -632,6 +790,16 @@ whileStmt() matches 'while (true) {}'.
Matches TypeLocs in the clang AST. +
Matches Types in the clang AST. +
Overloaded method as shortcut for isA(hasName(...)). -
Overloaded method as shortcut for isDerivedFrom(hasName(...)).
Overloaded method as shortcut for +isSameOrDerivedFrom(hasName(...)). +
Matches template instantiations of function, class, or static member variable template instantiations. @@ -823,6 +992,18 @@ compoundStmt(statementCountIs(0)))
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]" +
Matches declaration statements that contain a specific number of declarations. @@ -909,6 +1090,17 @@ Usable as: Matcher<FunctionDecl>
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) {} +
Matches literals that are equal to the given value. @@ -1174,7 +1366,7 @@ matcher. Given void f() { if (true) { int x = 42; } } void g() { for (;;) { int x = 43; } } -expr(integerLiteral(hasAncsestor(ifStmt()))) matches 42, but not 43. +expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. Usable as: Any Matcher
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 +
Matches the base expression of an array subscript expression. @@ -1241,11 +1445,12 @@ Example matches b (matcher = binaryOperator(hasRHS()))
Matches a type if the declaration of the type matches the given ++ Matcher<CXXConstructExpr> hasDeclaration Matcher<Decl> InnerMatcher @@ -1331,12 +1536,6 @@ Example matches A() in the last line Matches a type if the declaration of the type matches the given matcher. -Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr> +Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<MemberExpr>
Similar to isDerivedFrom(), but also matches classes that directly -match Base. -
Matches C++ classes that are directly or indirectly derived from a class matching Base. @@ -1358,6 +1557,12 @@ In the following example, Bar matches isDerivedFrom(hasName("X")):
Similar to isDerivedFrom(), but also matches classes that directly +match Base. +
Matches if the call expression's callee's declaration matches the given matcher. @@ -1391,11 +1596,12 @@ Example matches y in x(y)
Matches a type if the declaration of the type matches the given ++ Matcher<CallExpr> hasDeclaration Matcher<Decl> InnerMatcher @@ -1753,6 +1959,15 @@ FIXME: Unit test this matcher Matches a type if the declaration of the type matches the given matcher. -Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr> +Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<MemberExpr>
Matches a type if the declaration of the type matches the given +matcher. + +Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<MemberExpr> +
Matches a member expression where the object expression is matched by a given matcher. @@ -1781,11 +1996,71 @@ memberExpr(member(hasName("first")))
Matches a type if the declaration of the type matches the given ++ Matcher<NestedNameSpecifierLoc> hasPrefix Matcher<NestedNameSpecifierLoc> InnerMatcher + + + 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::" ++ Matcher<NestedNameSpecifierLoc> specifiesTypeLoc Matcher<TypeLoc> InnerMatcher + + + 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::" ++ Matcher<NestedNameSpecifier> hasPrefix Matcher<NestedNameSpecifier> InnerMatcher + + + 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::" ++ Matcher<NestedNameSpecifier> specifiesNamespace Matcher<NamespaceDecl> InnerMatcher + + + 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::" ++ Matcher<NestedNameSpecifier> specifiesType Matcher<QualType> InnerMatcher + + + 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::" ++ Matcher<QualType> hasDeclaration Matcher<Decl> InnerMatcher @@ -1838,6 +2113,12 @@ classTemplateSpecializationDecl(hasAnyTemplateArgument( Matches a type if the declaration of the type matches the given matcher. -Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr> +Usable as: Matcher<QualType>, Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<MemberExpr>
Matches TypedefTypes referring to a specific +TypedefNameDecl. +
Matches unary expressions that have a specific type of argument. @@ -1851,7 +2132,7 @@ unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))Matcher<UnaryOperator> hasUnaryOperand Matcher<Expr> InnerMatcher @@ -1907,6 +2188,20 @@ Example matches x (matcher = varDecl(hasInitializer(callExpr()))) Matches if the operand of a unary operator matches. -Example matches true (matcher = hasOperand(boolLiteral(equals(true)))) +Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true)))) !true
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]" +
Matches a 'for', 'while', or 'do while' statement that has a given body.