diff --git a/src/class_diagram/visitor/template_builder.cc b/src/class_diagram/visitor/template_builder.cc index d55b537e..68611eea 100644 --- a/src/class_diagram/visitor/template_builder.cc +++ b/src/class_diagram/visitor/template_builder.cc @@ -795,7 +795,10 @@ template_parameter map_type_parameter_to_template_parameter( detail::map_type_parameter_to_template_parameter(alias_decl, tp)); } - return template_parameter::make_argument(tp); + std::string arg = tp; + if (arg == "_Bool") + arg = "bool"; + return template_parameter::make_argument(arg); } std::optional build_template_parameter( @@ -822,14 +825,15 @@ std::optional build_template_parameter( return {}; // simple template param without qualifiers - if (common::is_type_token(*it) && it_next == end) { + if (common::is_type_token(*it) && (it_next == end || *it_next == ")")) { res = map_type_parameter_to_template_parameter(decl, *it); return res; } // template parameter with qualifier at the end else if (common::is_type_token(*it) && common::is_qualifier(*it_next)) { res = map_type_parameter_to_template_parameter(decl, *it); - res.set_qualifier(*it_next); + param_qualifier += *it_next; + res.set_qualifier(param_qualifier); return res; } // method template parameter @@ -847,7 +851,8 @@ std::optional build_template_parameter( } if (it != end && common::is_qualifier(*it)) { - res.set_qualifier(*it); + param_qualifier += *it; + res.set_qualifier(param_qualifier); } return res; @@ -861,17 +866,18 @@ std::optional build_template_parameter( else if (common::is_type_token(*it) && *it_next == "(") { res.add_template_param( map_type_parameter_to_template_parameter(decl, *it)); - it_next++; + it_next++; // skip '(' res.add_template_param( map_type_parameter_to_template_parameter(decl, *it_next)); it = it_next; it++; - if (*it == "::") { + it_next = it; + it_next++; + + if (*it == "::" && *it_next == "*") { res.set_method_template(true); - it++; - it++; - it++; + std::advance(it, 3); } if (it != end) { @@ -879,6 +885,7 @@ std::optional build_template_parameter( if (*it == "(") { it++; while (true) { + // This will break on more complex args auto arg_separator = std::find(it, end, ","); if (arg_separator == end) { // just one arg @@ -904,7 +911,8 @@ std::optional build_template_parameter( it++; if (it != end && common::is_qualifier(*it)) { - res.set_qualifier(*it); + param_qualifier += *it; + res.set_qualifier(param_qualifier); } } diff --git a/src/common/clang_utils.cc b/src/common/clang_utils.cc index be50439a..874a4812 100644 --- a/src/common/clang_utils.cc +++ b/src/common/clang_utils.cc @@ -479,9 +479,8 @@ bool is_identifier_character(char c) { return std::isalnum(c) || c == '_'; } bool is_identifier(const std::string &t) { - return std::isalpha(t.at(0)) && - std::all_of(t.begin(), t.end(), - [](const char c) { return is_identifier_character(c); }); + return std::all_of(t.begin(), t.end(), + [](const char c) { return is_identifier_character(c); }); } bool is_keyword(const std::string &t) diff --git a/tests/t00062/test_case.h b/tests/t00062/test_case.h index 58ee6e81..335b43a2 100644 --- a/tests/t00062/test_case.h +++ b/tests/t00062/test_case.h @@ -39,15 +39,15 @@ TEST_CASE("t00062", "[test-case][class]") 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", "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", "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", "float (C::*)(int)&&")); + REQUIRE_THAT(puml, IsClassTemplate("A", "char[N]")); REQUIRE_THAT(puml, IsClassTemplate("A", "char[1000]"));