forked from OSchip/llvm-project
Rename AST node matchers to match the AST node names directly. Part of this rename also splits recordDecl() (which used to match CXXRecordDecl) into recordDecl() (that matches RecordDecl) and cxxRecordDecl (that matches CXXRecordDecl). Also adds isStruct(), isUnion(), and isClass() narrowing matchers for RecordDecl objects.
llvm-svn: 247885
This commit is contained in:
parent
6c1f0933ac
commit
512fb64765
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,7 @@
|
|||
// a functional in-language DSL to express queries over the C++ AST.
|
||||
//
|
||||
// For example, to match a class with a certain name, one would call:
|
||||
// recordDecl(hasName("MyClass"))
|
||||
// cxxRecordDecl(hasName("MyClass"))
|
||||
// which returns a matcher that can be used to find all AST nodes that declare
|
||||
// a class named 'MyClass'.
|
||||
//
|
||||
|
@ -25,13 +25,13 @@
|
|||
//
|
||||
// For example, when we're interested in child classes of a certain class, we
|
||||
// would write:
|
||||
// recordDecl(hasName("MyClass"), hasChild(id("child", recordDecl())))
|
||||
// cxxRecordDecl(hasName("MyClass"), hasChild(id("child", recordDecl())))
|
||||
// When the match is found via the MatchFinder, a user provided callback will
|
||||
// be called with a BoundNodes instance that contains a mapping from the
|
||||
// strings that we provided for the id(...) calls to the nodes that were
|
||||
// matched.
|
||||
// In the given example, each time our matcher finds a match we get a callback
|
||||
// where "child" is bound to the CXXRecordDecl node of the matching child
|
||||
// where "child" is bound to the RecordDecl node of the matching child
|
||||
// class declaration.
|
||||
//
|
||||
// See ASTMatchersInternal.h for a more in-depth explanation of the
|
||||
|
@ -170,7 +170,8 @@ const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl;
|
|||
|
||||
/// \brief Matches AST nodes that were expanded within the main-file.
|
||||
///
|
||||
/// Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
|
||||
/// Example matches X but not Y
|
||||
/// (matcher = cxxRecordDecl(isExpansionInMainFile())
|
||||
/// \code
|
||||
/// #include <Y.h>
|
||||
/// class X {};
|
||||
|
@ -191,7 +192,7 @@ AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,
|
|||
/// \brief Matches AST nodes that were expanded within system-header-files.
|
||||
///
|
||||
/// Example matches Y but not X
|
||||
/// (matcher = recordDecl(isExpansionInSystemHeader())
|
||||
/// (matcher = cxxRecordDecl(isExpansionInSystemHeader())
|
||||
/// \code
|
||||
/// #include <SystemHeader.h>
|
||||
/// class X {};
|
||||
|
@ -216,7 +217,7 @@ AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,
|
|||
/// partially matching a given regex.
|
||||
///
|
||||
/// Example matches Y but not X
|
||||
/// (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
|
||||
/// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
|
||||
/// \code
|
||||
/// #include "ASTMatcher.h"
|
||||
/// class X {};
|
||||
|
@ -304,6 +305,19 @@ const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl;
|
|||
const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
|
||||
namespaceAliasDecl;
|
||||
|
||||
/// \brief Matches class, struct, and union declarations.
|
||||
///
|
||||
/// Example matches \c X, \c Z, \c U, and \c S
|
||||
/// \code
|
||||
/// class X;
|
||||
/// template<class T> class Z {};
|
||||
/// struct S {};
|
||||
/// union U {};
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Decl,
|
||||
RecordDecl> recordDecl;
|
||||
|
||||
/// \brief Matches C++ class declarations.
|
||||
///
|
||||
/// Example matches \c X, \c Z
|
||||
|
@ -313,7 +327,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Decl,
|
||||
CXXRecordDecl> recordDecl;
|
||||
CXXRecordDecl> cxxRecordDecl;
|
||||
|
||||
/// \brief Matches C++ class template declarations.
|
||||
///
|
||||
|
@ -385,7 +399,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// int i;
|
||||
/// };
|
||||
/// \endcode
|
||||
const internal::VariadicAllOfMatcher<CXXCtorInitializer> ctorInitializer;
|
||||
const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer;
|
||||
|
||||
/// \brief Matches template arguments.
|
||||
///
|
||||
|
@ -724,7 +738,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Decl,
|
||||
CXXConstructorDecl> constructorDecl;
|
||||
CXXConstructorDecl> cxxConstructorDecl;
|
||||
|
||||
/// \brief Matches explicit C++ destructor declarations.
|
||||
///
|
||||
|
@ -737,7 +751,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Decl,
|
||||
CXXDestructorDecl> destructorDecl;
|
||||
CXXDestructorDecl> cxxDestructorDecl;
|
||||
|
||||
/// \brief Matches enum declarations.
|
||||
///
|
||||
|
@ -767,7 +781,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \code
|
||||
/// class X { void y(); };
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> methodDecl;
|
||||
const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl;
|
||||
|
||||
/// \brief Matches conversion operator declarations.
|
||||
///
|
||||
|
@ -776,7 +790,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> methodDecl;
|
|||
/// class X { operator int() const; };
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
|
||||
conversionDecl;
|
||||
cxxConversionDecl;
|
||||
|
||||
/// \brief Matches variable declarations.
|
||||
///
|
||||
|
@ -889,7 +903,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr;
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXMemberCallExpr> memberCallExpr;
|
||||
CXXMemberCallExpr> cxxMemberCallExpr;
|
||||
|
||||
/// \brief Matches ObjectiveC Message invocation expressions.
|
||||
///
|
||||
|
@ -922,8 +936,9 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \code
|
||||
/// const std::string str = std::string();
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
|
||||
exprWithCleanups;
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
ExprWithCleanups> exprWithCleanups;
|
||||
|
||||
/// \brief Matches init list expressions.
|
||||
///
|
||||
|
@ -947,8 +962,9 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr;
|
|||
/// \endcode
|
||||
/// substNonTypeTemplateParmExpr()
|
||||
/// matches "N" in the right-hand side of "static const int n = N;"
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr>
|
||||
substNonTypeTemplateParmExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
SubstNonTypeTemplateParmExpr> substNonTypeTemplateParmExpr;
|
||||
|
||||
/// \brief Matches using declarations.
|
||||
///
|
||||
|
@ -970,8 +986,9 @@ const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl;
|
|||
/// \endcode
|
||||
/// usingDirectiveDecl()
|
||||
/// matches \code using namespace X \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
|
||||
usingDirectiveDecl;
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Decl,
|
||||
UsingDirectiveDecl> usingDirectiveDecl;
|
||||
|
||||
/// \brief Matches unresolved using value declarations.
|
||||
///
|
||||
|
@ -1010,7 +1027,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \brief Matches constructor call expressions (including implicit ones).
|
||||
///
|
||||
/// Example matches string(ptr, n) and ptr within arguments of f
|
||||
/// (matcher = constructExpr())
|
||||
/// (matcher = cxxConstructExpr())
|
||||
/// \code
|
||||
/// void f(const string &a, const string &b);
|
||||
/// char *ptr;
|
||||
|
@ -1019,43 +1036,43 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXConstructExpr> constructExpr;
|
||||
CXXConstructExpr> cxxConstructExpr;
|
||||
|
||||
/// \brief Matches unresolved constructor call expressions.
|
||||
///
|
||||
/// Example matches T(t) in return statement of f
|
||||
/// (matcher = unresolvedConstructExpr())
|
||||
/// (matcher = cxxUnresolvedConstructExpr())
|
||||
/// \code
|
||||
/// template <typename T>
|
||||
/// void f(const T& t) { return T(t); }
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXUnresolvedConstructExpr> unresolvedConstructExpr;
|
||||
CXXUnresolvedConstructExpr> cxxUnresolvedConstructExpr;
|
||||
|
||||
/// \brief Matches implicit and explicit this expressions.
|
||||
///
|
||||
/// Example matches the implicit this expression in "return i".
|
||||
/// (matcher = thisExpr())
|
||||
/// (matcher = cxxThisExpr())
|
||||
/// \code
|
||||
/// struct foo {
|
||||
/// int i;
|
||||
/// int f() { return i; }
|
||||
/// };
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> thisExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr;
|
||||
|
||||
/// \brief Matches nodes where temporaries are created.
|
||||
///
|
||||
/// Example matches FunctionTakesString(GetStringByValue())
|
||||
/// (matcher = bindTemporaryExpr())
|
||||
/// (matcher = cxxBindTemporaryExpr())
|
||||
/// \code
|
||||
/// FunctionTakesString(GetStringByValue());
|
||||
/// FunctionTakesStringByPointer(GetStringPointer());
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXBindTemporaryExpr> bindTemporaryExpr;
|
||||
CXXBindTemporaryExpr> cxxBindTemporaryExpr;
|
||||
|
||||
/// \brief Matches nodes where temporaries are materialized.
|
||||
///
|
||||
|
@ -1085,9 +1102,9 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \code
|
||||
/// new X;
|
||||
/// \endcode
|
||||
/// newExpr()
|
||||
/// cxxNewExpr()
|
||||
/// matches 'new X'.
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> newExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
|
||||
|
||||
/// \brief Matches delete expressions.
|
||||
///
|
||||
|
@ -1095,9 +1112,9 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> newExpr;
|
|||
/// \code
|
||||
/// delete X;
|
||||
/// \endcode
|
||||
/// deleteExpr()
|
||||
/// cxxDeleteExpr()
|
||||
/// matches 'delete X'.
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> deleteExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr;
|
||||
|
||||
/// \brief Matches array subscript expressions.
|
||||
///
|
||||
|
@ -1115,14 +1132,14 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
///
|
||||
/// Example matches the CXXDefaultArgExpr placeholder inserted for the
|
||||
/// default value of the second parameter in the call expression f(42)
|
||||
/// (matcher = defaultArgExpr())
|
||||
/// (matcher = cxxDefaultArgExpr())
|
||||
/// \code
|
||||
/// void f(int x, int y = 0);
|
||||
/// f(42);
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXDefaultArgExpr> defaultArgExpr;
|
||||
CXXDefaultArgExpr> cxxDefaultArgExpr;
|
||||
|
||||
/// \brief Matches overloaded operator calls.
|
||||
///
|
||||
|
@ -1132,7 +1149,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// FIXME: figure out why these do not match?
|
||||
///
|
||||
/// Example matches both operator<<((o << b), c) and operator<<(o, b)
|
||||
/// (matcher = operatorCallExpr())
|
||||
/// (matcher = cxxOperatorCallExpr())
|
||||
/// \code
|
||||
/// ostream &operator<< (ostream &out, int i) { };
|
||||
/// ostream &o; int b = 1, c = 1;
|
||||
|
@ -1140,7 +1157,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXOperatorCallExpr> operatorCallExpr;
|
||||
CXXOperatorCallExpr> cxxOperatorCallExpr;
|
||||
|
||||
/// \brief Matches expressions.
|
||||
///
|
||||
|
@ -1207,12 +1224,14 @@ AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>,
|
|||
|
||||
/// \brief Matches range-based for statements.
|
||||
///
|
||||
/// forRangeStmt() matches 'for (auto a : i)'
|
||||
/// cxxForRangeStmt() matches 'for (auto a : i)'
|
||||
/// \code
|
||||
/// int i[] = {1, 2, 3}; for (auto a : i);
|
||||
/// for(int j = 0; j < 5; ++j);
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> forRangeStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXForRangeStmt> cxxForRangeStmt;
|
||||
|
||||
/// \brief Matches the initialization statement of a for loop.
|
||||
///
|
||||
|
@ -1367,27 +1386,27 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt;
|
|||
/// \code
|
||||
/// try {} catch(int i) {}
|
||||
/// \endcode
|
||||
/// catchStmt()
|
||||
/// cxxCatchStmt()
|
||||
/// matches 'catch(int i)'
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> catchStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt;
|
||||
|
||||
/// \brief Matches try statements.
|
||||
///
|
||||
/// \code
|
||||
/// try {} catch(int i) {}
|
||||
/// \endcode
|
||||
/// tryStmt()
|
||||
/// cxxTryStmt()
|
||||
/// matches 'try {}'
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> tryStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
|
||||
|
||||
/// \brief Matches throw expressions.
|
||||
///
|
||||
/// \code
|
||||
/// try { throw 5; } catch(int i) {}
|
||||
/// \endcode
|
||||
/// throwExpr()
|
||||
/// cxxThrowExpr()
|
||||
/// matches 'throw 5'
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> throwExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr;
|
||||
|
||||
/// \brief Matches null statements.
|
||||
///
|
||||
|
@ -1416,7 +1435,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXBoolLiteralExpr> boolLiteral;
|
||||
CXXBoolLiteralExpr> cxxBoolLiteral;
|
||||
|
||||
/// \brief Matches string literals (also matches wide string literals).
|
||||
///
|
||||
|
@ -1480,7 +1499,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \brief Matches nullptr literal.
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXNullPtrLiteralExpr> nullPtrLiteralExpr;
|
||||
CXXNullPtrLiteralExpr> cxxNullPtrLiteralExpr;
|
||||
|
||||
/// \brief Matches GNU __null expression.
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
|
@ -1546,7 +1565,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXReinterpretCastExpr> reinterpretCastExpr;
|
||||
CXXReinterpretCastExpr> cxxReinterpretCastExpr;
|
||||
|
||||
/// \brief Matches a C++ static_cast expression.
|
||||
///
|
||||
|
@ -1554,7 +1573,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \see reinterpretCast
|
||||
///
|
||||
/// Example:
|
||||
/// staticCastExpr()
|
||||
/// cxxStaticCastExpr()
|
||||
/// matches
|
||||
/// static_cast<long>(8)
|
||||
/// in
|
||||
|
@ -1563,12 +1582,12 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXStaticCastExpr> staticCastExpr;
|
||||
CXXStaticCastExpr> cxxStaticCastExpr;
|
||||
|
||||
/// \brief Matches a dynamic_cast expression.
|
||||
///
|
||||
/// Example:
|
||||
/// dynamicCastExpr()
|
||||
/// cxxDynamicCastExpr()
|
||||
/// matches
|
||||
/// dynamic_cast<D*>(&b);
|
||||
/// in
|
||||
|
@ -1579,7 +1598,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXDynamicCastExpr> dynamicCastExpr;
|
||||
CXXDynamicCastExpr> cxxDynamicCastExpr;
|
||||
|
||||
/// \brief Matches a const_cast expression.
|
||||
///
|
||||
|
@ -1591,7 +1610,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXConstCastExpr> constCastExpr;
|
||||
CXXConstCastExpr> cxxConstCastExpr;
|
||||
|
||||
/// \brief Matches a C-style cast expression.
|
||||
///
|
||||
|
@ -1661,7 +1680,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr;
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXFunctionalCastExpr> functionalCastExpr;
|
||||
CXXFunctionalCastExpr> cxxFunctionalCastExpr;
|
||||
|
||||
/// \brief Matches functional cast expressions having N != 1 arguments
|
||||
///
|
||||
|
@ -1671,7 +1690,7 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CXXTemporaryObjectExpr> temporaryObjectExpr;
|
||||
CXXTemporaryObjectExpr> cxxTemporaryObjectExpr;
|
||||
|
||||
/// \brief Matches \c QualTypes in the clang AST.
|
||||
const internal::VariadicAllOfMatcher<QualType> qualType;
|
||||
|
@ -1693,8 +1712,8 @@ const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
|
|||
/// \endcode
|
||||
/// The matcher:
|
||||
/// \code
|
||||
/// recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
|
||||
/// has(fieldDecl(hasName("b")).bind("v"))))
|
||||
/// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
|
||||
/// has(fieldDecl(hasName("b")).bind("v"))))
|
||||
/// \endcode
|
||||
/// will generate two results binding "v", the first of which binds
|
||||
/// the field declaration of \c a, the second the field declaration of
|
||||
|
@ -1830,9 +1849,10 @@ AST_MATCHER_P(NamedDecl, matchesName, std::string, RegExp) {
|
|||
/// a << a; // <-- This matches
|
||||
/// \endcode
|
||||
///
|
||||
/// \c operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified
|
||||
/// line and \c recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches
|
||||
/// the declaration of \c A.
|
||||
/// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
|
||||
/// specified line and
|
||||
/// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
|
||||
/// matches the declaration of \c A.
|
||||
///
|
||||
/// Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
|
||||
inline internal::PolymorphicMatcherWithParam1<
|
||||
|
@ -1901,8 +1921,8 @@ AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, std::string,
|
|||
/// class B { void member(); };
|
||||
/// \endcode
|
||||
///
|
||||
/// \c recordDecl(hasMethod(hasName("func"))) matches the declaration of \c A
|
||||
/// but not \c B.
|
||||
/// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of
|
||||
/// \c A but not \c B.
|
||||
AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>,
|
||||
InnerMatcher) {
|
||||
return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(),
|
||||
|
@ -1912,7 +1932,8 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>,
|
|||
/// \brief Matches AST nodes that have child AST nodes that match the
|
||||
/// provided matcher.
|
||||
///
|
||||
/// Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
|
||||
/// Example matches X, Y
|
||||
/// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))
|
||||
/// \code
|
||||
/// class X {}; // Matches X, because X::X is a class of name X inside X.
|
||||
/// class Y { class X {}; };
|
||||
|
@ -1929,7 +1950,7 @@ LLVM_ATTRIBUTE_UNUSED has = {};
|
|||
/// provided matcher.
|
||||
///
|
||||
/// Example matches X, Y, Z
|
||||
/// (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
|
||||
/// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))
|
||||
/// \code
|
||||
/// class X {}; // Matches X, because X::X is a class of name X inside X.
|
||||
/// class Y { class X {}; };
|
||||
|
@ -1945,7 +1966,8 @@ LLVM_ATTRIBUTE_UNUSED hasDescendant = {};
|
|||
/// \brief Matches AST nodes that have child AST nodes that match the
|
||||
/// provided matcher.
|
||||
///
|
||||
/// Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
|
||||
/// Example matches X, Y
|
||||
/// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
|
||||
/// \code
|
||||
/// class X {}; // Matches X, because X::X is a class of name X inside X.
|
||||
/// class Y { class X {}; };
|
||||
|
@ -1965,7 +1987,7 @@ LLVM_ATTRIBUTE_UNUSED forEach = {};
|
|||
/// provided matcher.
|
||||
///
|
||||
/// Example matches X, A, B, C
|
||||
/// (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
|
||||
/// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))
|
||||
/// \code
|
||||
/// class X {}; // Matches X, because X::X is a class of name X inside X.
|
||||
/// class A { class X {}; };
|
||||
|
@ -1978,7 +2000,9 @@ LLVM_ATTRIBUTE_UNUSED forEach = {};
|
|||
/// each result that matches instead of only on the first one.
|
||||
///
|
||||
/// Note: Recursively combined ForEachDescendant can cause many matches:
|
||||
/// recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
|
||||
/// cxxRecordDecl(forEachDescendant(cxxRecordDecl(
|
||||
/// forEachDescendant(cxxRecordDecl())
|
||||
/// )))
|
||||
/// will match 10 times (plus injected class name matches) on:
|
||||
/// \code
|
||||
/// class A { class B { class C { class D { class E {}; }; }; }; };
|
||||
|
@ -1998,7 +2022,8 @@ LLVM_ATTRIBUTE_UNUSED forEachDescendant = {};
|
|||
/// \endcode
|
||||
/// The matcher:
|
||||
/// \code
|
||||
/// recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m")))
|
||||
/// cxxRecordDecl(hasName("::A"),
|
||||
/// findAll(cxxRecordDecl(isDefinition()).bind("m")))
|
||||
/// \endcode
|
||||
/// will generate results for \c A, \c B and \c C.
|
||||
///
|
||||
|
@ -2039,7 +2064,7 @@ const internal::ArgumentAdaptingMatcherFunc<
|
|||
|
||||
/// \brief Matches if the provided matcher does not match.
|
||||
///
|
||||
/// Example matches Y (matcher = recordDecl(unless(hasName("X"))))
|
||||
/// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
|
||||
/// \code
|
||||
/// class X {};
|
||||
/// class Y {};
|
||||
|
@ -2080,7 +2105,7 @@ hasDeclaration(const internal::Matcher<Decl> &InnerMatcher) {
|
|||
/// \brief Matches on the implicit object argument of a member call expression.
|
||||
///
|
||||
/// Example matches y.x()
|
||||
/// (matcher = memberCallExpr(on(hasType(recordDecl(hasName("Y"))))))
|
||||
/// (matcher = cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))))
|
||||
/// \code
|
||||
/// class Y { public: void x(); };
|
||||
/// void z() { Y y; y.x(); }",
|
||||
|
@ -2120,7 +2145,7 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>,
|
|||
/// \code
|
||||
/// [self.bodyView loadHTMLString:html baseURL:NULL];
|
||||
/// \endcode
|
||||
AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) {
|
||||
AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) {
|
||||
Selector Sel = Node.getSelector();
|
||||
return BaseName.compare(Sel.getAsString()) == 0;
|
||||
}
|
||||
|
@ -2173,7 +2198,6 @@ AST_MATCHER(ObjCMessageExpr, hasUnarySelector) {
|
|||
/// webView.frame = bodyFrame;
|
||||
/// // ^---- matches here
|
||||
/// \endcode
|
||||
|
||||
AST_MATCHER(ObjCMessageExpr, hasKeywordSelector) {
|
||||
return Node.getSelector().isKeywordSelector();
|
||||
}
|
||||
|
@ -2219,7 +2243,8 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>,
|
|||
/// \brief Matches if the call expression's callee's declaration matches the
|
||||
/// given matcher.
|
||||
///
|
||||
/// Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
|
||||
/// Example matches y.x() (matcher = callExpr(callee(
|
||||
/// cxxMethodDecl(hasName("x")))))
|
||||
/// \code
|
||||
/// class Y { public: void x(); };
|
||||
/// void z() { Y y; y.x(); }
|
||||
|
@ -2232,8 +2257,8 @@ AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher<Decl>, InnerMatcher,
|
|||
/// \brief Matches if the expression's or declaration's type matches a type
|
||||
/// matcher.
|
||||
///
|
||||
/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
|
||||
/// and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
|
||||
/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
|
||||
/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
|
||||
/// \code
|
||||
/// class X {};
|
||||
/// void y(X &x) { x; X z; }
|
||||
|
@ -2249,12 +2274,12 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
|
|||
///
|
||||
/// In case of a value declaration (for example a variable declaration),
|
||||
/// this resolves one layer of indirection. For example, in the value
|
||||
/// declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
|
||||
/// while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
|
||||
/// of x."
|
||||
/// declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of
|
||||
/// X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the
|
||||
/// declaration of x.
|
||||
///
|
||||
/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
|
||||
/// and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
|
||||
/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
|
||||
/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
|
||||
/// \code
|
||||
/// class X {};
|
||||
/// void y(X &x) { x; X z; }
|
||||
|
@ -2292,7 +2317,7 @@ AST_MATCHER_P(DeclaratorDecl, hasTypeLoc, internal::Matcher<TypeLoc>, Inner) {
|
|||
/// class Y { public: void x(); };
|
||||
/// void z() { Y* y; y->x(); }
|
||||
/// \endcode
|
||||
/// memberCallExpr(on(hasType(asString("class Y *"))))
|
||||
/// cxxMemberCallExpr(on(hasType(asString("class Y *"))))
|
||||
/// matches y->x()
|
||||
AST_MATCHER_P(QualType, asString, std::string, Name) {
|
||||
return Name == Node.getAsString();
|
||||
|
@ -2302,8 +2327,8 @@ AST_MATCHER_P(QualType, asString, std::string, Name) {
|
|||
/// matches the specified matcher.
|
||||
///
|
||||
/// Example matches y->x()
|
||||
/// (matcher = memberCallExpr(on(hasType(pointsTo
|
||||
/// recordDecl(hasName("Y")))))))
|
||||
/// (matcher = cxxMemberCallExpr(on(hasType(pointsTo
|
||||
/// cxxRecordDecl(hasName("Y")))))))
|
||||
/// \code
|
||||
/// class Y { public: void x(); };
|
||||
/// void z() { Y *y; y->x(); }
|
||||
|
@ -2326,7 +2351,7 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>,
|
|||
/// type matches the specified matcher.
|
||||
///
|
||||
/// Example matches X &x and const X &y
|
||||
/// (matcher = varDecl(hasType(references(recordDecl(hasName("X"))))))
|
||||
/// (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X"))))))
|
||||
/// \code
|
||||
/// class X {
|
||||
/// void a(X b) {
|
||||
|
@ -2596,7 +2621,7 @@ AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N,
|
|||
/// // ...
|
||||
/// }
|
||||
/// /endcode
|
||||
/// catchStmt(isCatchAll()) matches catch(...) but not catch(int).
|
||||
/// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
|
||||
AST_MATCHER(CXXCatchStmt, isCatchAll) {
|
||||
return Node.getExceptionDecl() == nullptr;
|
||||
}
|
||||
|
@ -2610,7 +2635,9 @@ AST_MATCHER(CXXCatchStmt, isCatchAll) {
|
|||
/// int foo_;
|
||||
/// };
|
||||
/// \endcode
|
||||
/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
|
||||
/// cxxRecordDecl(has(cxxConstructorDecl(
|
||||
/// hasAnyConstructorInitializer(anything())
|
||||
/// )))
|
||||
/// record matches Foo, hasAnyConstructorInitializer matches foo_(1)
|
||||
AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer,
|
||||
internal::Matcher<CXXCtorInitializer>, InnerMatcher) {
|
||||
|
@ -2627,7 +2654,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer,
|
|||
/// int foo_;
|
||||
/// };
|
||||
/// \endcode
|
||||
/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
|
||||
/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
|
||||
/// forField(hasName("foo_"))))))
|
||||
/// matches Foo
|
||||
/// with forField matching foo_
|
||||
|
@ -2647,7 +2674,7 @@ AST_MATCHER_P(CXXCtorInitializer, forField,
|
|||
/// int foo_;
|
||||
/// };
|
||||
/// \endcode
|
||||
/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
|
||||
/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
|
||||
/// withInitializer(integerLiteral(equals(1)))))))
|
||||
/// matches Foo
|
||||
/// with withInitializer matching (1)
|
||||
|
@ -2669,7 +2696,7 @@ AST_MATCHER_P(CXXCtorInitializer, withInitializer,
|
|||
/// string foo_;
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(hasAnyConstructorInitializer(isWritten()))
|
||||
/// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten()))
|
||||
/// will match Foo(int), but not Foo()
|
||||
AST_MATCHER(CXXCtorInitializer, isWritten) {
|
||||
return Node.isWritten();
|
||||
|
@ -2689,7 +2716,7 @@ AST_MATCHER(CXXCtorInitializer, isWritten) {
|
|||
/// E() : B() {}
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))
|
||||
/// cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))
|
||||
/// will match E(), but not match D(int).
|
||||
AST_MATCHER(CXXCtorInitializer, isBaseInitializer) {
|
||||
return Node.isBaseInitializer();
|
||||
|
@ -2709,7 +2736,7 @@ AST_MATCHER(CXXCtorInitializer, isBaseInitializer) {
|
|||
/// E() : B() {}
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
|
||||
/// cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
|
||||
/// will match D(int), but not match E().
|
||||
AST_MATCHER(CXXCtorInitializer, isMemberInitializer) {
|
||||
return Node.isMemberInitializer();
|
||||
|
@ -2756,7 +2783,7 @@ AST_MATCHER(CXXConstructExpr, isListInitialization) {
|
|||
/// \code
|
||||
/// class X { void f(int x) {} };
|
||||
/// \endcode
|
||||
/// methodDecl(hasParameter(0, hasType(varDecl())))
|
||||
/// cxxMethodDecl(hasParameter(0, hasType(varDecl())))
|
||||
/// matches f(int x) {}
|
||||
/// with hasParameter(...)
|
||||
/// matching int x
|
||||
|
@ -2776,7 +2803,7 @@ AST_MATCHER_P2(FunctionDecl, hasParameter,
|
|||
/// \code
|
||||
/// class X { void f(int x, int y, int z) {} };
|
||||
/// \endcode
|
||||
/// methodDecl(hasAnyParameter(hasName("y")))
|
||||
/// cxxMethodDecl(hasAnyParameter(hasName("y")))
|
||||
/// matches f(int x, int y, int z) {}
|
||||
/// with hasAnyParameter(...)
|
||||
/// matching int y
|
||||
|
@ -2805,7 +2832,7 @@ AST_MATCHER_P(FunctionDecl, parameterCountIs, unsigned, N) {
|
|||
/// \code
|
||||
/// class X { int f() { return 1; } };
|
||||
/// \endcode
|
||||
/// methodDecl(returns(asString("int")))
|
||||
/// cxxMethodDecl(returns(asString("int")))
|
||||
/// matches int f() { return 1; }
|
||||
AST_MATCHER_P(FunctionDecl, returns,
|
||||
internal::Matcher<QualType>, InnerMatcher) {
|
||||
|
@ -2859,7 +2886,7 @@ AST_POLYMORPHIC_MATCHER(isConstexpr,
|
|||
/// \brief Matches the condition expression of an if statement, for loop,
|
||||
/// or conditional operator.
|
||||
///
|
||||
/// Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
|
||||
/// Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
|
||||
/// \code
|
||||
/// if (true) {}
|
||||
/// \endcode
|
||||
|
@ -2876,7 +2903,7 @@ AST_POLYMORPHIC_MATCHER_P(hasCondition,
|
|||
/// \brief Matches the then-statement of an if statement.
|
||||
///
|
||||
/// Examples matches the if statement
|
||||
/// (matcher = ifStmt(hasThen(boolLiteral(equals(true)))))
|
||||
/// (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true)))))
|
||||
/// \code
|
||||
/// if (false) true; else false;
|
||||
/// \endcode
|
||||
|
@ -2888,7 +2915,7 @@ AST_MATCHER_P(IfStmt, hasThen, internal::Matcher<Stmt>, InnerMatcher) {
|
|||
/// \brief Matches the else-statement of an if statement.
|
||||
///
|
||||
/// Examples matches the if statement
|
||||
/// (matcher = ifStmt(hasElse(boolLiteral(equals(true)))))
|
||||
/// (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true)))))
|
||||
/// \code
|
||||
/// if (false) false; else true;
|
||||
/// \endcode
|
||||
|
@ -2905,7 +2932,7 @@ AST_MATCHER_P(IfStmt, hasElse, internal::Matcher<Stmt>, InnerMatcher) {
|
|||
/// \code
|
||||
/// class X { int a; int b; };
|
||||
/// \endcode
|
||||
/// recordDecl(
|
||||
/// cxxRecordDecl(
|
||||
/// has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
|
||||
/// has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
|
||||
/// matches the class \c X, as \c a and \c b have the same type.
|
||||
|
@ -3037,7 +3064,7 @@ AST_MATCHER_P(CompoundStmt, statementCountIs, unsigned, N) {
|
|||
|
||||
/// \brief Matches literals that are equal to the given value.
|
||||
///
|
||||
/// Example matches true (matcher = boolLiteral(equals(true)))
|
||||
/// Example matches true (matcher = cxxBoolLiteral(equals(true)))
|
||||
/// \code
|
||||
/// true
|
||||
/// \endcode
|
||||
|
@ -3101,7 +3128,8 @@ inline internal::Matcher<BinaryOperator> hasEitherOperand(
|
|||
|
||||
/// \brief Matches if the operand of a unary operator matches.
|
||||
///
|
||||
/// Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true))))
|
||||
/// Example matches true (matcher = hasUnaryOperand(
|
||||
/// cxxBoolLiteral(equals(true))))
|
||||
/// \code
|
||||
/// !true
|
||||
/// \endcode
|
||||
|
@ -3115,7 +3143,7 @@ AST_MATCHER_P(UnaryOperator, hasUnaryOperand,
|
|||
/// \brief Matches if the cast's source expression matches the given matcher.
|
||||
///
|
||||
/// Example: matches "a string" (matcher =
|
||||
/// hasSourceExpression(constructExpr()))
|
||||
/// hasSourceExpression(cxxConstructExpr()))
|
||||
/// \code
|
||||
/// class URL { URL(string); };
|
||||
/// URL url = "a string";
|
||||
|
@ -3146,6 +3174,42 @@ AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType,
|
|||
return InnerMatcher.matches(Node.getType(), Finder, Builder);
|
||||
}
|
||||
|
||||
/// \brief Matches RecordDecl object that are spelled with "struct."
|
||||
///
|
||||
/// Example matches S, but not C or U.
|
||||
/// \code
|
||||
/// struct S {};
|
||||
/// class C {};
|
||||
/// union U {};
|
||||
/// \endcode
|
||||
AST_MATCHER(RecordDecl, isStruct) {
|
||||
return Node.isStruct();
|
||||
}
|
||||
|
||||
/// \brief Matches RecordDecl object that are spelled with "union."
|
||||
///
|
||||
/// Example matches U, but not C or S.
|
||||
/// \code
|
||||
/// struct S {};
|
||||
/// class C {};
|
||||
/// union U {};
|
||||
/// \endcode
|
||||
AST_MATCHER(RecordDecl, isUnion) {
|
||||
return Node.isUnion();
|
||||
}
|
||||
|
||||
/// \brief Matches RecordDecl object that are spelled with "class."
|
||||
///
|
||||
/// Example matches C, but not S or U.
|
||||
/// \code
|
||||
/// struct S {};
|
||||
/// class C {};
|
||||
/// union U {};
|
||||
/// \endcode
|
||||
AST_MATCHER(RecordDecl, isClass) {
|
||||
return Node.isClass();
|
||||
}
|
||||
|
||||
/// \brief Matches the true branch expression of a conditional operator.
|
||||
///
|
||||
/// Example matches a
|
||||
|
@ -3199,7 +3263,7 @@ AST_POLYMORPHIC_MATCHER(isDefinition,
|
|||
/// this to?
|
||||
///
|
||||
/// Example matches A() in the last line
|
||||
/// (matcher = constructExpr(hasDeclaration(methodDecl(
|
||||
/// (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl(
|
||||
/// ofClass(hasName("A"))))))
|
||||
/// \code
|
||||
/// class A {
|
||||
|
@ -3274,7 +3338,7 @@ AST_MATCHER(CXXMethodDecl, isPure) {
|
|||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// methodDecl(isConst()) matches A::foo() but not A::bar()
|
||||
/// cxxMethodDecl(isConst()) matches A::foo() but not A::bar()
|
||||
AST_MATCHER(CXXMethodDecl, isConst) {
|
||||
return Node.isConst();
|
||||
}
|
||||
|
@ -3391,7 +3455,7 @@ AST_MATCHER_P(MemberExpr, member,
|
|||
/// struct X { int m; };
|
||||
/// void f(X x) { x.m; m; }
|
||||
/// \endcode
|
||||
/// memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X")))))))
|
||||
/// memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))))
|
||||
/// matches "x.m" and "m"
|
||||
/// with hasObjectExpression(...)
|
||||
/// matching "x" and the implicit object expression of "m" which has type X*.
|
||||
|
@ -3443,7 +3507,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl,
|
|||
/// \code
|
||||
/// template <typename T> class X {}; class A {}; template class X<A>;
|
||||
/// \endcode
|
||||
/// recordDecl(hasName("::X"), isTemplateInstantiation())
|
||||
/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
|
||||
/// matches the template instantiation of X<A>.
|
||||
///
|
||||
/// But given
|
||||
|
@ -3451,7 +3515,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl,
|
|||
/// template <typename T> class X {}; class A {};
|
||||
/// template <> class X<A> {}; X<A> x;
|
||||
/// \endcode
|
||||
/// recordDecl(hasName("::X"), isTemplateInstantiation())
|
||||
/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
|
||||
/// does not match, as X<A> is an explicit template specialization.
|
||||
///
|
||||
/// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
|
||||
|
@ -3475,7 +3539,7 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstantiation,
|
|||
/// functionDecl(isInstantiated())
|
||||
/// matches 'A(int) {...};' and 'A(unsigned) {...}'.
|
||||
AST_MATCHER_FUNCTION(internal::Matcher<Decl>, isInstantiated) {
|
||||
auto IsInstantiation = decl(anyOf(recordDecl(isTemplateInstantiation()),
|
||||
auto IsInstantiation = decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
|
||||
functionDecl(isTemplateInstantiation())));
|
||||
return decl(anyOf(IsInstantiation, hasAncestor(IsInstantiation)));
|
||||
}
|
||||
|
@ -3496,7 +3560,7 @@ AST_MATCHER_FUNCTION(internal::Matcher<Decl>, isInstantiated) {
|
|||
/// instantiation.
|
||||
AST_MATCHER_FUNCTION(internal::Matcher<Stmt>, isInTemplateInstantiation) {
|
||||
return stmt(
|
||||
hasAncestor(decl(anyOf(recordDecl(isTemplateInstantiation()),
|
||||
hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
|
||||
functionDecl(isTemplateInstantiation())))));
|
||||
}
|
||||
|
||||
|
@ -4045,7 +4109,7 @@ AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType);
|
|||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// \c recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
|
||||
/// \c cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
|
||||
/// declaration of \c class \c D.
|
||||
AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) {
|
||||
const DeclContext *DC = Node.getDeclContext();
|
||||
|
@ -4090,7 +4154,9 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
|
|||
/// struct A { struct B { struct C {}; }; };
|
||||
/// A::B::C c;
|
||||
/// \endcode
|
||||
/// nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A")))))
|
||||
/// nestedNameSpecifier(specifiesType(
|
||||
/// hasDeclaration(cxxRecordDecl(hasName("A")))
|
||||
/// ))
|
||||
/// matches "A::"
|
||||
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
|
||||
internal::Matcher<QualType>, InnerMatcher) {
|
||||
|
@ -4108,7 +4174,7 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
|
|||
/// A::B::C c;
|
||||
/// \endcode
|
||||
/// nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(
|
||||
/// hasDeclaration(recordDecl(hasName("A")))))))
|
||||
/// hasDeclaration(cxxRecordDecl(hasName("A")))))))
|
||||
/// matches "A::"
|
||||
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
|
||||
internal::Matcher<TypeLoc>, InnerMatcher) {
|
||||
|
@ -4226,7 +4292,9 @@ AST_MATCHER_P(SwitchStmt, forEachSwitchCase, internal::Matcher<SwitchCase>,
|
|||
/// \code
|
||||
/// class A { A() : i(42), j(42) {} int i; int j; };
|
||||
/// \endcode
|
||||
/// constructorDecl(forEachConstructorInitializer(forField(decl().bind("x"))))
|
||||
/// cxxConstructorDecl(forEachConstructorInitializer(
|
||||
/// forField(decl().bind("x"))
|
||||
/// ))
|
||||
/// will trigger two matches, binding for 'i' and 'j' respectively.
|
||||
AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer,
|
||||
internal::Matcher<CXXCtorInitializer>, InnerMatcher) {
|
||||
|
@ -4253,7 +4321,7 @@ AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer,
|
|||
/// S(S &&); // #3
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
|
||||
/// cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
|
||||
AST_MATCHER(CXXConstructorDecl, isCopyConstructor) {
|
||||
return Node.isCopyConstructor();
|
||||
}
|
||||
|
@ -4268,7 +4336,7 @@ AST_MATCHER(CXXConstructorDecl, isCopyConstructor) {
|
|||
/// S(S &&); // #3
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
|
||||
/// cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
|
||||
AST_MATCHER(CXXConstructorDecl, isMoveConstructor) {
|
||||
return Node.isMoveConstructor();
|
||||
}
|
||||
|
@ -4283,7 +4351,7 @@ AST_MATCHER(CXXConstructorDecl, isMoveConstructor) {
|
|||
/// S(S &&); // #3
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
|
||||
/// cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
|
||||
AST_MATCHER(CXXConstructorDecl, isDefaultConstructor) {
|
||||
return Node.isDefaultConstructor();
|
||||
}
|
||||
|
@ -4300,8 +4368,8 @@ AST_MATCHER(CXXConstructorDecl, isDefaultConstructor) {
|
|||
/// explicit operator bool(); // #4
|
||||
/// };
|
||||
/// \endcode
|
||||
/// constructorDecl(isExplicit()) will match #2, but not #1.
|
||||
/// conversionDecl(isExplicit()) will match #4, but not #3.
|
||||
/// cxxConstructorDecl(isExplicit()) will match #2, but not #1.
|
||||
/// cxxConversionDecl(isExplicit()) will match #4, but not #3.
|
||||
AST_POLYMORPHIC_MATCHER(isExplicit,
|
||||
AST_POLYMORPHIC_SUPPORTED_TYPES(CXXConstructorDecl,
|
||||
CXXConversionDecl)) {
|
||||
|
@ -4386,8 +4454,9 @@ AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) {
|
|||
/// \code
|
||||
/// kernel<<<i,j>>>();
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
|
||||
CUDAKernelCallExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
CUDAKernelCallExpr> cudaKernelCallExpr;
|
||||
|
||||
} // end namespace ast_matchers
|
||||
} // end namespace clang
|
||||
|
|
|
@ -107,15 +107,12 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(atomicType);
|
||||
REGISTER_MATCHER(autoType);
|
||||
REGISTER_MATCHER(binaryOperator);
|
||||
REGISTER_MATCHER(bindTemporaryExpr);
|
||||
REGISTER_MATCHER(blockPointerType);
|
||||
REGISTER_MATCHER(boolLiteral);
|
||||
REGISTER_MATCHER(breakStmt);
|
||||
REGISTER_MATCHER(builtinType);
|
||||
REGISTER_MATCHER(callExpr);
|
||||
REGISTER_MATCHER(caseStmt);
|
||||
REGISTER_MATCHER(castExpr);
|
||||
REGISTER_MATCHER(catchStmt);
|
||||
REGISTER_MATCHER(characterLiteral);
|
||||
REGISTER_MATCHER(classTemplateDecl);
|
||||
REGISTER_MATCHER(classTemplateSpecializationDecl);
|
||||
|
@ -124,27 +121,45 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(compoundStmt);
|
||||
REGISTER_MATCHER(conditionalOperator);
|
||||
REGISTER_MATCHER(constantArrayType);
|
||||
REGISTER_MATCHER(constCastExpr);
|
||||
REGISTER_MATCHER(constructExpr);
|
||||
REGISTER_MATCHER(constructorDecl);
|
||||
REGISTER_MATCHER(containsDeclaration);
|
||||
REGISTER_MATCHER(continueStmt);
|
||||
REGISTER_MATCHER(conversionDecl);
|
||||
REGISTER_MATCHER(cStyleCastExpr);
|
||||
REGISTER_MATCHER(ctorInitializer);
|
||||
REGISTER_MATCHER(CUDAKernelCallExpr);
|
||||
REGISTER_MATCHER(cudaKernelCallExpr);
|
||||
REGISTER_MATCHER(cxxBindTemporaryExpr);
|
||||
REGISTER_MATCHER(cxxBoolLiteral);
|
||||
REGISTER_MATCHER(cxxCatchStmt);
|
||||
REGISTER_MATCHER(cxxConstCastExpr);
|
||||
REGISTER_MATCHER(cxxConstructExpr);
|
||||
REGISTER_MATCHER(cxxConstructorDecl);
|
||||
REGISTER_MATCHER(cxxConversionDecl);
|
||||
REGISTER_MATCHER(cxxCtorInitializer);
|
||||
REGISTER_MATCHER(cxxDefaultArgExpr);
|
||||
REGISTER_MATCHER(cxxDeleteExpr);
|
||||
REGISTER_MATCHER(cxxDestructorDecl);
|
||||
REGISTER_MATCHER(cxxDynamicCastExpr);
|
||||
REGISTER_MATCHER(cxxForRangeStmt);
|
||||
REGISTER_MATCHER(cxxFunctionalCastExpr);
|
||||
REGISTER_MATCHER(cxxMemberCallExpr);
|
||||
REGISTER_MATCHER(cxxMethodDecl);
|
||||
REGISTER_MATCHER(cxxNewExpr);
|
||||
REGISTER_MATCHER(cxxNullPtrLiteralExpr);
|
||||
REGISTER_MATCHER(cxxOperatorCallExpr);
|
||||
REGISTER_MATCHER(cxxRecordDecl);
|
||||
REGISTER_MATCHER(cxxReinterpretCastExpr);
|
||||
REGISTER_MATCHER(cxxStaticCastExpr);
|
||||
REGISTER_MATCHER(cxxTemporaryObjectExpr);
|
||||
REGISTER_MATCHER(cxxThisExpr);
|
||||
REGISTER_MATCHER(cxxThrowExpr);
|
||||
REGISTER_MATCHER(cxxTryStmt);
|
||||
REGISTER_MATCHER(cxxUnresolvedConstructExpr);
|
||||
REGISTER_MATCHER(decl);
|
||||
REGISTER_MATCHER(declaratorDecl);
|
||||
REGISTER_MATCHER(declCountIs);
|
||||
REGISTER_MATCHER(declRefExpr);
|
||||
REGISTER_MATCHER(declStmt);
|
||||
REGISTER_MATCHER(defaultArgExpr);
|
||||
REGISTER_MATCHER(defaultStmt);
|
||||
REGISTER_MATCHER(deleteExpr);
|
||||
REGISTER_MATCHER(dependentSizedArrayType);
|
||||
REGISTER_MATCHER(destructorDecl);
|
||||
REGISTER_MATCHER(doStmt);
|
||||
REGISTER_MATCHER(dynamicCastExpr);
|
||||
REGISTER_MATCHER(eachOf);
|
||||
REGISTER_MATCHER(elaboratedType);
|
||||
REGISTER_MATCHER(enumConstantDecl);
|
||||
|
@ -161,10 +176,8 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(forEachDescendant);
|
||||
REGISTER_MATCHER(forEachSwitchCase);
|
||||
REGISTER_MATCHER(forField);
|
||||
REGISTER_MATCHER(forRangeStmt);
|
||||
REGISTER_MATCHER(forStmt);
|
||||
REGISTER_MATCHER(friendDecl);
|
||||
REGISTER_MATCHER(functionalCastExpr);
|
||||
REGISTER_MATCHER(functionDecl);
|
||||
REGISTER_MATCHER(functionTemplateDecl);
|
||||
REGISTER_MATCHER(functionType);
|
||||
|
@ -245,6 +258,7 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(isArrow);
|
||||
REGISTER_MATCHER(isBaseInitializer);
|
||||
REGISTER_MATCHER(isCatchAll);
|
||||
REGISTER_MATCHER(isClass);
|
||||
REGISTER_MATCHER(isConst);
|
||||
REGISTER_MATCHER(isConstQualified);
|
||||
REGISTER_MATCHER(isCopyConstructor);
|
||||
|
@ -274,7 +288,9 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(isProtected);
|
||||
REGISTER_MATCHER(isPublic);
|
||||
REGISTER_MATCHER(isPure);
|
||||
REGISTER_MATCHER(isStruct);
|
||||
REGISTER_MATCHER(isTemplateInstantiation);
|
||||
REGISTER_MATCHER(isUnion);
|
||||
REGISTER_MATCHER(isVirtual);
|
||||
REGISTER_MATCHER(isWritten);
|
||||
REGISTER_MATCHER(labelStmt);
|
||||
|
@ -284,18 +300,14 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(matchesSelector);
|
||||
REGISTER_MATCHER(materializeTemporaryExpr);
|
||||
REGISTER_MATCHER(member);
|
||||
REGISTER_MATCHER(memberCallExpr);
|
||||
REGISTER_MATCHER(memberExpr);
|
||||
REGISTER_MATCHER(memberPointerType);
|
||||
REGISTER_MATCHER(methodDecl);
|
||||
REGISTER_MATCHER(namedDecl);
|
||||
REGISTER_MATCHER(namespaceAliasDecl);
|
||||
REGISTER_MATCHER(namespaceDecl);
|
||||
REGISTER_MATCHER(namesType);
|
||||
REGISTER_MATCHER(nestedNameSpecifier);
|
||||
REGISTER_MATCHER(nestedNameSpecifierLoc);
|
||||
REGISTER_MATCHER(newExpr);
|
||||
REGISTER_MATCHER(nullPtrLiteralExpr);
|
||||
REGISTER_MATCHER(nullStmt);
|
||||
REGISTER_MATCHER(numSelectorArgs);
|
||||
REGISTER_MATCHER(ofClass);
|
||||
|
@ -304,7 +316,6 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(objcObjectPointerType);
|
||||
REGISTER_MATCHER(on);
|
||||
REGISTER_MATCHER(onImplicitObjectArgument);
|
||||
REGISTER_MATCHER(operatorCallExpr);
|
||||
REGISTER_MATCHER(parameterCountIs);
|
||||
REGISTER_MATCHER(parenType);
|
||||
REGISTER_MATCHER(parmVarDecl);
|
||||
|
@ -317,7 +328,6 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(refersToDeclaration);
|
||||
REGISTER_MATCHER(refersToIntegralType);
|
||||
REGISTER_MATCHER(refersToType);
|
||||
REGISTER_MATCHER(reinterpretCastExpr);
|
||||
REGISTER_MATCHER(returns);
|
||||
REGISTER_MATCHER(returnStmt);
|
||||
REGISTER_MATCHER(rValueReferenceType);
|
||||
|
@ -326,7 +336,6 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(specifiesType);
|
||||
REGISTER_MATCHER(specifiesTypeLoc);
|
||||
REGISTER_MATCHER(statementCountIs);
|
||||
REGISTER_MATCHER(staticCastExpr);
|
||||
REGISTER_MATCHER(staticAssertDecl);
|
||||
REGISTER_MATCHER(stmt);
|
||||
REGISTER_MATCHER(stringLiteral);
|
||||
|
@ -338,13 +347,9 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(templateArgumentCountIs);
|
||||
REGISTER_MATCHER(templateSpecializationType);
|
||||
REGISTER_MATCHER(templateTypeParmType);
|
||||
REGISTER_MATCHER(temporaryObjectExpr);
|
||||
REGISTER_MATCHER(thisExpr);
|
||||
REGISTER_MATCHER(throughUsingDecl);
|
||||
REGISTER_MATCHER(throwExpr);
|
||||
REGISTER_MATCHER(to);
|
||||
REGISTER_MATCHER(translationUnitDecl);
|
||||
REGISTER_MATCHER(tryStmt);
|
||||
REGISTER_MATCHER(type);
|
||||
REGISTER_MATCHER(typedefDecl);
|
||||
REGISTER_MATCHER(typedefType);
|
||||
|
@ -353,7 +358,6 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(unaryOperator);
|
||||
REGISTER_MATCHER(unaryTransformType);
|
||||
REGISTER_MATCHER(unless);
|
||||
REGISTER_MATCHER(unresolvedConstructExpr);
|
||||
REGISTER_MATCHER(unresolvedUsingTypenameDecl);
|
||||
REGISTER_MATCHER(unresolvedUsingValueDecl);
|
||||
REGISTER_MATCHER(userDefinedLiteral);
|
||||
|
|
|
@ -27,8 +27,9 @@ using clang::tooling::FrontendActionFactory;
|
|||
|
||||
TEST(GetParents, ReturnsParentForDecl) {
|
||||
MatchVerifier<Decl> Verifier;
|
||||
EXPECT_TRUE(Verifier.match("class C { void f(); };",
|
||||
methodDecl(hasParent(recordDecl(hasName("C"))))));
|
||||
EXPECT_TRUE(
|
||||
Verifier.match("class C { void f(); };",
|
||||
cxxMethodDecl(hasParent(recordDecl(hasName("C"))))));
|
||||
}
|
||||
|
||||
TEST(GetParents, ReturnsParentForStmt) {
|
||||
|
@ -42,19 +43,20 @@ TEST(GetParents, ReturnsParentInsideTemplateInstantiations) {
|
|||
EXPECT_TRUE(DeclVerifier.match(
|
||||
"template<typename T> struct C { void f() {} };"
|
||||
"void g() { C<int> c; c.f(); }",
|
||||
methodDecl(hasName("f"),
|
||||
hasParent(recordDecl(isTemplateInstantiation())))));
|
||||
cxxMethodDecl(hasName("f"),
|
||||
hasParent(cxxRecordDecl(isTemplateInstantiation())))));
|
||||
EXPECT_TRUE(DeclVerifier.match(
|
||||
"template<typename T> struct C { void f() {} };"
|
||||
"void g() { C<int> c; c.f(); }",
|
||||
methodDecl(hasName("f"),
|
||||
hasParent(recordDecl(unless(isTemplateInstantiation()))))));
|
||||
cxxMethodDecl(hasName("f"),
|
||||
hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))))));
|
||||
EXPECT_FALSE(DeclVerifier.match(
|
||||
"template<typename T> struct C { void f() {} };"
|
||||
"void g() { C<int> c; c.f(); }",
|
||||
methodDecl(hasName("f"),
|
||||
allOf(hasParent(recordDecl(unless(isTemplateInstantiation()))),
|
||||
hasParent(recordDecl(isTemplateInstantiation()))))));
|
||||
cxxMethodDecl(
|
||||
hasName("f"),
|
||||
allOf(hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))),
|
||||
hasParent(cxxRecordDecl(isTemplateInstantiation()))))));
|
||||
}
|
||||
|
||||
TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) {
|
||||
|
@ -62,9 +64,9 @@ TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) {
|
|||
EXPECT_TRUE(TemplateVerifier.match(
|
||||
"template<typename T> struct C { void f() {} };"
|
||||
"void g() { C<int> c; c.f(); }",
|
||||
compoundStmt(
|
||||
allOf(hasAncestor(recordDecl(isTemplateInstantiation())),
|
||||
hasAncestor(recordDecl(unless(isTemplateInstantiation())))))));
|
||||
compoundStmt(allOf(
|
||||
hasAncestor(cxxRecordDecl(isTemplateInstantiation())),
|
||||
hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation())))))));
|
||||
}
|
||||
|
||||
} // end namespace ast_matchers
|
||||
|
|
|
@ -471,7 +471,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl1) {
|
|||
"struct A {"
|
||||
" A();"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A()"));
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl2) {
|
|||
"struct A {"
|
||||
" A(int a);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A(int a)"));
|
||||
}
|
||||
|
||||
|
@ -489,7 +489,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl3) {
|
|||
"struct A {"
|
||||
" A(const A &a);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A(const A &a)"));
|
||||
}
|
||||
|
||||
|
@ -498,7 +498,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl4) {
|
|||
"struct A {"
|
||||
" A(const A &a, int = 0);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A(const A &a, int = 0)"));
|
||||
}
|
||||
|
||||
|
@ -507,7 +507,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl5) {
|
|||
"struct A {"
|
||||
" A(const A &&a);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A(const A &&a)"));
|
||||
}
|
||||
|
||||
|
@ -516,7 +516,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl6) {
|
|||
"struct A {"
|
||||
" explicit A(int a);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"explicit A(int a)"));
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl7) {
|
|||
"struct A {"
|
||||
" constexpr A();"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"constexpr A()"));
|
||||
}
|
||||
|
||||
|
@ -534,7 +534,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl8) {
|
|||
"struct A {"
|
||||
" A() = default;"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A() = default"));
|
||||
}
|
||||
|
||||
|
@ -543,7 +543,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl9) {
|
|||
"struct A {"
|
||||
" A() = delete;"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A() = delete"));
|
||||
}
|
||||
|
||||
|
@ -553,7 +553,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl10) {
|
|||
"struct A {"
|
||||
" A(const A &a);"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A<T...>(const A<T...> &a)"));
|
||||
// WRONG; Should be: "A(const A<T...> &a);"
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) {
|
|||
"struct A : public T... {"
|
||||
" A(T&&... ts) : T(ts)... {}"
|
||||
"};",
|
||||
constructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"A<T...>(T &&...ts) : T(ts)..."));
|
||||
// WRONG; Should be: "A(T &&...ts) : T(ts)... {}"
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl1) {
|
|||
"struct A {"
|
||||
" ~A();"
|
||||
"};",
|
||||
destructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"~A()"));
|
||||
}
|
||||
|
||||
|
@ -583,7 +583,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl2) {
|
|||
"struct A {"
|
||||
" virtual ~A();"
|
||||
"};",
|
||||
destructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"virtual ~A()"));
|
||||
}
|
||||
|
||||
|
@ -592,7 +592,7 @@ TEST(DeclPrinter, TestCXXConversionDecl1) {
|
|||
"struct A {"
|
||||
" operator int();"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"operator int()"));
|
||||
}
|
||||
|
||||
|
@ -601,7 +601,7 @@ TEST(DeclPrinter, TestCXXConversionDecl2) {
|
|||
"struct A {"
|
||||
" operator bool();"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"operator bool()"));
|
||||
}
|
||||
|
||||
|
@ -611,7 +611,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) {
|
|||
"struct A {"
|
||||
" operator Z();"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
|
||||
"operator Z()"));
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
|
|||
"struct Z {"
|
||||
" void *operator new(std::size_t);"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
"void *operator new(std::size_t)"));
|
||||
// Should be: with semicolon
|
||||
}
|
||||
|
@ -632,7 +632,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
|
|||
"struct Z {"
|
||||
" void *operator new[](std::size_t);"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
"void *operator new[](std::size_t)"));
|
||||
// Should be: with semicolon
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
|
|||
"struct Z {"
|
||||
" void operator delete(void *);"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
"void operator delete(void *) noexcept"));
|
||||
// Should be: with semicolon, without noexcept?
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
|
|||
"struct Z {"
|
||||
" void operator delete(void *);"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
"void operator delete(void *)"));
|
||||
// Should be: with semicolon
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
|
|||
"struct Z {"
|
||||
" void operator delete[](void *);"
|
||||
"};",
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
"void operator delete[](void *) noexcept"));
|
||||
// Should be: with semicolon, without noexcept?
|
||||
}
|
||||
|
@ -690,7 +690,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
|
|||
|
||||
ASSERT_TRUE(PrintedDeclCXX98Matches(
|
||||
Code,
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
Expected));
|
||||
}
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
|
|||
|
||||
ASSERT_TRUE(PrintedDeclCXX98Matches(
|
||||
Code,
|
||||
methodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
|
||||
Expected));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,13 +92,13 @@ TEST(ParmVarDecl, KNRRange) {
|
|||
TEST(CXXNewExpr, ArrayRange) {
|
||||
RangeVerifier<CXXNewExpr> Verifier;
|
||||
Verifier.expectRange(1, 12, 1, 22);
|
||||
EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", newExpr()));
|
||||
EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", cxxNewExpr()));
|
||||
}
|
||||
|
||||
TEST(CXXNewExpr, ParenRange) {
|
||||
RangeVerifier<CXXNewExpr> Verifier;
|
||||
Verifier.expectRange(1, 12, 1, 20);
|
||||
EXPECT_TRUE(Verifier.match("void f() { new int(); }", newExpr()));
|
||||
EXPECT_TRUE(Verifier.match("void f() { new int(); }", cxxNewExpr()));
|
||||
}
|
||||
|
||||
TEST(MemberExpr, ImplicitMemberRange) {
|
||||
|
@ -221,7 +221,7 @@ TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) {
|
|||
TEST(CXXNewExpr, TypeParenRange) {
|
||||
RangeVerifier<CXXNewExpr> Verifier;
|
||||
Verifier.expectRange(1, 10, 1, 18);
|
||||
EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr()));
|
||||
EXPECT_TRUE(Verifier.match("int* a = new (int);", cxxNewExpr()));
|
||||
}
|
||||
|
||||
class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> {
|
||||
|
@ -252,7 +252,7 @@ TEST(CXXFunctionalCastExpr, SourceRange) {
|
|||
"int foo() {\n"
|
||||
" return int{};\n"
|
||||
"}",
|
||||
functionalCastExpr(), Lang_CXX11));
|
||||
cxxFunctionalCastExpr(), Lang_CXX11));
|
||||
}
|
||||
|
||||
TEST(CXXConstructExpr, SourceRange) {
|
||||
|
@ -262,7 +262,7 @@ TEST(CXXConstructExpr, SourceRange) {
|
|||
"struct A { A(int, int); };\n"
|
||||
"void f(A a);\n"
|
||||
"void g() { f({0, 0}); }",
|
||||
constructExpr(), Lang_CXX11));
|
||||
cxxConstructExpr(), Lang_CXX11));
|
||||
}
|
||||
|
||||
TEST(CXXTemporaryObjectExpr, SourceRange) {
|
||||
|
@ -271,7 +271,7 @@ TEST(CXXTemporaryObjectExpr, SourceRange) {
|
|||
EXPECT_TRUE(Verifier.match(
|
||||
"struct A { A(int, int); };\n"
|
||||
"A a( A{0, 0} );",
|
||||
temporaryObjectExpr(), Lang_CXX11));
|
||||
cxxTemporaryObjectExpr(), Lang_CXX11));
|
||||
}
|
||||
|
||||
TEST(CXXUnresolvedConstructExpr, SourceRange) {
|
||||
|
@ -284,7 +284,7 @@ TEST(CXXUnresolvedConstructExpr, SourceRange) {
|
|||
"U foo() {\n"
|
||||
" return U{};\n"
|
||||
"}",
|
||||
unresolvedConstructExpr(), Args, Lang_CXX11));
|
||||
cxxUnresolvedConstructExpr(), Args, Lang_CXX11));
|
||||
}
|
||||
|
||||
TEST(UsingDecl, SourceRange) {
|
||||
|
@ -434,11 +434,11 @@ TEST(FriendDecl, FriendConstructorDestructorLocation) {
|
|||
LocationVerifier<FriendDecl> ConstructorVerifier;
|
||||
ConstructorVerifier.expectLocation(6, 11);
|
||||
EXPECT_TRUE(ConstructorVerifier.match(
|
||||
Code, friendDecl(has(constructorDecl(ofClass(hasName("B")))))));
|
||||
Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B")))))));
|
||||
LocationVerifier<FriendDecl> DestructorVerifier;
|
||||
DestructorVerifier.expectLocation(6, 19);
|
||||
EXPECT_TRUE(DestructorVerifier.match(
|
||||
Code, friendDecl(has(destructorDecl(ofClass(hasName("B")))))));
|
||||
Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B")))))));
|
||||
}
|
||||
|
||||
TEST(FriendDecl, FriendConstructorDestructorRange) {
|
||||
|
@ -452,11 +452,11 @@ TEST(FriendDecl, FriendConstructorDestructorRange) {
|
|||
RangeVerifier<FriendDecl> ConstructorVerifier;
|
||||
ConstructorVerifier.expectRange(6, 1, 6, 13);
|
||||
EXPECT_TRUE(ConstructorVerifier.match(
|
||||
Code, friendDecl(has(constructorDecl(ofClass(hasName("B")))))));
|
||||
Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B")))))));
|
||||
RangeVerifier<FriendDecl> DestructorVerifier;
|
||||
DestructorVerifier.expectRange(6, 1, 6, 22);
|
||||
EXPECT_TRUE(DestructorVerifier.match(
|
||||
Code, friendDecl(has(destructorDecl(ofClass(hasName("B")))))));
|
||||
Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B")))))));
|
||||
}
|
||||
|
||||
TEST(FriendDecl, FriendTemplateFunctionLocation) {
|
||||
|
@ -527,7 +527,7 @@ TEST(FriendDecl, InstantiationSourceRange) {
|
|||
" friend void operator+<>(S<T> src);\n"
|
||||
"};\n"
|
||||
"void test(S<double> s) { +s; }",
|
||||
friendDecl(hasParent(recordDecl(isTemplateInstantiation())))));
|
||||
friendDecl(hasParent(cxxRecordDecl(isTemplateInstantiation())))));
|
||||
}
|
||||
|
||||
TEST(ObjCMessageExpr, CXXConstructExprRange) {
|
||||
|
@ -539,7 +539,7 @@ TEST(ObjCMessageExpr, CXXConstructExprRange) {
|
|||
"+ (void) f1: (A)arg;\n"
|
||||
"@end\n"
|
||||
"void f2() { A a; [B f1: (a)]; }\n",
|
||||
constructExpr(), Lang_OBJCXX));
|
||||
cxxConstructExpr(), Lang_OBJCXX));
|
||||
}
|
||||
|
||||
} // end namespace ast_matchers
|
||||
|
|
|
@ -196,7 +196,7 @@ TEST(StmtPrinter, TestCXXConversionDeclImplicit) {
|
|||
"void foo(A a, A b) {"
|
||||
" bar(a & b);"
|
||||
"}",
|
||||
memberCallExpr(anything()).bind("id"),
|
||||
cxxMemberCallExpr(anything()).bind("id"),
|
||||
"a & b"));
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ TEST(StmtPrinter, TestCXXConversionDeclExplicit) {
|
|||
"void foo(A a, A b) {"
|
||||
" auto x = (a & b).operator void *();"
|
||||
"}",
|
||||
memberCallExpr(anything()).bind("id"),
|
||||
cxxMemberCallExpr(anything()).bind("id"),
|
||||
"(a & b)"));
|
||||
// WRONG; Should be: (a & b).operator void *()
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -301,12 +301,12 @@ TEST(ParserTest, CompletionNamedValues) {
|
|||
EXPECT_EQ("String nameX", Comps[0].MatcherDecl);
|
||||
|
||||
// Can complete if there are names in the expression.
|
||||
Code = "methodDecl(hasName(nameX), ";
|
||||
Code = "cxxMethodDecl(hasName(nameX), ";
|
||||
Comps = Parser::completeExpression(Code, Code.size(), nullptr, &NamedValues);
|
||||
EXPECT_LT(0u, Comps.size());
|
||||
|
||||
// Can complete names and registry together.
|
||||
Code = "methodDecl(hasP";
|
||||
Code = "cxxMethodDecl(hasP";
|
||||
Comps = Parser::completeExpression(Code, Code.size(), nullptr, &NamedValues);
|
||||
ASSERT_EQ(3u, Comps.size());
|
||||
EXPECT_EQ("aramA", Comps[0].TypedText);
|
||||
|
|
|
@ -129,7 +129,7 @@ TEST_F(RegistryTest, CanConstructNoArgs) {
|
|||
Matcher<Stmt> IsArrowValue = constructMatcher(
|
||||
"memberExpr", constructMatcher("isArrow")).getTypedMatcher<Stmt>();
|
||||
Matcher<Stmt> BoolValue =
|
||||
constructMatcher("boolLiteral").getTypedMatcher<Stmt>();
|
||||
constructMatcher("cxxBoolLiteral").getTypedMatcher<Stmt>();
|
||||
|
||||
const std::string ClassSnippet = "struct Foo { int x; };\n"
|
||||
"Foo *foo = new Foo;\n"
|
||||
|
@ -195,7 +195,7 @@ TEST_F(RegistryTest, OverloadedMatchers) {
|
|||
"callExpr",
|
||||
constructMatcher(
|
||||
"callee",
|
||||
constructMatcher("methodDecl",
|
||||
constructMatcher("cxxMethodDecl",
|
||||
constructMatcher("hasName", StringRef("x")))))
|
||||
.getTypedMatcher<Stmt>();
|
||||
|
||||
|
@ -255,11 +255,11 @@ TEST_F(RegistryTest, PolymorphicMatchers) {
|
|||
EXPECT_FALSE(matches("void Foo(){};", RecordDecl));
|
||||
|
||||
Matcher<Stmt> ConstructExpr = constructMatcher(
|
||||
"constructExpr",
|
||||
"cxxConstructExpr",
|
||||
constructMatcher(
|
||||
"hasDeclaration",
|
||||
constructMatcher(
|
||||
"methodDecl",
|
||||
"cxxMethodDecl",
|
||||
constructMatcher(
|
||||
"ofClass", constructMatcher("hasName", StringRef("Foo"))))))
|
||||
.getTypedMatcher<Stmt>();
|
||||
|
@ -300,7 +300,7 @@ TEST_F(RegistryTest, TypeTraversal) {
|
|||
|
||||
TEST_F(RegistryTest, CXXCtorInitializer) {
|
||||
Matcher<Decl> CtorDecl = constructMatcher(
|
||||
"constructorDecl",
|
||||
"cxxConstructorDecl",
|
||||
constructMatcher(
|
||||
"hasAnyConstructorInitializer",
|
||||
constructMatcher("forField",
|
||||
|
@ -416,9 +416,10 @@ TEST_F(RegistryTest, Errors) {
|
|||
"(Actual = String)",
|
||||
Error->toString());
|
||||
Error.reset(new Diagnostics());
|
||||
EXPECT_TRUE(constructMatcher("recordDecl", constructMatcher("recordDecl"),
|
||||
constructMatcher("parameterCountIs", 3),
|
||||
Error.get()).isNull());
|
||||
EXPECT_TRUE(
|
||||
constructMatcher("cxxRecordDecl", constructMatcher("cxxRecordDecl"),
|
||||
constructMatcher("parameterCountIs", 3), Error.get())
|
||||
.isNull());
|
||||
EXPECT_EQ("Incorrect type for arg 2. (Expected = Matcher<CXXRecordDecl>) != "
|
||||
"(Actual = Matcher<FunctionDecl>)",
|
||||
Error->toString());
|
||||
|
@ -432,7 +433,7 @@ TEST_F(RegistryTest, Errors) {
|
|||
Error->toString());
|
||||
Error.reset(new Diagnostics());
|
||||
EXPECT_TRUE(constructMatcher(
|
||||
"recordDecl",
|
||||
"cxxRecordDecl",
|
||||
constructMatcher("allOf",
|
||||
constructMatcher("isDerivedFrom", StringRef("FOO")),
|
||||
constructMatcher("isArrow")),
|
||||
|
|
|
@ -71,7 +71,7 @@ TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) {
|
|||
ReplaceStmtWithStmt Callback("always-false", "should-be");
|
||||
expectRewritten(Code, Expected,
|
||||
id("always-false", conditionalOperator(
|
||||
hasCondition(boolLiteral(equals(false))),
|
||||
hasCondition(cxxBoolLiteral(equals(false))),
|
||||
hasFalseExpression(id("should-be", expr())))),
|
||||
Callback);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ TEST(RefactoringCallbacksTest, RemovesEntireIfOnEmptyElse) {
|
|||
std::string Expected = "void f() { }";
|
||||
ReplaceIfStmtWithItsBody Callback("id", false);
|
||||
expectRewritten(Code, Expected,
|
||||
id("id", ifStmt(hasCondition(boolLiteral(equals(false))))),
|
||||
id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false))))),
|
||||
Callback);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue