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

2018-03-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Please add some test coverage for the NNS case.


Repository:
  rC Clang

https://reviews.llvm.org/D43800



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-02-26 Thread David L. Jones via Phabricator via cfe-commits
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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,
-AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+AST_POLYMORPHIC_SUPPORTED_TYPES(
+Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto  = 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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,
-AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+AST_POLYMORPHIC_SUPPORTED_TYPES(
+Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto  = 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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching,
-  AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),
+  AST_POLYMORPHIC_SUPPORTED_TYPES(
+  Decl, Stmt, TypeLoc, NestedNameSpecifierLoc),
   std::string, RegExp) {
   auto  = Finder->getASTContext().getSourceManager();
-  auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getLocStart());
+  auto ExpansionLoc =
+  SourceManager.getExpansionLoc(Node.getSourceRange().getBegin());
   if (ExpansionLoc.isInvalid()) {
 return false;
   }


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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,
-AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+AST_POLYMORPHIC_SUPPORTED_TYPES(
+Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto  = 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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,
-AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) {
+AST_POLYMORPHIC_SUPPORTED_TYPES(
+Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
   auto  = 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, Matcher, Matcher
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
 AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching,
-  AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),
+  AST_POLYMORPHIC_SUPPORTED_TYPES(
+  Decl, Stmt, TypeLoc, NestedNameSpecifierLoc),