diff options
author | Daniel Jasper <djasper@google.com> | 2012-10-17 08:52:59 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-10-17 08:52:59 +0000 |
commit | ce62007526cdf718faed10df5e9fc7c3cd160cde (patch) | |
tree | 6e52424506b6f42a6df076d37023c129aa533c5c /lib/ASTMatchers/ASTMatchFinder.cpp | |
parent | 64fe36eab6f0cf02a38d1a555e2e132890e231d2 (diff) |
First version of matchers for Types and TypeLocs.
Review: http://llvm-reviews.chandlerc.com/D47
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ASTMatchers/ASTMatchFinder.cpp')
-rw-r--r-- | lib/ASTMatchers/ASTMatchFinder.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/ASTMatchers/ASTMatchFinder.cpp b/lib/ASTMatchers/ASTMatchFinder.cpp index 80ea16aa52..ebbadc424d 100644 --- a/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/lib/ASTMatchers/ASTMatchFinder.cpp @@ -553,10 +553,15 @@ bool MatchASTVisitor::TraverseType(QualType TypeNode) { return RecursiveASTVisitor<MatchASTVisitor>::TraverseType(TypeNode); } -bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLoc) { - match(TypeLoc.getType()); - return RecursiveASTVisitor<MatchASTVisitor>:: - TraverseTypeLoc(TypeLoc); +bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLocNode) { + // The RecursiveASTVisitor only visits types if they're not within TypeLocs. + // We still want to find those types via matchers, so we match them here. Note + // that the TypeLocs are structurally a shadow-hierarchy to the expressed + // type, so we visit all involved parts of a compound type when matching on + // each TypeLoc. + match(TypeLocNode); + match(TypeLocNode.getType()); + return RecursiveASTVisitor<MatchASTVisitor>::TraverseTypeLoc(TypeLocNode); } bool MatchASTVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { @@ -649,6 +654,12 @@ void MatchFinder::addMatcher(const NestedNameSpecifierLocMatcher &NodeMatch, new NestedNameSpecifierLocMatcher(NodeMatch), Action)); } +void MatchFinder::addMatcher(const TypeLocMatcher &NodeMatch, + MatchCallback *Action) { + MatcherCallbackPairs.push_back(std::make_pair( + new TypeLocMatcher(NodeMatch), Action)); +} + ASTConsumer *MatchFinder::newASTConsumer() { return new internal::MatchASTConsumer(&MatcherCallbackPairs, ParsingDone); } |