diff options
author | Daniel Jasper <djasper@google.com> | 2012-10-30 15:42:00 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-10-30 15:42:00 +0000 |
commit | d1ce3c178b9c648687591b190e0d252124fc2459 (patch) | |
tree | 6379bd7c0db193dcf8075e9a0e9520d1bfcc4656 /lib/ASTMatchers | |
parent | 0d1e645bbfd3727b0dd758bdb685c6e5c7592fec (diff) |
Implement descendant matchers for NestedNamespecifiers
This implements has(), hasDescendant(), forEach() and
forEachDescendant() for NestedNameSpecifier and NestedNameSpecifierLoc
matchers.
Review: http://llvm-reviews.chandlerc.com/D86
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167017 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ASTMatchers')
-rw-r--r-- | lib/ASTMatchers/ASTMatchFinder.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/ASTMatchers/ASTMatchFinder.cpp b/lib/ASTMatchers/ASTMatchFinder.cpp index 38df2a199b..b081f5426e 100644 --- a/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/lib/ASTMatchers/ASTMatchFinder.cpp @@ -147,6 +147,12 @@ public: traverse(*D); else if (const Stmt *S = DynNode.get<Stmt>()) traverse(*S); + else if (const NestedNameSpecifier *NNS = + DynNode.get<NestedNameSpecifier>()) + traverse(*NNS); + else if (const NestedNameSpecifierLoc *NNSLoc = + DynNode.get<NestedNameSpecifierLoc>()) + traverse(*NNSLoc); else if (const QualType *Q = DynNode.get<QualType>()) traverse(*Q); else if (const TypeLoc *T = DynNode.get<TypeLoc>()) @@ -197,6 +203,16 @@ public: // The TypeLoc is matched inside traverse. return traverse(TypeLocNode); } + bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { + ScopedIncrement ScopedDepth(&CurrentDepth); + return (NNS == NULL) || traverse(*NNS); + } + bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { + ScopedIncrement ScopedDepth(&CurrentDepth); + if (!match(*NNS.getNestedNameSpecifier())) + return false; + return !NNS || traverse(NNS); + } bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return true; } @@ -231,6 +247,13 @@ private: bool baseTraverse(TypeLoc TypeLocNode) { return VisitorBase::TraverseTypeLoc(TypeLocNode); } + bool baseTraverse(const NestedNameSpecifier &NNS) { + return VisitorBase::TraverseNestedNameSpecifier( + const_cast<NestedNameSpecifier*>(&NNS)); + } + bool baseTraverse(NestedNameSpecifierLoc NNS) { + return VisitorBase::TraverseNestedNameSpecifierLoc(NNS); + } // Sets 'Matched' to true if 'Matcher' matches 'Node' and: // 0 < CurrentDepth <= MaxDepth. |