[PATCH] D125061: [clang] A more robust way to attach comments
Zixu Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 5 17:20:37 PDT 2022
zixuw created this revision.
Herald added a subscriber: arphaman.
Herald added a reviewer: dang.
Herald added a project: All.
zixuw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The current implementation in `getRawCommentForDeclNoCacheImpl` to check
if a leading comment is attached to a given `Decl *D` is to see if there
is any of `";{}#@"` between the comment and the source location of `D`,
which indicates that there's other declarations or preprocessor
directives that the comment is meant for. However, this does not work
for enum constants, which are separated by commas.
Comma was originally included in the filter characters list, but removed
in b534d3a0ef69 because macros, attributes and other decorators might
also introduce commas before a declaration. And there's no good way to
reliably and efficiently check if all the commas are from other
declarations.
This patch added a forward pointer in `DeclBase` pointing to the
previous declaration inside the lexical `DeclContext`, similar to the
existing `NextInContextAndBits`. This constructs a doubly linked list so
we can easily query the lexically preceding declaration of the current
decl `D`, to check if any decl falls between the comment and `D`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125061
Files:
clang/include/clang/AST/DeclBase.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclBase.cpp
clang/test/Index/annotate-comments-enum-constant.c
clang/test/Index/annotate-comments.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125061.427499.patch
Type: text/x-patch
Size: 9466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220506/939d0e85/attachment.bin>
More information about the cfe-commits
mailing list