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 | 6fc3433b155f127c43f089f22b44461f91cb444a (patch) | |
tree | e5ecd21294e46102df851ca3fc107fc00ce75117 /clang/lib/ASTMatchers/ASTMatchFinder.cpp | |
parent | e0cf14fa9d33d6eda3e43881e3bfc12369e04ba2 (diff) | |
download | bcm5719-llvm-6fc3433b155f127c43f089f22b44461f91cb444a.tar.gz bcm5719-llvm-6fc3433b155f127c43f089f22b44461f91cb444a.zip |
Implement descendant matchers for NestedNamespecifiers
This implements has(), hasDescendant(), forEach() and
forEachDescendant() for NestedNameSpecifier and NestedNameSpecifierLoc
matchers.
Review: http://llvm-reviews.chandlerc.com/D86
llvm-svn: 167017
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchFinder.cpp')
-rw-r--r-- | clang/lib/ASTMatchers/ASTMatchFinder.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index 38df2a199bd..b081f5426ea 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/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. |