EasilySwappableParametersCheck.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::bugprone {
  12. /// Finds function definitions where parameters of convertible types follow
  13. /// each other directly, making call sites prone to calling the function with
  14. /// swapped (or badly ordered) arguments.
  15. ///
  16. /// For the user-facing documentation see:
  17. /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/easily-swappable-parameters.html
  18. class EasilySwappableParametersCheck : public ClangTidyCheck {
  19. public:
  20. EasilySwappableParametersCheck(StringRef Name, ClangTidyContext *Context);
  21. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  22. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  23. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  24. /// The minimum length of an adjacent swappable parameter range required for
  25. /// a diagnostic.
  26. const std::size_t MinimumLength;
  27. /// The parameter names (as written in the source text) to be ignored.
  28. const std::vector<StringRef> IgnoredParameterNames;
  29. /// The parameter typename suffixes (as written in the source code) to be
  30. /// ignored.
  31. const std::vector<StringRef> IgnoredParameterTypeSuffixes;
  32. /// Whether to consider differently qualified versions of the same type
  33. /// mixable.
  34. const bool QualifiersMix;
  35. /// Whether to model implicit conversions "in full" (conditions apply)
  36. /// during analysis and consider types that are implicitly convertible to
  37. /// one another mixable.
  38. const bool ModelImplicitConversions;
  39. /// If enabled, diagnostics for parameters that are used together in a
  40. /// similar way are not emitted.
  41. const bool SuppressParametersUsedTogether;
  42. /// The number of characters two parameter names might be dissimilar at
  43. /// either end for the report about the parameters to be silenced.
  44. /// E.g. the names "LHS" and "RHS" are 1-dissimilar suffixes of each other,
  45. /// while "Text1" and "Text2" are 1-dissimilar prefixes of each other.
  46. const std::size_t NamePrefixSuffixSilenceDissimilarityTreshold;
  47. };
  48. } // namespace clang::tidy::bugprone
  49. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EASILYSWAPPABLEPARAMETERSCHECK_H