From 47ccb561c98c60c3e81b29f0f78a5c35de33638a Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 24 Apr 2023 00:28:38 +0200 Subject: [PATCH] Fixed handling of unexposed variadic template params --- src/class_diagram/visitor/template_builder.cc | 6 ++++++ src/common/clang_utils.cc | 15 +++++++++++++++ tests/t00062/test_case.h | 15 ++++++++++++++- tests/test_util.cc | 11 +++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/class_diagram/visitor/template_builder.cc b/src/class_diagram/visitor/template_builder.cc index c4f83fbf..d55b537e 100644 --- a/src/class_diagram/visitor/template_builder.cc +++ b/src/class_diagram/visitor/template_builder.cc @@ -852,6 +852,12 @@ std::optional build_template_parameter( return res; } + else if (common::is_type_token(*it) && *it_next == "...") { + // Variadic template parameter + auto parm = map_type_parameter_to_template_parameter(decl, *it); + parm.is_variadic(true); + return parm; + } else if (common::is_type_token(*it) && *it_next == "(") { res.add_template_param( map_type_parameter_to_template_parameter(decl, *it)); diff --git a/src/common/clang_utils.cc b/src/common/clang_utils.cc index 2bb2e2b0..be50439a 100644 --- a/src/common/clang_utils.cc +++ b/src/common/clang_utils.cc @@ -563,6 +563,21 @@ std::vector tokenize_unexposed_template_parameter( result.push_back("*"); tok.clear(); } + else if (c == '.') { + // This can only be the case if we have a variadic template, + // right? + if (tok == "..") { + result.push_back("..."); + tok.clear(); + } + else if (tok == ".") { + tok = ".."; + } + else if (!tok.empty()) { + result.push_back(tok); + tok = "."; + } + } else { tok += c; } diff --git a/tests/t00062/test_case.h b/tests/t00062/test_case.h index 116dbc9c..58ee6e81 100644 --- a/tests/t00062/test_case.h +++ b/tests/t00062/test_case.h @@ -36,7 +36,20 @@ TEST_CASE("t00062", "[test-case][class]") REQUIRE_THAT(puml, EndsWith("@enduml\n")); // Check if all classes exist - REQUIRE_THAT(puml, IsClass(_A("AAA"))); + REQUIRE_THAT(puml, IsClassTemplate("A", "T")); + REQUIRE_THAT(puml, IsClassTemplate("A", "U &")); + REQUIRE_THAT(puml, IsClassTemplate("A", "U &&")); + // REQUIRE_THAT(puml, IsClassTemplate("A", "U const&")); + REQUIRE_THAT(puml, IsClassTemplate("A", "M C::*")); + REQUIRE_THAT(puml, IsClassTemplate("A", "M C::*&&")); + REQUIRE_THAT(puml, IsClassTemplate("A", "M (C::*)(Arg)")); + // REQUIRE_THAT(puml, IsClassTemplate("A", "int (C::*)(bool)")); + REQUIRE_THAT(puml, IsClassTemplate("A", "M (C::*)(Arg)&&")); + // REQUIRE_THAT(puml, IsClassTemplate("A", "int + // (C::*)(bool)&&")); + REQUIRE_THAT(puml, IsClassTemplate("A", "M (C::*)(Arg1,Arg2,Arg3)")); + REQUIRE_THAT(puml, IsClassTemplate("A", "char[N]")); + REQUIRE_THAT(puml, IsClassTemplate("A", "char[1000]")); // Check if class templates exist // REQUIRE_THAT(puml, IsClassTemplate("A", "T,P,CMP,int N")); diff --git a/tests/test_util.cc b/tests/test_util.cc index 406919c8..413cbb33 100644 --- a/tests/test_util.cc +++ b/tests/test_util.cc @@ -384,4 +384,15 @@ TEST_CASE("Test tokenize_unexposed_template_parameter", "[unit-test]") CHECK(r[i++] == "unsigned"); CHECK(r[i++] == "int"); } + + { + int i = 0; + + auto r = tokenize_unexposed_template_parameter("Ret(Args...)"); + CHECK(r[i++] == "Ret"); + CHECK(r[i++] == "("); + CHECK(r[i++] == "Args"); + CHECK(r[i++] == "..."); + CHECK(r[i++] == ")"); + } }