diff options
author | Daniel Jasper <djasper@google.com> | 2012-09-07 12:48:17 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-09-07 12:48:17 +0000 |
commit | 76dafa7e6487c0b51fadebd16bdefe0e0e23d595 (patch) | |
tree | 543d26320d7a6526a4e0baa76227d5cd87644049 /include | |
parent | 579b120038ca817e0ce423303ebc1b4e0c6cbbe1 (diff) |
Change the behavior of the isDerivedFrom-matcher to not match on the
class itself. This caused some confusion (intuitively, a class is not
derived from itself) and makes it hard to write certain matchers, e.g.
"match and bind any pair of base and subclass".
The original behavior can be achieved with a new isA-matcher. Similar
to all other matchers, this matcher has the same behavior and name as
the corresponding AST-entity - in this case the isa<>() function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163385 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 23743e529b..91a3ecfd49 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -1108,11 +1108,11 @@ AST_MATCHER_P(CXXOperatorCallExpr, /// \brief Matches C++ classes that are directly or indirectly derived from /// a class matching \c Base. /// -/// Note that a class is considered to be also derived from itself. +/// Note that a class is not considered to be derived from itself. /// -/// Example matches X, Y, Z, C (Base == hasName("X")) +/// Example matches Y, Z, C (Base == hasName("X")) /// \code -/// class X; // A class is considered to be derived from itself +/// class X; /// class Y : public X {}; // directly derived /// class Z : public Y {}; // indirectly derived /// typedef X A; @@ -1137,6 +1137,18 @@ inline internal::Matcher<CXXRecordDecl> isDerivedFrom(StringRef BaseName) { return isDerivedFrom(hasName(BaseName)); } +/// \brief Similar to \c isDerivedFrom(), but also matches classes that directly +/// match \c Base. +inline internal::Matcher<CXXRecordDecl> isA(internal::Matcher<NamedDecl> Base) { + return anyOf(Base, isDerivedFrom(Base)); +} + +/// \brief Overloaded method as shortcut for \c isA(hasName(...)). +inline internal::Matcher<CXXRecordDecl> isA(StringRef BaseName) { + assert(!BaseName.empty()); + return isA(hasName(BaseName)); +} + /// \brief Matches AST nodes that have child AST nodes that match the /// provided matcher. /// |