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