[cfe-commits] [PATCH] Matchers for Types, QualTypes and TypeLocs

Daniel Jasper djasper at google.com
Mon Oct 15 14:17:27 PDT 2012

Comment at: include/clang/ASTMatchers/ASTMatchersMacros.h:233
@@ -227,8 +232,3 @@
-/// The traversal is done using the given \c FunctionName.
-#define LOC_TRAVERSE_MATCHER(                                                  \
-      MatcherName, NodeType, FunctionName)                                     \
-  inline internal::Matcher<NodeType> hasPrefix(                                \
-      const internal::Matcher<NodeType> &InnerMatcher) {                       \
-    return internal::makeMatcher(new internal::TraverseMatcher<NodeType>(      \
-      InnerMatcher, &NodeType::getPrefix));                                    \
+/// The traversal is done using \c FunctionName.
+#define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName)                   \
Manuel Klimek wrote:
> Daniel Jasper wrote:
> > Manuel Klimek wrote:
> > > Perhaps: The traversal is done using \c NodeTypel::FunctionName.?
> > Like this?
> Are you saying NodeType is not the one that FunctionName is called on?
What NodeType?

Comment extended.

Comment at: include/clang/ASTMatchers/ASTMatchers.h:2462
@@ +2461,3 @@
+/// Given
+///   struct A {};
+///   A a;
Manuel Klimek wrote:
> Missing the \code tags...
Added. Here and below.

Comment at: lib/ASTMatchers/ASTMatchFinder.cpp:560
@@ +559,3 @@
+  // RecursiveASTVisitor by itself would only visit the TypeLocs, not the
+  // contained types.
+  match(TypeLocNode);
Manuel Klimek wrote:
> The question is: why do we want to traverse the Types here?
We do not traverse the Types. We only match them. So basically, whenever you find a TypeLoc hierarchy in the AST, there is a corresponding Type hierarchy. The RecursiveASTVisitor does not visit both, as the TypeLoc is sort of a superset of the Type. However, when matching, we also want to match the contained types, if we happen to have a type-matcher, no?

So, what we basically do is traverse the hierarchy once and try to match both Types and TypeLocs.


More information about the cfe-commits mailing list