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),