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