| Ariel J. Bernal | 601858a | 2013-07-15 15:37:05 +0000 | [diff] [blame] | 1 | //===-- Core/CustomMatchers.h - Perf measurement helpers -----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file provides custom matchers to be used by different |
| 12 | /// transforms that requier the same matchers. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| Chandler Carruth | 35c0361 | 2013-09-04 19:13:50 +0000 | [diff] [blame] | 16 | #ifndef CLANG_MODERNIZE_CUSTOMMATCHERS_H |
| 17 | #define CLANG_MODERNIZE_CUSTOMMATCHERS_H |
| Ariel J. Bernal | 601858a | 2013-07-15 15:37:05 +0000 | [diff] [blame] | 18 | |
| 19 | #include "clang/ASTMatchers/ASTMatchers.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | namespace ast_matchers { |
| 23 | |
| 24 | /// \brief Matches declarations whose declaration context is the C++ standard |
| 25 | /// library namespace \c std. |
| 26 | /// |
| 27 | /// Note that inline namespaces are silently ignored during the lookup since |
| 28 | /// both libstdc++ and libc++ are known to use them for versioning purposes. |
| 29 | /// |
| 30 | /// Given |
| 31 | /// \code |
| 32 | /// namespace ns { |
| 33 | /// struct my_type {}; |
| 34 | /// using namespace std; |
| 35 | /// } |
| 36 | /// |
| 37 | /// using std::vector; |
| 38 | /// using ns::my_type; |
| 39 | /// using ns::list; |
| 40 | /// \endcode |
| 41 | /// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace()))) |
| 42 | /// matches "using std::vector" and "using ns::list". |
| 43 | AST_MATCHER(Decl, isFromStdNamespace) { |
| 44 | const DeclContext *D = Node.getDeclContext(); |
| 45 | |
| 46 | while (D->isInlineNamespace()) |
| 47 | D = D->getParent(); |
| 48 | |
| 49 | if (!D->isNamespace() || !D->getParent()->isTranslationUnit()) |
| 50 | return false; |
| 51 | |
| 52 | const IdentifierInfo *Info = cast<NamespaceDecl>(D)->getIdentifier(); |
| 53 | |
| 54 | return Info && Info->isStr("std"); |
| 55 | } |
| 56 | } // namespace ast_matchers |
| 57 | } // namespace clang |
| 58 | |
| Chandler Carruth | 35c0361 | 2013-09-04 19:13:50 +0000 | [diff] [blame] | 59 | #endif // CLANG_MODERNIZE_CUSTOMMATCHERS_H |