llvm-project
46 строк · 1.6 Кб
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
9#include "NoInternalDependenciesCheck.h"10#include "AbseilMatcher.h"11#include "clang/AST/ASTContext.h"12#include "clang/ASTMatchers/ASTMatchFinder.h"13
14using namespace clang::ast_matchers;15
16namespace clang::tidy::abseil {17
18void NoInternalDependenciesCheck::registerMatchers(MatchFinder *Finder) {19// TODO: refactor matcher to be configurable or just match on any internal20// access from outside the enclosing namespace.21
22Finder->addMatcher(23nestedNameSpecifierLoc(loc(specifiesNamespace(namespaceDecl(24matchesName("internal"),25hasParent(namespaceDecl(hasName("absl")))))),26unless(isInAbseilFile()))27.bind("InternalDep"),28this);29}
30
31void NoInternalDependenciesCheck::check(const MatchFinder::MatchResult &Result) {32const auto *InternalDependency =33Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep");34
35SourceLocation LocAtFault =36Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc());37
38if (!LocAtFault.isValid())39return;40
41diag(LocAtFault,42"do not reference any 'internal' namespaces; those implementation "43"details are reserved to Abseil");44}
45
46} // namespace clang::tidy::abseil47