clang-tools  14.0.0git
EasilySwappableParametersCheck.h
Go to the documentation of this file.
1 //===--- EasilySwappableParametersCheck.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_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 
14 namespace clang {
15 namespace tidy {
16 namespace bugprone {
17 
18 /// Finds function definitions where parameters of convertible types follow
19 /// each other directly, making call sites prone to calling the function with
20 /// swapped (or badly ordered) arguments.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-easily-swappable-parameters.html
25 public:
27  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
30 
31  /// The minimum length of an adjacent swappable parameter range required for
32  /// a diagnostic.
33  const std::size_t MinimumLength;
34 
35  /// The parameter names (as written in the source text) to be ignored.
36  const std::vector<std::string> IgnoredParameterNames;
37 
38  /// The parameter typename suffixes (as written in the source code) to be
39  /// ignored.
40  const std::vector<std::string> IgnoredParameterTypeSuffixes;
41 
42  /// Whether to consider differently qualified versions of the same type
43  /// mixable.
44  const bool QualifiersMix;
45 
46  /// Whether to model implicit conversions "in full" (conditions apply)
47  /// during analysis and consider types that are implicitly convertible to
48  /// one another mixable.
50 
51  /// If enabled, diagnostics for parameters that are used together in a
52  /// similar way are not emitted.
54 
55  /// The number of characters two parameter names might be dissimilar at
56  /// either end for the report about the parameters to be silenced.
57  /// E.g. the names "LHS" and "RHS" are 1-dissimilar suffixes of each other,
58  /// while "Text1" and "Text2" are 1-dissimilar prefixes of each other.
60 };
61 
62 } // namespace bugprone
63 } // namespace tidy
64 } // namespace clang
65 
66 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::bugprone::EasilySwappableParametersCheck::EasilySwappableParametersCheck
EasilySwappableParametersCheck(StringRef Name, ClangTidyContext *Context)
Definition: EasilySwappableParametersCheck.cpp:2075
clang::tidy::bugprone::EasilySwappableParametersCheck::SuppressParametersUsedTogether
const bool SuppressParametersUsedTogether
If enabled, diagnostics for parameters that are used together in a similar way are not emitted.
Definition: EasilySwappableParametersCheck.h:53
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::bugprone::EasilySwappableParametersCheck::QualifiersMix
const bool QualifiersMix
Whether to consider differently qualified versions of the same type mixable.
Definition: EasilySwappableParametersCheck.h:44
clang::tidy::bugprone::EasilySwappableParametersCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: EasilySwappableParametersCheck.cpp:2128
clang::tidy::bugprone::EasilySwappableParametersCheck::IgnoredParameterNames
const std::vector< std::string > IgnoredParameterNames
The parameter names (as written in the source text) to be ignored.
Definition: EasilySwappableParametersCheck.h:36
clang::tidy::bugprone::EasilySwappableParametersCheck::MinimumLength
const std::size_t MinimumLength
The minimum length of an adjacent swappable parameter range required for a diagnostic.
Definition: EasilySwappableParametersCheck.h:33
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:76
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::bugprone::EasilySwappableParametersCheck::IgnoredParameterTypeSuffixes
const std::vector< std::string > IgnoredParameterTypeSuffixes
The parameter typename suffixes (as written in the source code) to be ignored.
Definition: EasilySwappableParametersCheck.h:40
clang::tidy::bugprone::EasilySwappableParametersCheck::NamePrefixSuffixSilenceDissimilarityTreshold
const std::size_t NamePrefixSuffixSilenceDissimilarityTreshold
The number of characters two parameter names might be dissimilar at either end for the report about t...
Definition: EasilySwappableParametersCheck.h:59
clang::tidy::bugprone::EasilySwappableParametersCheck::ModelImplicitConversions
const bool ModelImplicitConversions
Whether to model implicit conversions "in full" (conditions apply) during analysis and consider types...
Definition: EasilySwappableParametersCheck.h:49
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::EasilySwappableParametersCheck
Finds function definitions where parameters of convertible types follow each other directly,...
Definition: EasilySwappableParametersCheck.h:24
clang::tidy::bugprone::EasilySwappableParametersCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: EasilySwappableParametersCheck.cpp:2110
clang::tidy::bugprone::EasilySwappableParametersCheck::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: EasilySwappableParametersCheck.cpp:2095