blob: 0c66ffbdb3554c46fe4480499f8280bd9a05236e [file] [log] [blame]
Peter Collingbourne35c3f612014-03-18 04:46:45 +00001//===--- ArgumentCommentCheck.h - clang-tidy --------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Peter Collingbourne35c3f612014-03-18 04:46:45 +00006//
7//===----------------------------------------------------------------------===//
8
Alexander Kornienkod4ac4af2017-11-24 14:16:29 +00009#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
Peter Collingbourne35c3f612014-03-18 04:46:45 +000011
Alexander Kornienko478fc5c2019-03-25 12:38:26 +000012#include "../ClangTidyCheck.h"
Peter Collingbourne35c3f612014-03-18 04:46:45 +000013#include "llvm/Support/Regex.h"
14
15namespace clang {
16namespace tidy {
Alexander Kornienko6f67bcb2017-11-23 17:02:48 +000017namespace bugprone {
Peter Collingbourne35c3f612014-03-18 04:46:45 +000018
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000019/// Checks that argument comments match parameter names.
20///
21/// The check understands argument comments in the form `/*parameter_name=*/`
22/// that are placed right before the argument.
23///
24/// \code
25/// void f(bool foo);
26///
27/// ...
28/// f(/*bar=*/true);
Paul Hoad6bfd7212019-02-08 17:00:01 +000029/// // warning: argument name 'bar' in comment does not match parameter name
30/// 'foo'
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000031/// \endcode
32///
33/// The check tries to detect typos and suggest automated fixes for them.
Peter Collingbourne35c3f612014-03-18 04:46:45 +000034class ArgumentCommentCheck : public ClangTidyCheck {
35public:
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +000036 ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context);
NAKAMURA Takumiafc49652014-03-18 07:22:43 +000037
Peter Collingbourne35c3f612014-03-18 04:46:45 +000038 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +000040 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
Peter Collingbourne35c3f612014-03-18 04:46:45 +000041
42private:
Paul Hoad6bfd7212019-02-08 17:00:01 +000043 const unsigned StrictMode : 1;
Alexander Kornienko42443e52019-09-05 14:48:23 +000044 const unsigned IgnoreSingleArgument : 1;
Paul Hoad6bfd7212019-02-08 17:00:01 +000045 const unsigned CommentBoolLiterals : 1;
46 const unsigned CommentIntegerLiterals : 1;
47 const unsigned CommentFloatLiterals : 1;
48 const unsigned CommentStringLiterals : 1;
49 const unsigned CommentUserDefinedLiterals : 1;
50 const unsigned CommentCharacterLiterals : 1;
51 const unsigned CommentNullPtrs : 1;
NAKAMURA Takumiafc49652014-03-18 07:22:43 +000052 llvm::Regex IdentRE;
Peter Collingbourne35c3f612014-03-18 04:46:45 +000053
Peter Collingbourne35c3f612014-03-18 04:46:45 +000054 void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
55 SourceLocation ArgBeginLoc,
56 llvm::ArrayRef<const Expr *> Args);
Paul Hoad6bfd7212019-02-08 17:00:01 +000057
58 bool shouldAddComment(const Expr *Arg) const;
Peter Collingbourne35c3f612014-03-18 04:46:45 +000059};
60
Alexander Kornienko6f67bcb2017-11-23 17:02:48 +000061} // namespace bugprone
Peter Collingbourne35c3f612014-03-18 04:46:45 +000062} // namespace tidy
63} // namespace clang
64
Alexander Kornienkod4ac4af2017-11-24 14:16:29 +000065#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H