clang-tools  14.0.0git
ElseAfterReturnCheck.h
Go to the documentation of this file.
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
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  llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
32  return TK_IgnoreUnlessSpelledInSource;
33  }
34 
35  using ConditionalBranchMap =
36  llvm::DenseMap<FileID, SmallVector<SourceRange, 1>>;
37 
38 private:
39  const bool WarnOnUnfixable;
40  const bool WarnOnConditionVariables;
41  ConditionalBranchMap PPConditionals;
42 };
43 
44 } // namespace readability
45 } // namespace tidy
46 } // namespace clang
47 
48 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::readability::ElseAfterReturnCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: ElseAfterReturnCheck.cpp:239
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::readability::ElseAfterReturnCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: ElseAfterReturnCheck.cpp:171
clang::tidy::readability::ElseAfterReturnCheck::getCheckTraversalKind
llvm::Optional< TraversalKind > getCheckTraversalKind() const override
Definition: ElseAfterReturnCheck.h:31
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::readability::ElseAfterReturnCheck::ElseAfterReturnCheck
ElseAfterReturnCheck(StringRef Name, ClangTidyContext *Context)
Definition: ElseAfterReturnCheck.cpp:152
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
clang::tidy::readability::ElseAfterReturnCheck
Flags the usages of else after return.
Definition: ElseAfterReturnCheck.h:22
clang::tidy::readability::ElseAfterReturnCheck::ConditionalBranchMap
llvm::DenseMap< FileID, SmallVector< SourceRange, 1 > > ConditionalBranchMap
Definition: ElseAfterReturnCheck.h:36
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::readability::ElseAfterReturnCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: ElseAfterReturnCheck.cpp:159
clang::tidy::readability::ElseAfterReturnCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: ElseAfterReturnCheck.cpp:164