Added handling of comment decorators (skip, note) in sequence diagram comments (#194)

This commit is contained in:
Bartek Kryza
2023-10-21 17:07:28 +02:00
parent ddbfffbf23
commit 7f595b1c54
19 changed files with 403 additions and 45 deletions

View File

@@ -59,7 +59,6 @@ clang::SourceManager &translation_unit_visitor::source_manager() const
void translation_unit_visitor::process_comment(
const clang::NamedDecl &decl, clanguml::common::model::decorated_element &e)
{
assert(comment_visitor_.get() != nullptr);
comment_visitor_->visit(decl, e);
@@ -67,12 +66,23 @@ void translation_unit_visitor::process_comment(
const auto *comment =
decl.getASTContext().getRawCommentForDeclNoCache(&decl);
process_comment(comment, decl.getASTContext().getDiagnostics(), e);
}
void translation_unit_visitor::process_comment(const clang::RawComment *comment,
clang::DiagnosticsEngine &de, clanguml::common::model::decorated_element &e)
{
if (comment != nullptr) {
auto [it, inserted] = processed_comments_.emplace(comment);
if (!inserted)
return;
// Process clang-uml decorators in the comments
// TODO: Refactor to use standard block comments processable by clang
// comments
e.add_decorators(decorators::parse(comment->getFormattedText(
source_manager_, decl.getASTContext().getDiagnostics())));
e.add_decorators(
decorators::parse(comment->getFormattedText(source_manager_, de)));
}
}

View File

@@ -102,7 +102,7 @@ public:
protected:
/**
* @brief Set source location in diagram element
* @brief Process comment directives in comment attached to a declaration
*
* @param decl Reference to @ref clang::NamedDecl
* @param element Reference to element to be updated
@@ -110,6 +110,17 @@ protected:
void process_comment(const clang::NamedDecl &decl,
clanguml::common::model::decorated_element &e);
/**
* @brief Process comment directives in raw comment
*
* @param comment clang::RawComment pointer
* @param de Reference to clang::DiagnosticsEngine
* @param element Reference to element to be updated
*/
void process_comment(const clang::RawComment *comment,
clang::DiagnosticsEngine &de,
clanguml::common::model::decorated_element &e);
private:
clang::SourceManager &source_manager_;
@@ -118,5 +129,7 @@ private:
std::filesystem::path relative_to_path_;
std::filesystem::path translation_unit_path_;
std::set<const clang::RawComment *> processed_comments_;
};
} // namespace clanguml::common::visitor