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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits