22#if LLVM_VERSION_MAJOR > 17
23#define CLANG_UML_LLVM_COMMENT_KIND(COMMENT_KIND) \
24 clang::comments::CommentKind::COMMENT_KIND
26#define CLANG_UML_LLVM_COMMENT_KIND(COMMENT_KIND) \
27 clang::comments::Comment::COMMENT_KIND##Kind
41 decl.getASTContext().getRawCommentForDeclNoCache(&decl);
43 if (comment ==
nullptr) {
49 auto formatted_comment = comment->getFormattedText(
53 cmt[
"raw"] = raw_comment;
54 cmt[
"formatted"] = formatted_comment;
56 using clang::comments::BlockCommandComment;
57 using clang::comments::FullComment;
58 using clang::comments::ParagraphComment;
59 using clang::comments::ParamCommandComment;
60 using clang::comments::TextComment;
61 using clang::comments::TParamCommandComment;
63 FullComment *full_comment =
64 comment->parse(decl.getASTContext(),
nullptr, &decl);
66 const auto &traits = decl.getASTContext().getCommentCommandTraits();
68 for (
const auto *block : full_comment->getBlocks()) {
69 const auto block_kind = block->getCommentKind();
71 std::string paragraph_text;
75 if (!cmt.contains(
"text"))
79 cmt[
"text"].get<std::string>() +
"\n" + paragraph_text;
81 if (!cmt.contains(
"paragraph"))
82 cmt[
"paragraph"] = inja::json::array();
84 cmt[
"paragraph"].push_back(paragraph_text);
89 else if (block_kind ==
92 clang::dyn_cast<ParamCommandComment>(block), traits, cmt);
94 else if (block_kind ==
97 clang::dyn_cast<TParamCommandComment>(block), traits, cmt);
99 else if (block_kind ==
101 if (
const auto *command =
102 clang::dyn_cast<BlockCommandComment>(block);
103 command !=
nullptr) {
104 const auto *command_info =
105 traits.getCommandInfo(command->getCommandID());
107 if (command_info->IsBlockCommand &&
108 command_info->NumArgs == 0U) {
115 else if (command_info->IsParamCommand) {
119 clang::dyn_cast<ParamCommandComment>(command), traits,
122 else if (command_info->IsTParamCommand) {
126 clang::dyn_cast<TParamCommandComment>(command), traits,
136 const clang::comments::BlockCommandComment *command,
139 using clang::comments::Comment;
140 using clang::comments::ParagraphComment;
141 using clang::comments::TextComment;
143 std::string command_text;
145 for (
const auto *paragraph_it = command->child_begin();
146 paragraph_it != command->child_end(); ++paragraph_it) {
148 if ((*paragraph_it)->getCommentKind() ==
151 traits, command_text);
155 const auto command_name = command->getCommandName(traits).str();
156 if (!command_text.empty()) {
157 if (!cmt.contains(command_name))
158 cmt[command_name] = inja::json::array();
160 cmt[command_name].push_back(command_text);
165 const clang::comments::ParamCommandComment *command,
168 using clang::comments::Comment;
169 using clang::comments::ParagraphComment;
170 using clang::comments::TextComment;
172 std::string description;
174 if (command ==
nullptr)
177 const auto name = command->getParamNameAsWritten().str();
179 for (
const auto *it = command->child_begin(); it != command->child_end();
182 if ((*it)->getCommentKind() ==
185 clang::dyn_cast<ParagraphComment>(*it), traits, description);
190 if (!cmt.contains(
"param"))
191 cmt[
"param"] = inja::json::array();
193 inja::json param = inja::json::object();
194 param[
"name"] = name;
195 param[
"description"] =
util::trim(description);
196 cmt[
"param"].push_back(std::move(param));
201 const clang::comments::TParamCommandComment *command,
204 using clang::comments::Comment;
205 using clang::comments::ParagraphComment;
206 using clang::comments::TextComment;
208 std::string description;
210 if (command ==
nullptr)
213 const auto name = command->getParamNameAsWritten().str();
215 for (
const auto *it = command->child_begin(); it != command->child_end();
217 if ((*it)->getCommentKind() ==
220 clang::dyn_cast<ParagraphComment>(*it), traits, description);
225 if (!cmt.contains(
"tparam"))
226 cmt[
"tparam"] = inja::json::array();
228 inja::json param = inja::json::object();
229 param[
"name"] = name;
230 param[
"description"] =
util::trim(description);
231 cmt[
"tparam"].push_back(std::move(param));
236 const clang::comments::ParagraphComment *paragraph,
237 const clang::comments::CommandTraits & , std::string &text)
239 using clang::comments::Comment;
240 using clang::comments::TextComment;
242 if (paragraph ==
nullptr)
245 for (
const auto *text_it = paragraph->child_begin();
246 text_it != paragraph->child_end(); ++text_it) {
248 if ((*text_it)->getCommentKind() ==
250 clang::dyn_cast<TextComment>(*text_it) !=
nullptr) {
252 text += clang::dyn_cast<TextComment>(*text_it)->getText();