clang-tools 10.0.0

NoNamespaceCheck.cpp
Go to the documentation of this file.
1 //===--- NoNamespaceCheck.cpp - clang-tidy---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "NoNamespaceCheck.h"
10 #include "AbseilMatcher.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13
14 using namespace clang::ast_matchers;
15
16 namespace clang {
17 namespace tidy {
18 namespace abseil {
19
20 void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
22 return;
23
24 Finder->addMatcher(
25 namespaceDecl(hasName("::absl"), unless(isInAbseilFile()))
26 .bind("abslNamespace"),
27 this);
28 }
29
30 void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
31 const auto *abslNamespaceDecl =
32 Result.Nodes.getNodeAs<NamespaceDecl>("abslNamespace");
33
34 diag(abslNamespaceDecl->getLocation(),
35 "namespace 'absl' is reserved for implementation of the Abseil library "
36 "and should not be opened in user code");
37 }
38
39 } // namespace abseil
40 } // namespace tidy
41 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:14
AbseilMatcher.h
NoNamespaceCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27