[PATCH] D142560: Allow getRawCommentForDecl to find comments in macros
Ben Barham via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 21:28:47 PDT 2023
bnbarham added inline comments.
================
Comment at: clang/test/Index/annotate-comments-objc.m:67-74
+#define DECLARE_ENUMS(name) \
+ /** enumFromMacro IS_DOXYGEN_SINGLE */ \
+ enum enumFromMacro { A }; \
+ /** namedEnumFromMacro IS_DOXYGEN_SINGLE */ \
+ enum name { B };
+
+/// IS_DOXYGEN_NOT_ATTACHED
----------------
What was the original motivation for the PR here? Was it the `DECLARE_FUNCTIONS` case above?
For this case, personally I would expect that something like:
```
#define DEFINE_TAG(name) \
<anytagdecl> name { .... };
/// Comment attached to foo
DEFINE_TAG(foo)
/// Comment attached to bar
DEFINE_TAG(bar)
```
Is far more common than the test case here. To put another way, the previous
```
if (const auto *TD = dyn_cast<TagDecl>(D)) {
// If location of the tag decl is inside a macro, but the spelling of
// the tag name comes from a macro argument, it looks like a special
// macro like NS_ENUM is being used to define the tag decl. In that
// case, adjust the source location to the expansion loc so that we can
// attach the comment to the tag decl.
if (SourceMgr.isMacroArgExpansion(DeclLoc) && TD->isCompleteDefinition())
return SourceMgr.getExpansionLoc(DeclLoc);
}
```
Seems more reasonable to me than the hardcoded macro-name check. Even `NS_*`-wise there's also `NS_ERROR_ENUM`, `NS_TYPED_ENUM`, `NS_TYPED_EXTENSIBLE_ENUM`, `NS_CLOSED_ENUM`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142560/new/
https://reviews.llvm.org/D142560
More information about the cfe-commits
mailing list