RedundantVoidArgCheck.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //===--- RedundantVoidArgCheck.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_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
  10. #include "../ClangTidyCheck.h"
  11. #include "clang/Lex/Token.h"
  12. #include <string>
  13. namespace clang::tidy::modernize {
  14. /// Find and remove redundant void argument lists.
  15. ///
  16. /// Examples:
  17. /// `int f(void);` becomes `int f();`
  18. /// `int (*f(void))(void);` becomes `int (*f())();`
  19. /// `typedef int (*f_t(void))(void);` becomes `typedef int (*f_t())();`
  20. /// `void (C::*p)(void);` becomes `void (C::*p)();`
  21. /// `C::C(void) {}` becomes `C::C() {}`
  22. /// `C::~C(void) {}` becomes `C::~C() {}`
  23. ///
  24. class RedundantVoidArgCheck : public ClangTidyCheck {
  25. public:
  26. RedundantVoidArgCheck(StringRef Name, ClangTidyContext *Context)
  27. : ClangTidyCheck(Name, Context) {}
  28. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  29. return LangOpts.CPlusPlus;
  30. }
  31. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  32. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  33. private:
  34. void processFunctionDecl(const ast_matchers::MatchFinder::MatchResult &Result,
  35. const FunctionDecl *Function);
  36. void
  37. processTypedefNameDecl(const ast_matchers::MatchFinder::MatchResult &Result,
  38. const TypedefNameDecl *Typedef);
  39. void processFieldDecl(const ast_matchers::MatchFinder::MatchResult &Result,
  40. const FieldDecl *Member);
  41. void processVarDecl(const ast_matchers::MatchFinder::MatchResult &Result,
  42. const VarDecl *Var);
  43. void
  44. processNamedCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
  45. const CXXNamedCastExpr *NamedCast);
  46. void
  47. processExplicitCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
  48. const ExplicitCastExpr *ExplicitCast);
  49. void processLambdaExpr(const ast_matchers::MatchFinder::MatchResult &Result,
  50. const LambdaExpr *Lambda);
  51. void
  52. removeVoidArgumentTokens(const ast_matchers::MatchFinder::MatchResult &Result,
  53. SourceRange Range, StringRef GrammarLocation);
  54. void removeVoidToken(Token VoidToken, StringRef Diagnostic);
  55. };
  56. } // namespace clang::tidy::modernize
  57. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H