Fixed handling of arguments in sequence diagrams

This commit is contained in:
Bartek Kryza
2022-12-04 23:38:26 +01:00
parent 1644a201d0
commit 14c2cb6263
9 changed files with 86 additions and 74 deletions

View File

@@ -304,7 +304,7 @@ bool translation_unit_visitor::VisitCXXMethodDecl(clang::CXXMethodDecl *m)
for (const auto *param : m->parameters()) {
m_ptr->add_parameter(simplify_system_template(
common::to_string(param->getType(), m->getASTContext())));
common::to_string(param->getType(), m->getASTContext(), false)));
}
set_source_location(*m, *m_ptr);
@@ -372,8 +372,8 @@ bool translation_unit_visitor::VisitFunctionDecl(clang::FunctionDecl *f)
f_ptr->set_namespace(ns);
for (const auto *param : f->parameters()) {
f_ptr->add_parameter(simplify_system_template(
common::to_string(param->getType(), f->getASTContext())));
f_ptr->add_parameter(simplify_system_template(common::to_string(
param->getType(), f->getASTContext(), false)));
}
f_ptr->set_id(common::to_id(f_ptr->full_name(false)));
@@ -415,7 +415,7 @@ bool translation_unit_visitor::VisitFunctionTemplateDecl(
for (const auto *param :
function_template->getTemplatedDecl()->parameters()) {
f_ptr->add_parameter(simplify_system_template(common::to_string(
param->getType(), function_template->getASTContext())));
param->getType(), function_template->getASTContext(), false)));
}
f_ptr->set_id(common::to_id(f_ptr->full_name(false)));
@@ -426,7 +426,6 @@ bool translation_unit_visitor::VisitFunctionTemplateDecl(
set_unique_id(function_template->getID(), f_ptr->id());
// TODO: Handle overloaded functions with different arguments
diagram().add_participant(std::move(f_ptr));
return true;
@@ -1657,11 +1656,12 @@ bool translation_unit_visitor::simplify_system_template(
std::string translation_unit_visitor::simplify_system_template(
const std::string &full_name) const
{
if (config().type_aliases().count(full_name) > 0) {
return config().type_aliases().at(full_name);
std::string result{full_name};
for(const auto& [k, v] : config().type_aliases()) {
util::replace_all(result, k, v);
}
return full_name;
return result;
}
std::string translation_unit_visitor::make_lambda_name(

View File

@@ -38,30 +38,36 @@ TEST_CASE("t20006", "[test-case][sequence]")
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b(int)"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a1(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b(std::string)"));
REQUIRE_THAT(
puml, HasCall(_A("B<std::string>"), _A("A<std::string>"), "a2"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("BB<int,int>"), "bb1"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,int>"), _A("AA<int>"), "aa1"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("BB<int,int>"), "bb2"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,int>"), _A("AA<int>"), "aa2"));
puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b(std::string)"));
REQUIRE_THAT(puml,
HasCall(_A("B<std::string>"), _A("A<std::string>"), "a2(std::string)"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()"), _A("BB<int,std::string>"), "bb1"));
REQUIRE_THAT(
puml, HasCall(_A("BB<int,std::string>"), _A("AA<int>"), "aa2"));
puml, HasCall(_A("tmain()"), _A("BB<int,int>"), "bb1(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,int>"), _A("AA<int>"), "aa1(int)"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()"), _A("BB<int,std::string>"), "bb2"));
REQUIRE_THAT(
puml, HasCall(_A("BB<int,std::string>"), _A("AA<int>"), "aa1"));
puml, HasCall(_A("tmain()"), _A("BB<int,int>"), "bb2(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,int>"), _A("AA<int>"), "aa2(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("BB<int,float>"), "bb1"));
REQUIRE_THAT(puml,
HasCall(
_A("tmain()"), _A("BB<int,std::string>"), "bb1(int,std::string)"));
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"));
puml, HasCall(_A("BB<int,std::string>"), _A("AA<int>"), "aa2(int)"));
REQUIRE_THAT(puml,
HasCall(
_A("tmain()"), _A("BB<int,std::string>"), "bb2(int,std::string)"));
REQUIRE_THAT(
puml, HasCall(_A("BB<int,std::string>"), _A("AA<int>"), "aa1(int)"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()"), _A("BB<int,float>"), "bb1(int,float)"));
REQUIRE_THAT(puml,
HasCall(_A("BB<int,float>"), _A("BB<int,float>"), "bb2(int,float)"));
REQUIRE_THAT(puml, HasCall(_A("BB<int,float>"), _A("AA<int>"), "aa2(int)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -35,12 +35,14 @@ TEST_CASE("t20007", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("Adder<int,int>"), "add"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()"), _A("Adder<int,float,double>"), "add"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("Adder<int,int>"), "add(int &&,int &&)"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("Adder<int,float,double>"),
"add(int &&,float &&,double &&)"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("Adder<std::string,std::string,std::string>"),
"add"));
"add(std::string &&,std::string &&,std::string &&)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -35,18 +35,21 @@ TEST_CASE("t20008", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a1"));
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a2"));
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a3"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b(int)"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a1(int)"));
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a2(int)"));
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a3(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<const char *>"), "b"));
REQUIRE_THAT(
puml, HasCall(_A("B<const char *>"), _A("A<const char *>"), "a2"));
puml, HasCall(_A("tmain()"), _A("B<const char *>"), "b(const char *)"));
REQUIRE_THAT(puml,
HasCall(
_A("B<const char *>"), _A("A<const char *>"), "a2(const char *)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b"));
REQUIRE_THAT(
puml, HasCall(_A("B<std::string>"), _A("A<std::string>"), "a3"));
puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b(std::string)"));
REQUIRE_THAT(puml,
HasCall(_A("B<std::string>"), _A("A<std::string>"), "a3(std::string)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -35,15 +35,16 @@ TEST_CASE("t20009", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b"));
REQUIRE_THAT(
puml, HasCall(_A("B<std::string>"), _A("A<std::string>"), "a"));
puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b(std::string)"));
REQUIRE_THAT(puml,
HasCall(_A("B<std::string>"), _A("A<std::string>"), "a(std::string)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b(int)"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<float>"), "b"));
REQUIRE_THAT(puml, HasCall(_A("B<float>"), _A("A<float>"), "a"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<float>"), "b(float)"));
REQUIRE_THAT(puml, HasCall(_A("B<float>"), _A("A<float>"), "a(float)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -35,17 +35,17 @@ TEST_CASE("t20010", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b1"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a1"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b1()"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a1()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b2"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a2"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b2()"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a2()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b3"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a3"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b3()"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a3()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b4"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a4"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b4()"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a4()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -35,13 +35,13 @@ TEST_CASE("t20011", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a(int)"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "b"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "c"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "d"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "b"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "b(int)"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "c(int)"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "d(int)"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "b(int)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -37,34 +37,34 @@ TEST_CASE("t20012", "[test-case][sequence]")
// Check if all calls exist
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("tmain()::(lambda t20012.cc:49:20)"),
"operator()"));
"operator()()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:49:20)"), _A("A"), "a"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aa"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aaa"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:49:20)"), _A("A"), "a()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aa()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aaa()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:49:20)"), _A("B"), "b"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bb"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bbb"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:49:20)"), _A("B"), "b()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bb()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bbb()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:62:20)"), _A("C"), "c"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "cc"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:62:20)"), _A("C"), "c()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "cc()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()::(lambda t20012.cc:62:20)"),
_A("tmain()::(lambda t20012.cc:49:20)"), "operator()"));
_A("tmain()::(lambda t20012.cc:49:20)"), "operator()()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:68:9)>"), "r"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:68:9)>"), "r()"));
REQUIRE_THAT(puml,
HasCall(_A("R<R::(lambda t20012.cc:68:9)>"),
_A("tmain()::(lambda t20012.cc:68:9)"), "operator()"));
_A("tmain()::(lambda t20012.cc:68:9)"), "operator()()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:68:9)"), _A("C"), "c"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:68:9)"), _A("C"), "c()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);

View File

@@ -131,7 +131,7 @@ ContainsMatcher HasCall(std::string const &from, std::string const &to,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} -> {} : {}", from, to, message), caseSensitivity));
fmt::format("{} -> {} : {}\n", from, to, message), caseSensitivity));
}
auto HasCallWithResponse(std::string const &from, std::string const &to,