Added generate_message_comments configuration option

This commit is contained in:
Bartek Kryza
2023-10-15 19:59:06 +02:00
parent c4d3d61770
commit 03e8c867f4
14 changed files with 127 additions and 0 deletions

View File

@@ -849,4 +849,30 @@ bool parse_source_location(const std::string &location_str, std::string &file,
return true;
}
std::optional<std::string> get_expression_comment(
const clang::SourceManager &sm, const clang::ASTContext &context,
const clang::Stmt *stmt)
{
// First get the first line of the expression
auto expr_begin = stmt->getSourceRange().getBegin();
const auto expr_begin_line = sm.getSpellingLineNumber(expr_begin);
if (!context.Comments.empty())
for (const auto [offset, raw_comment] :
*context.Comments.getCommentsInFile(sm.getMainFileID())) {
auto comment =
raw_comment->getFormattedText(sm, sm.getDiagnostics());
const auto comment_end_line = sm.getSpellingLineNumber(
raw_comment->getSourceRange().getEnd());
if (expr_begin_line == comment_end_line ||
expr_begin_line == comment_end_line + 1)
return comment;
}
return {};
}
} // namespace clanguml::common

View File

@@ -282,4 +282,8 @@ clang::QualType dereference(clang::QualType type);
std::pair<clang::QualType, std::deque<common::model::context>>
consume_type_context(clang::QualType type);
std::optional<std::string> get_expression_comment(
const clang::SourceManager &sm, const clang::ASTContext &context,
const clang::Stmt *stmt);
} // namespace clanguml::common