[clang] associate newline and function decl. trailing Doxygen comments#198534
Open
aydinmercan wants to merge 2 commits into
Open
[clang] associate newline and function decl. trailing Doxygen comments#198534aydinmercan wants to merge 2 commits into
aydinmercan wants to merge 2 commits into
Conversation
The clang AST now correctly matches trailing Doxygen comments for function declarations and also comments that come after the declaration with the same `<` trailing directive.
|
@llvm/pr-subscribers-clang Author: Aydın Mercan (aydinmercan) ChangesThe clang AST now correctly matches trailing Doxygen comments for function declarations and also comments that come after the declaration with the same Full diff: https://github.com/llvm/llvm-project/pull/198534.diff 1 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index bc4771aec77d1..fc2048239ba55 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -243,13 +243,20 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl(
LangOpts.CommentOpts.ParseAllComments) &&
CommentBehindDecl->isTrailingComment() &&
(isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D) ||
- isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D))) {
+ isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D) ||
+ isa<FunctionDecl>(D))) {
- // Check that Doxygen trailing comment comes after the declaration, starts
- // on the same line and in the same file as the declaration.
- if (SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) ==
+ const auto DeclLineNumber =
+ SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second);
+
+ const auto DeclOfCommentLine =
Comments.getCommentBeginLine(CommentBehindDecl, DeclLocDecomp.first,
- OffsetCommentBehindDecl->first)) {
+ OffsetCommentBehindDecl->first);
+
+ // Check that Doxygen trailing comment comes after the declaration, starts
+ // on the same or next line and in the same file as the declaration.
+ if (DeclLineNumber == std::clamp(DeclLineNumber, DeclOfCommentLine,
+ DeclOfCommentLine + 1)) {
return CommentBehindDecl;
}
}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The clang AST now correctly matches trailing Doxygen comments for function declarations and also comments that come after the declaration with the same
<trailing directive.