Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:18

0001 //===--- ArgumentCommentCheck.h - clang-tidy --------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "llvm/Support/Regex.h"
0014 
0015 namespace clang::tidy::bugprone {
0016 
0017 /// Checks that argument comments match parameter names.
0018 ///
0019 /// The check understands argument comments in the form `/*parameter_name=*/`
0020 /// that are placed right before the argument.
0021 ///
0022 /// \code
0023 ///   void f(bool foo);
0024 ///
0025 ///   ...
0026 ///   f(/*bar=*/true);
0027 ///   // warning: argument name 'bar' in comment does not match parameter name
0028 ///   'foo'
0029 /// \endcode
0030 ///
0031 /// The check tries to detect typos and suggest automated fixes for them.
0032 class ArgumentCommentCheck : public ClangTidyCheck {
0033 public:
0034   ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context);
0035 
0036   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0037   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0038   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0039 
0040 private:
0041   const unsigned StrictMode : 1;
0042   const unsigned IgnoreSingleArgument : 1;
0043   const unsigned CommentBoolLiterals : 1;
0044   const unsigned CommentIntegerLiterals : 1;
0045   const unsigned CommentFloatLiterals : 1;
0046   const unsigned CommentStringLiterals : 1;
0047   const unsigned CommentUserDefinedLiterals : 1;
0048   const unsigned CommentCharacterLiterals : 1;
0049   const unsigned CommentNullPtrs : 1;
0050   llvm::Regex IdentRE;
0051 
0052   void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
0053                      SourceLocation ArgBeginLoc,
0054                      llvm::ArrayRef<const Expr *> Args);
0055 
0056   bool shouldAddComment(const Expr *Arg) const;
0057 };
0058 
0059 } // namespace clang::tidy::bugprone
0060 
0061 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H