[PATCH] Replace overloaded ASTMatchFinder::addMatcher() function with one that takes a DynTypedMatcher.
Samuel Benzaquen
sbenza at google.com
Wed May 8 13:01:42 PDT 2013
Fixed the comment on match(QualType)
Hi klimek,
http://llvm-reviews.chandlerc.com/D770
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D770?vs=1892&id=1893#toc
Files:
include/clang/ASTMatchers/ASTMatchFinder.h
include/clang/ASTMatchers/ASTMatchersInternal.h
lib/ASTMatchers/ASTMatchFinder.cpp
Index: include/clang/ASTMatchers/ASTMatchFinder.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchFinder.h
+++ include/clang/ASTMatchers/ASTMatchFinder.h
@@ -117,17 +117,7 @@
///
/// Does not take ownership of 'Action'.
/// @{
- void addMatcher(const DeclarationMatcher &NodeMatch,
- MatchCallback *Action);
- void addMatcher(const TypeMatcher &NodeMatch,
- MatchCallback *Action);
- void addMatcher(const StatementMatcher &NodeMatch,
- MatchCallback *Action);
- void addMatcher(const NestedNameSpecifierMatcher &NodeMatch,
- MatchCallback *Action);
- void addMatcher(const NestedNameSpecifierLocMatcher &NodeMatch,
- MatchCallback *Action);
- void addMatcher(const TypeLocMatcher &NodeMatch,
+ void addMatcher(const internal::DynTypedMatcher &NodeMatch,
MatchCallback *Action);
/// @}
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -239,6 +239,9 @@
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const = 0;
+ /// \brief Makes a copy of this matcher object.
+ virtual DynTypedMatcher *clone() const = 0;
+
/// \brief Returns a unique ID for the matcher.
virtual uint64_t getID() const = 0;
};
@@ -285,6 +288,9 @@
return Implementation->matches(Node, Finder, Builder);
}
+ /// \brief Makes a copy of this matcher object.
+ virtual Matcher<T> *clone() const { return new Matcher<T>(*this); }
+
/// \brief Returns an ID that uniquely identifies the matcher.
uint64_t getID() const {
/// FIXME: Document the requirements this imposes on matcher
Index: lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- lib/ASTMatchers/ASTMatchFinder.cpp
+++ lib/ASTMatchers/ASTMatchFinder.cpp
@@ -409,6 +409,13 @@
}
}
+ // The traversal will not visit Types directly, only QualTypes. We overload
+ // match(QualType) to run the matchers on the underlying type also.
+ void match(QualType Node) {
+ match(ast_type_traits::DynTypedNode::create(Node));
+ if (!Node.isNull()) match(*Node);
+ }
+
template <typename T> void match(const T &Node) {
match(ast_type_traits::DynTypedNode::create(Node));
}
@@ -708,40 +715,9 @@
}
}
-void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
- MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new internal::Matcher<Decl>(NodeMatch), Action));
-}
-
-void MatchFinder::addMatcher(const TypeMatcher &NodeMatch,
- MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new internal::Matcher<QualType>(NodeMatch), Action));
-}
-
-void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
- MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new internal::Matcher<Stmt>(NodeMatch), Action));
-}
-
-void MatchFinder::addMatcher(const NestedNameSpecifierMatcher &NodeMatch,
- MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new NestedNameSpecifierMatcher(NodeMatch), Action));
-}
-
-void MatchFinder::addMatcher(const NestedNameSpecifierLocMatcher &NodeMatch,
- MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new NestedNameSpecifierLocMatcher(NodeMatch), Action));
-}
-
-void MatchFinder::addMatcher(const TypeLocMatcher &NodeMatch,
+void MatchFinder::addMatcher(const internal::DynTypedMatcher &NodeMatch,
MatchCallback *Action) {
- MatcherCallbackPairs.push_back(std::make_pair(
- new TypeLocMatcher(NodeMatch), Action));
+ MatcherCallbackPairs.push_back(std::make_pair(NodeMatch.clone(), Action));
}
ASTConsumer *MatchFinder::newASTConsumer() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D770.2.patch
Type: text/x-patch
Size: 4151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130508/7d3c2bdf/attachment.bin>
More information about the cfe-commits
mailing list