clang-tools 8.0.0

NoInternalDependenciesCheck.cpp
Go to the documentation of this file.
1 //===--- NoInternalDependenciesCheck.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 "NoInternalDependenciesCheck.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 NoInternalDependenciesCheck::registerMatchers(MatchFinder *Finder) {
22 if (!getLangOpts().CPlusPlus)
23 return;
24
25 // TODO: refactor matcher to be configurable or just match on any internal
26 // access from outside the enclosing namespace.
27
28 Finder->addMatcher(
29 nestedNameSpecifierLoc(loc(specifiesNamespace(namespaceDecl(
30 matchesName("internal"),
31 hasParent(namespaceDecl(hasName("absl")))))),
32 unless(isInAbseilFile()))
33 .bind("InternalDep"),
34 this);
35 }
36
37 void NoInternalDependenciesCheck::check(const MatchFinder::MatchResult &Result) {
38 const auto *InternalDependency =
39 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep");
40
41 diag(InternalDependency->getBeginLoc(),
42 "do not reference any 'internal' namespaces; those implementation "
43 "details are reserved to Abseil");
44 }
45
46 } // namespace abseil
47 } // namespace tidy
48 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:15
AbseilMatcher.h
NoInternalDependenciesCheck.h
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18