[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / clang-tools-extra / clang-tidy / llvmlibc / ImplementationInNamespaceCheck.cpp
blobd05310f09ef773a7d75ab8b31fcfeda92b31e2d7
1 //===--- ImplementationInNamespaceCheck.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 "ImplementationInNamespaceCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers;
15 namespace clang::tidy::llvm_libc {
17 const static StringRef RequiredNamespace = "__llvm_libc";
18 void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
19 Finder->addMatcher(
20 decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
21 .bind("child_of_translation_unit"),
22 this);
25 void ImplementationInNamespaceCheck::check(
26 const MatchFinder::MatchResult &Result) {
27 const auto *MatchedDecl =
28 Result.Nodes.getNodeAs<Decl>("child_of_translation_unit");
29 if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
30 return;
32 if (const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl)) {
33 if (NS->getName() != RequiredNamespace) {
34 diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
35 << RequiredNamespace;
37 return;
39 diag(MatchedDecl->getLocation(),
40 "declaration must be declared within the '%0' namespace")
41 << RequiredNamespace;
44 } // namespace clang::tidy::llvm_libc