Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 1 | //===--- ArgumentCommentCheck.h - clang-tidy --------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Alexander Kornienko | d4ac4af | 2017-11-24 14:16:29 +0000 | [diff] [blame] | 9 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 11 | |
Alexander Kornienko | 478fc5c | 2019-03-25 12:38:26 +0000 | [diff] [blame] | 12 | #include "../ClangTidyCheck.h" |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Regex.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
Alexander Kornienko | 6f67bcb | 2017-11-23 17:02:48 +0000 | [diff] [blame] | 17 | namespace bugprone { |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 18 | |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 19 | /// 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 Hoad | 6bfd721 | 2019-02-08 17:00:01 +0000 | [diff] [blame] | 29 | /// // warning: argument name 'bar' in comment does not match parameter name |
| 30 | /// 'foo' |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 31 | /// \endcode |
| 32 | /// |
| 33 | /// The check tries to detect typos and suggest automated fixes for them. |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 34 | class ArgumentCommentCheck : public ClangTidyCheck { |
| 35 | public: |
Alexander Kornienko | 6e0cbc8 | 2014-09-12 08:53:36 +0000 | [diff] [blame] | 36 | ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context); |
NAKAMURA Takumi | afc4965 | 2014-03-18 07:22:43 +0000 | [diff] [blame] | 37 | |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 38 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 39 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 40 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 41 | |
| 42 | private: |
Paul Hoad | 6bfd721 | 2019-02-08 17:00:01 +0000 | [diff] [blame] | 43 | const unsigned StrictMode : 1; |
Alexander Kornienko | 42443e5 | 2019-09-05 14:48:23 +0000 | [diff] [blame] | 44 | const unsigned IgnoreSingleArgument : 1; |
Paul Hoad | 6bfd721 | 2019-02-08 17:00:01 +0000 | [diff] [blame] | 45 | 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 Takumi | afc4965 | 2014-03-18 07:22:43 +0000 | [diff] [blame] | 52 | llvm::Regex IdentRE; |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 53 | |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 54 | void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee, |
| 55 | SourceLocation ArgBeginLoc, |
| 56 | llvm::ArrayRef<const Expr *> Args); |
Paul Hoad | 6bfd721 | 2019-02-08 17:00:01 +0000 | [diff] [blame] | 57 | |
| 58 | bool shouldAddComment(const Expr *Arg) const; |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Alexander Kornienko | 6f67bcb | 2017-11-23 17:02:48 +0000 | [diff] [blame] | 61 | } // namespace bugprone |
Peter Collingbourne | 35c3f61 | 2014-03-18 04:46:45 +0000 | [diff] [blame] | 62 | } // namespace tidy |
| 63 | } // namespace clang |
| 64 | |
Alexander Kornienko | d4ac4af | 2017-11-24 14:16:29 +0000 | [diff] [blame] | 65 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H |