From 9c3d65bf473125a31c01773647b6ab26bedf856b Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 29 Nov 2022 22:55:49 +0100 Subject: [PATCH] Added calls through pointers and references in template instantiation sequence diagram test case --- .../visitor/translation_unit_visitor.cc | 15 +++++++++- .../visitor/translation_unit_visitor.h | 4 +++ tests/t20006/t20006.cc | 29 ++++++++++++++++--- tests/t20006/test_case.h | 5 ++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.cc b/src/sequence_diagram/visitor/translation_unit_visitor.cc index 3b44e8c6..b0bb88d3 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.cc +++ b/src/sequence_diagram/visitor/translation_unit_visitor.cc @@ -567,7 +567,9 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr) clang::dyn_cast_or_null( function_call_expr->getCallee()); - if (!dependent_member_callee->getBaseType().isNull()) { + if (is_callee_valid_template_specialization( + dependent_member_callee)) { + const auto *primary_template = dependent_member_callee->getBaseType() ->getAs() @@ -715,6 +717,17 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr) return true; } +bool translation_unit_visitor::is_callee_valid_template_specialization( + const clang::CXXDependentScopeMemberExpr *dependent_member_callee) const +{ + return !dependent_member_callee->getBaseType().isNull() && + dependent_member_callee->getBaseType() + ->getAs() && + !dependent_member_callee->getBaseType() + ->getAs() + ->isPointerType(); +} + bool translation_unit_visitor::is_smart_pointer( const clang::TemplateDecl *primary_template) const { diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.h b/src/sequence_diagram/visitor/translation_unit_visitor.h index 9d1d2a96..02d42516 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.h +++ b/src/sequence_diagram/visitor/translation_unit_visitor.h @@ -302,6 +302,10 @@ private: bool is_smart_pointer(const clang::TemplateDecl *primary_template) const; + bool is_callee_valid_template_specialization( + const clang::CXXDependentScopeMemberExpr *dependent_member_callee) + const; + // Reference to the output diagram model clanguml::sequence_diagram::model::diagram &diagram_; diff --git a/tests/t20006/t20006.cc b/tests/t20006/t20006.cc index e0d6e2b3..f76e9d54 100644 --- a/tests/t20006/t20006.cc +++ b/tests/t20006/t20006.cc @@ -31,10 +31,27 @@ template struct BB { }; template struct BB { - void bb1(T t, std::string f) { aa_.aa2(t); } - void bb2(T t, std::string f) { aa_.aa1(t); } + void bb1(T t, std::string f) { aa_->aa2(t); } + void bb2(T t, std::string f) { aa_->aa1(t); } - AA aa_; + BB(AA *aa) + : aa_{aa} + { + } + + AA *aa_; +}; + +template struct BB { + void bb1(T t, float f) { bb2(t, f); } + void bb2(T t, float f) { aa_.aa2(t); } + + BB(AA &aa) + : aa_{aa} + { + } + + AA &aa_; }; void tmain() @@ -46,13 +63,17 @@ void tmain() bstring.b("bstring"); BB bbint; - BB bbstring; + AA aaint; + BB bbstring{&aaint}; + BB bbfloat{aaint}; bbint.bb1(1, 1); bbint.bb2(2, 2); bbstring.bb1(1, "calling aa2"); bbstring.bb2(1, "calling aa1"); + + bbfloat.bb1(1, 1.0f); } } } \ No newline at end of file diff --git a/tests/t20006/test_case.h b/tests/t20006/test_case.h index 539f8ffc..77ba8a6b 100644 --- a/tests/t20006/test_case.h +++ b/tests/t20006/test_case.h @@ -58,6 +58,11 @@ TEST_CASE("t20006", "[test-case][sequence]") REQUIRE_THAT( puml, HasCall(_A("BB"), _A("AA"), "aa1")); + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("BB"), "bb1")); + REQUIRE_THAT( + puml, HasCall(_A("BB"), _A("BB"), "bb2")); + REQUIRE_THAT(puml, HasCall(_A("BB"), _A("AA"), "aa2")); + save_puml( "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); } \ No newline at end of file