Added calls through pointers and references in template instantiation sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-11-29 22:55:49 +01:00
parent 0e3c69ce38
commit 9c3d65bf47
4 changed files with 48 additions and 5 deletions

View File

@@ -567,7 +567,9 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr)
clang::dyn_cast_or_null<clang::CXXDependentScopeMemberExpr>(
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<clang::TemplateSpecializationType>()
@@ -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<clang::TemplateSpecializationType>() &&
!dependent_member_callee->getBaseType()
->getAs<clang::TemplateSpecializationType>()
->isPointerType();
}
bool translation_unit_visitor::is_smart_pointer(
const clang::TemplateDecl *primary_template) const
{

View File

@@ -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_;

View File

@@ -31,10 +31,27 @@ template <typename T, typename F> struct BB {
};
template <typename T> struct BB<T, std::string> {
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<T> aa_;
BB<T, std::string>(AA<T> *aa)
: aa_{aa}
{
}
AA<T> *aa_;
};
template <typename T> struct BB<T, float> {
void bb1(T t, float f) { bb2(t, f); }
void bb2(T t, float f) { aa_.aa2(t); }
BB<T, float>(AA<T> &aa)
: aa_{aa}
{
}
AA<T> &aa_;
};
void tmain()
@@ -46,13 +63,17 @@ void tmain()
bstring.b("bstring");
BB<int, int> bbint;
BB<int, std::string> bbstring;
AA<int> aaint;
BB<int, std::string> bbstring{&aaint};
BB<int, float> 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);
}
}
}

View File

@@ -58,6 +58,11 @@ TEST_CASE("t20006", "[test-case][sequence]")
REQUIRE_THAT(
puml, HasCall(_A("BB<int,std::string>"), _A("AA<int>"), "aa1"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("BB<int,float>"), "bb1"));
REQUIRE_THAT(
puml, HasCall(_A("BB<int,float>"), _A("BB<int,float>"), "bb2"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,float>"), _A("AA<int>"), "aa2"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}