@@ -17,11 +17,15 @@ using namespace clang::ast_matchers;
1717namespace clang ::tidy::readability {
1818class UseCppStyleCommentsCheck ::CStyleCommentHandler : public CommentHandler {
1919public:
20- CStyleCommentHandler (UseCppStyleCommentsCheck &Check)
20+ CStyleCommentHandler (UseCppStyleCommentsCheck &Check, bool ExcludeDoxygen )
2121 : Check(Check),
2222 CStyleCommentMatch (
23- " ^[ \t ]*/\\ *+[ \t\r\n ]*(.*[ \t\r\n ]*)*[ \t\r\n ]*\\ *+/[ \t\r\n ]*$" ) {
24- }
23+ " ^[ \t ]*/\\ *+[ \t\r\n ]*(.*[ \t\r\n ]*)*[ \t\r\n ]*\\ *+/[ \t\r\n ]*$" ),
24+ ExcludeDoxygen(ExcludeDoxygen) {}
25+
26+ void setExcludeDoxygen (bool Exclude) { ExcludeDoxygen = Exclude; }
27+
28+ bool isExcludeDoxygen () const { return ExcludeDoxygen; }
2529
2630 std::string convertToCppStyleComment (const SourceManager &SM,
2731 const SourceRange &Range) {
@@ -58,6 +62,14 @@ class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
5862 return Result;
5963 }
6064
65+ bool isDoxygenStyleComment (const StringRef &Text) {
66+ StringRef Trimmed = Text.ltrim ();
67+ return Trimmed.starts_with (" /**" ) || Trimmed.starts_with (" /*!" ) ||
68+ Trimmed.starts_with (" ///" ) || Trimmed.starts_with (" //!" ) ||
69+ (Trimmed.starts_with (" /*" ) &&
70+ Trimmed.drop_front (2 ).starts_with (" *" ));
71+ }
72+
6173 bool CheckForInlineComments (Preprocessor &PP, SourceRange Range) {
6274 const SourceManager &SM = PP.getSourceManager ();
6375 const SourceLocation CommentStart = Range.getBegin ();
@@ -100,6 +112,10 @@ class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
100112 const StringRef Text = Lexer::getSourceText (
101113 CharSourceRange::getCharRange (Range), SM, PP.getLangOpts ());
102114
115+ if (ExcludeDoxygen && isDoxygenStyleComment (Text)) {
116+ return false ;
117+ }
118+
103119 SmallVector<StringRef> Matches;
104120 if (!CStyleCommentMatch.match (Text, &Matches)) {
105121 return false ;
@@ -120,13 +136,15 @@ class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
120136
121137private:
122138 UseCppStyleCommentsCheck &Check;
139+ bool ExcludeDoxygen;
123140 llvm::Regex CStyleCommentMatch;
124141};
125142
126143UseCppStyleCommentsCheck::UseCppStyleCommentsCheck (StringRef Name,
127144 ClangTidyContext *Context)
128145 : ClangTidyCheck(Name, Context),
129- Handler(std::make_unique<CStyleCommentHandler>(*this )) {}
146+ Handler(std::make_unique<CStyleCommentHandler>(
147+ *this , Options.get(" ExcludeDoxygenStyleComments" , false ))) {}
130148
131149void UseCppStyleCommentsCheck::registerPPCallbacks (
132150 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
@@ -135,5 +153,10 @@ void UseCppStyleCommentsCheck::registerPPCallbacks(
135153
136154void UseCppStyleCommentsCheck::check (const MatchFinder::MatchResult &Result) {}
137155
156+ void UseCppStyleCommentsCheck::storeOptions (ClangTidyOptions::OptionMap &Opts) {
157+ Options.store (Opts, " ExcludeDoxygenStyleComments" ,
158+ Handler->isExcludeDoxygen ());
159+ }
160+
138161UseCppStyleCommentsCheck::~UseCppStyleCommentsCheck () = default ;
139- } // namespace clang::tidy::readability
162+ } // namespace clang::tidy::readability
0 commit comments