1 //===--- ElseAfterReturnCheck.h - clang-tidy---------------------*- C++ -*-===// 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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H 11 12 #include "../ClangTidyCheck.h" 13 #include "llvm/ADT/DenseMap.h" 14 15 namespace clang { 16 namespace tidy { 17 namespace readability { 18 19 /// Flags the usages of `else` after `return`. 20 /// 21 /// http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return 22 class ElseAfterReturnCheck : public ClangTidyCheck { 23 public: 24 ElseAfterReturnCheck(StringRef Name, ClangTidyContext *Context); 25 26 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 27 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, 28 Preprocessor *ModuleExpanderPP) override; 29 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 31 32 using ConditionalBranchMap = 33 llvm::DenseMap<FileID, SmallVector<SourceRange, 1>>; 34 35 private: 36 const bool WarnOnUnfixable; 37 const bool WarnOnConditionVariables; 38 ConditionalBranchMap PPConditionals; 39 }; 40 41 } // namespace readability 42 } // namespace tidy 43 } // namespace clang 44 45 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H 46