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