brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · e28713e Raw
55 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "clang-tidy/ClangTidyCheck.h"10 11#include "nodebug_on_aliases.hpp"12#include "utilities.hpp"13 14namespace libcpp {15namespace {16AST_MATCHER(clang::NamedDecl, isPretty) { return !is_ugly_name(Node.getName()); }17AST_MATCHER(clang::NamedDecl, isUgly) { return is_ugly_name(Node.getName()); }18} // namespace19 20nodebug_on_aliases::nodebug_on_aliases(llvm::StringRef name, clang::tidy::ClangTidyContext* context)21    : clang::tidy::ClangTidyCheck(name, context) {}22 23void nodebug_on_aliases::registerMatchers(clang::ast_matchers::MatchFinder* finder) {24  using namespace clang::ast_matchers;25  finder->addMatcher(26      typeAliasDecl(unless(anyOf(isPretty(), hasAttr(clang::attr::NoDebug), hasAncestor(functionDecl()))))27          .bind("nodebug_on_internal_aliases"),28      this);29 30  finder->addMatcher(31      typeAliasDecl(32          unless(hasAttr(clang::attr::NoDebug)),33          hasName("type"),34          hasAncestor(cxxRecordDecl(unless(has(namedDecl(unless(anyOf(35              typeAliasDecl(hasName("type")),36              typeAliasDecl(isUgly()),37              recordDecl(isImplicit()),38              templateTypeParmDecl(),39              nonTypeTemplateParmDecl(),40              templateTemplateParmDecl()))))))))41          .bind("nodebug_on_type_traits"),42      this);43}44 45void nodebug_on_aliases::check(const clang::ast_matchers::MatchFinder::MatchResult& result) {46  if (const auto* alias = result.Nodes.getNodeAs<clang::TypeAliasDecl>("nodebug_on_internal_aliases")) {47    diag(alias->getBeginLoc(), "Internal aliases should always be marked _LIBCPP_NODEBUG");48  }49 50  if (const auto* alias = result.Nodes.getNodeAs<clang::TypeAliasDecl>("nodebug_on_type_traits")) {51    diag(alias->getBeginLoc(), "The alias of type traits should always be marked _LIBCPP_NODEBUG");52  }53}54} // namespace libcpp55