[PATCH] D111242: Add `TypeLoc`-related matchers.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 7 08:29:15 PDT 2021


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6361-6362
+/// \endcode
+/// qualifiedTypeLoc(hasUnqualifiedLoc(pointerTypeLoc()))
+///   matches the `TypeLoc` of the variable declaration of `x`, but not `y`.
+AST_MATCHER_P(QualifiedTypeLoc, hasUnqualifiedLoc, TypeLocMatcher,
----------------
I'm trying to reason my way through this. You want to match a qualified type location and `int * const` matches that. Then you want it to match an unqualified type loc and `int` matches that. Then it should be a pointer type... but `int` does not match that. So I wouldn't expect `x` to be matched. What have I misunderstood?


================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6406-6414
+/// Matches reference `TypeLoc`s.
+///
+/// Given
+/// \code
+///   int x = 3;
+///   int& xx = x;
+/// \endcode
----------------
I'd appreciate more documentation on whether this is expected to match both lvalue and rvalue references. I suppose there's a secondary question of whether this matches member functions too:
```
struct S {
  void func() &; // Can this match this as a reference type loc?
};
```


================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6469-6487
+inline bool
+MatchTemplateArgLocAt(const DeclRefExpr &Node, unsigned int Index,
+                      internal::Matcher<TemplateArgumentLoc> InnerMatcher,
+                      internal::ASTMatchFinder *Finder,
+                      internal::BoundNodesTreeBuilder *Builder) {
+  llvm::ArrayRef<TemplateArgumentLoc> ArgLocs = Node.template_arguments();
+  return Index < ArgLocs.size() &&
----------------
Should these live in ASTMatchersInternal.h?


================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6510-6520
+/// Matches elaborated `TypeLoc`s.
+///
+/// Given
+/// \code
+///   class C {};
+///   class C c;
+/// \endcode
----------------
It'd be helpful to document how this behaves in C where the tag needs to be used (unlike in C++ where the tag can be elided unless you want an elaborated type). Same below.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111242/new/

https://reviews.llvm.org/D111242



More information about the cfe-commits mailing list