[PATCH] D43800: [ASTMatchers] Allow file-based narrowing matches to work with NestedNameSpecifierLocs.

David L. Jones via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 26 19:00:01 PST 2018


dlj created this revision.
dlj added a reviewer: rsmith.
Herald added subscribers: sanjoy, klimek.

The narrowing matchers isExpansionInMainFile, isExpansionInSystemHeader, and
isExpansionInFileMatching work for TypeLocs, but not NestedNameSpecifierLocs.
This changes the matchers to use getSourceRange() to get location information,
which not only works for the previous cases, but also for NNSLocs.


Repository:
  rC Clang

https://reviews.llvm.org/D43800

Files:
  include/clang/ASTMatchers/ASTMatchers.h


Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -240,12 +240,14 @@
 ///   class Y {};
 /// \endcode
 ///
-/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>,
+/// Matcher<NestedNameSpecifierLoc>
 AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,
-                        AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+                        AST_POLYMORPHIC_SUPPORTED_TYPES(
+                            Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto &SourceManager = Finder->getASTContext().getSourceManager();
   return SourceManager.isInMainFile(
-      SourceManager.getExpansionLoc(Node.getLocStart()));
+      SourceManager.getExpansionLoc(Node.getSourceRange().getBegin()));
 }
 
 /// \brief Matches AST nodes that were expanded within system-header-files.
@@ -261,11 +263,14 @@
 ///   class Y {};
 /// \endcode
 ///
-/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>,
+/// Matcher<NestedNameSpecifierLoc>
 AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,
-                        AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+                        AST_POLYMORPHIC_SUPPORTED_TYPES(
+                            Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto &SourceManager = Finder->getASTContext().getSourceManager();
-  auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getLocStart());
+  auto ExpansionLoc =
+      SourceManager.getExpansionLoc(Node.getSourceRange().getBegin());
   if (ExpansionLoc.isInvalid()) {
     return false;
   }
@@ -286,12 +291,15 @@
 ///   class Y {};
 /// \endcode
 ///
-/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>,
+/// Matcher<NestedNameSpecifierLoc>
 AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching,
-                          AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),
+                          AST_POLYMORPHIC_SUPPORTED_TYPES(
+                              Decl, Stmt, TypeLoc, NestedNameSpecifierLoc),
                           std::string, RegExp) {
   auto &SourceManager = Finder->getASTContext().getSourceManager();
-  auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getLocStart());
+  auto ExpansionLoc =
+      SourceManager.getExpansionLoc(Node.getSourceRange().getBegin());
   if (ExpansionLoc.isInvalid()) {
     return false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43800.136025.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180227/45cd8281/attachment.bin>


More information about the cfe-commits mailing list