[AMDGPU][True16][MC] update VOP1 dasm test with latest script (#120281)
[llvm-project.git] / clang-tools-extra / clang-tidy / abseil / NoInternalDependenciesCheck.cpp
blobd04afa48e18de29079c6057e63c02b54aa411b3d
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 //===----------------------------------------------------------------------===//
9 #include "NoInternalDependenciesCheck.h"
10 #include "AbseilMatcher.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
16 namespace clang::tidy::abseil {
18 void NoInternalDependenciesCheck::registerMatchers(MatchFinder *Finder) {
19 // TODO: refactor matcher to be configurable or just match on any internal
20 // access from outside the enclosing namespace.
22 Finder->addMatcher(
23 nestedNameSpecifierLoc(loc(specifiesNamespace(namespaceDecl(
24 matchesName("internal"),
25 hasParent(namespaceDecl(hasName("absl")))))),
26 unless(isInAbseilFile()))
27 .bind("InternalDep"),
28 this);
31 void NoInternalDependenciesCheck::check(const MatchFinder::MatchResult &Result) {
32 const auto *InternalDependency =
33 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep");
35 SourceLocation LocAtFault =
36 Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc());
38 if (!LocAtFault.isValid())
39 return;
41 diag(LocAtFault,
42 "do not reference any 'internal' namespaces; those implementation "
43 "details are reserved to Abseil");
46 } // namespace clang::tidy::abseil