clang-tools 8.0.0

NoNamespaceCheck.cpp
Go to the documentation of this file.
1 //===--- NoNamespaceCheck.cpp - clang-tidy---------------------------------===//
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 #include "NoNamespaceCheck.h"
11 #include "AbseilMatcher.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
14
15 using namespace clang::ast_matchers;
16
17 namespace clang {
18 namespace tidy {
19 namespace abseil {
20
21 void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {
22 if (!getLangOpts().CPlusPlus)
23 return;
24
25 Finder->addMatcher(
26 namespaceDecl(hasName("::absl"), unless(isInAbseilFile()))
27 .bind("abslNamespace"),
28 this);
29 }
30
31 void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
32 const auto *abslNamespaceDecl =
33 Result.Nodes.getNodeAs<NamespaceDecl>("abslNamespace");
34
35 diag(abslNamespaceDecl->getLocation(),
36 "namespace 'absl' is reserved for implementation of the Abseil library "
37 "and should not be opened in user code");
38 }
39
40 } // namespace abseil
41 } // namespace tidy
42 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:15
AbseilMatcher.h
NoNamespaceCheck.h
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18