blob: 485a47cd41762d3a8df225fdad65a14bbf8a514a [file] [log] [blame]
Ariel J. Bernal601858a2013-07-15 15:37:05 +00001//===-- 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 Carruth35c03612013-09-04 19:13:50 +000016#ifndef CLANG_MODERNIZE_CUSTOMMATCHERS_H
17#define CLANG_MODERNIZE_CUSTOMMATCHERS_H
Ariel J. Bernal601858a2013-07-15 15:37:05 +000018
19#include "clang/ASTMatchers/ASTMatchers.h"
20
21namespace clang {
22namespace 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".
43AST_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 Carruth35c03612013-09-04 19:13:50 +000059#endif // CLANG_MODERNIZE_CUSTOMMATCHERS_H