brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 8f6b5a4 Raw
55 lines · c
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#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESCOPEDLOCKCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESCOPEDLOCKCHECK_H11 12#include "../ClangTidyCheck.h"13#include "clang/AST/ASTTypeTraits.h"14#include "clang/AST/Stmt.h"15#include <optional>16 17namespace clang::tidy::modernize {18 19/// Finds uses of ``std::lock_guard`` and suggests replacing them with C++17's20/// alternative ``std::scoped_lock``.21///22/// For the user-facing documentation see:23/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-scoped-lock.html24class UseScopedLockCheck : public ClangTidyCheck {25public:26  UseScopedLockCheck(StringRef Name, ClangTidyContext *Context);27  void registerMatchers(ast_matchers::MatchFinder *Finder) override;28  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;29  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;30  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {31    return LangOpts.CPlusPlus17;32  }33  std::optional<TraversalKind> getCheckTraversalKind() const override {34    return TK_IgnoreUnlessSpelledInSource;35  }36 37private:38  void diagOnSingleLock(const VarDecl *LockGuard,39                        const ast_matchers::MatchFinder::MatchResult &Result);40  void diagOnMultipleLocks(41      const llvm::SmallVector<llvm::SmallVector<const VarDecl *>> &LockGroups,42      const ast_matchers::MatchFinder::MatchResult &Result);43  void diagOnSourceInfo(const TypeSourceInfo *LockGuardSourceInfo,44                        const ast_matchers::MatchFinder::MatchResult &Result);45  void diagOnUsingDecl(const UsingDecl *UsingDecl,46                       const ast_matchers::MatchFinder::MatchResult &Result);47 48  const bool WarnOnSingleLocks;49  const bool WarnOnUsingAndTypedef;50};51 52} // namespace clang::tidy::modernize53 54#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESCOPEDLOCKCHECK_H55