ArgumentCommentCheck.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===--- ArgumentCommentCheck.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_ARGUMENTCOMMENTCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. #include "llvm/Support/Regex.h"
  12. namespace clang::tidy::bugprone {
  13. /// Checks that argument comments match parameter names.
  14. ///
  15. /// The check understands argument comments in the form `/*parameter_name=*/`
  16. /// that are placed right before the argument.
  17. ///
  18. /// \code
  19. /// void f(bool foo);
  20. ///
  21. /// ...
  22. /// f(/*bar=*/true);
  23. /// // warning: argument name 'bar' in comment does not match parameter name
  24. /// 'foo'
  25. /// \endcode
  26. ///
  27. /// The check tries to detect typos and suggest automated fixes for them.
  28. class ArgumentCommentCheck : public ClangTidyCheck {
  29. public:
  30. ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context);
  31. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  32. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  33. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  34. private:
  35. const unsigned StrictMode : 1;
  36. const unsigned IgnoreSingleArgument : 1;
  37. const unsigned CommentBoolLiterals : 1;
  38. const unsigned CommentIntegerLiterals : 1;
  39. const unsigned CommentFloatLiterals : 1;
  40. const unsigned CommentStringLiterals : 1;
  41. const unsigned CommentUserDefinedLiterals : 1;
  42. const unsigned CommentCharacterLiterals : 1;
  43. const unsigned CommentNullPtrs : 1;
  44. llvm::Regex IdentRE;
  45. void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
  46. SourceLocation ArgBeginLoc,
  47. llvm::ArrayRef<const Expr *> Args);
  48. bool shouldAddComment(const Expr *Arg) const;
  49. };
  50. } // namespace clang::tidy::bugprone
  51. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H