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 | 516b02e54870ce1fad494ca097e68443563cc4ec (patch) | |
tree | 491a030814983437af6869072fdf7bbdbe940a0b /clang/lib/ASTMatchers/ASTMatchFinder.cpp | |
parent | 05a3b01d4fc03df29f9e7afeea9f89b81f386e7c (diff) | |
download | bcm5719-llvm-516b02e54870ce1fad494ca097e68443563cc4ec.tar.gz bcm5719-llvm-516b02e54870ce1fad494ca097e68443563cc4ec.zip |
First version of matchers for Types and TypeLocs.
Review: http://llvm-reviews.chandlerc.com/D47
llvm-svn: 166094
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchFinder.cpp')
-rw-r--r-- | clang/lib/ASTMatchers/ASTMatchFinder.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index 80ea16aa525..ebbadc424d4 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/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); } |