diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.cc b/src/sequence_diagram/visitor/translation_unit_visitor.cc index b1b81a63..d45f03c0 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.cc +++ b/src/sequence_diagram/visitor/translation_unit_visitor.cc @@ -641,45 +641,18 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr) if (!callee_function) return true; - bool is_implicit = false; auto callee_name = callee_function->getQualifiedNameAsString() + "()"; std::unique_ptr f_ptr; - // - // The target template function is implicit if it's - // specialization/instantiation was not explicitly defined - // (i.e. it was not added to the diagram by visitor methods) - // - is_implicit = - !get_ast_local_id(callee_function->getID()).has_value(); - - // - // If the callee is a specialization of a function template, - // build it's instantiation model to get the id - // - if (callee_function->getTemplateSpecializationArgs() && - callee_function->getTemplateSpecializationArgs()->size() > 0) { - f_ptr = build_function_template_instantiation(*callee_function); - - f_ptr->set_id(common::to_id(f_ptr->full_name(false))); - set_ast_local_id(callee_function->getID(), f_ptr->id()); + if(!get_ast_local_id(callee_function->getID()).has_value()) { + // This is hopefully not an interesting call... + return true; } - - if (is_implicit) { - LOG_DBG("Processing implicit template specialization {}", - f_ptr->full_name(false)); - - // If this is an implicit template specialization/instantiation - // for now we just redirect the call to it's primary template - // (TODO: this is not correct in a general case) - m.to = get_ast_local_id( - callee_function->getPrimaryTemplate()->getID()) - .value(); - } - else + else { m.to = get_ast_local_id(callee_function->getID()).value(); + } auto message_name = callee_name; m.message_name = message_name.substr(0, message_name.size() - 2); diff --git a/tests/t20007/.clang-uml b/tests/t20007/.clang-uml new file mode 100644 index 00000000..40a6a2f7 --- /dev/null +++ b/tests/t20007/.clang-uml @@ -0,0 +1,14 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t20007_sequence: + type: sequence + glob: + - ../../tests/t20007/t20007.cc + include: + namespaces: + - clanguml::t20007 + using_namespace: + - clanguml::t20007 + start_from: + - function: "clanguml::t20007::tmain()" \ No newline at end of file diff --git a/tests/t20007/t20007.cc b/tests/t20007/t20007.cc new file mode 100644 index 00000000..b7c3ec44 --- /dev/null +++ b/tests/t20007/t20007.cc @@ -0,0 +1,25 @@ +#include +#include + +namespace clanguml { +namespace t20007 { + +template struct Adder { + First add(First &&arg, Args &&...args) { return (arg + ... + args); } +}; + +void tmain() +{ + using namespace std::string_literals; + + Adder adder1; + Adder adder2; + Adder adder3; + + [[maybe_unused]] auto res1 = adder1.add(2, 2); + [[maybe_unused]] auto res2 = adder2.add(1, 2.0, 3.0); + [[maybe_unused]] auto res3 = adder3.add("one"s, "two"s, "three"s); +} + +} +} \ No newline at end of file diff --git a/tests/t20007/test_case.h b/tests/t20007/test_case.h new file mode 100644 index 00000000..5fc2d26a --- /dev/null +++ b/tests/t20007/test_case.h @@ -0,0 +1,47 @@ +/** + * tests/t20007/test_case.h + * + * Copyright (c) 2021-2022 Bartek Kryza + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +TEST_CASE("t20007", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20007"); + + auto diagram = config.diagrams["t20007_sequence"]; + + REQUIRE(diagram->name == "t20007_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20007_sequence"); + + auto puml = generate_sequence_puml(diagram, *model); + AliasMatcher _A(puml); + + REQUIRE_THAT(puml, StartsWith("@startuml")); + REQUIRE_THAT(puml, EndsWith("@enduml\n")); + + // Check if all calls exist + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("Adder"), "add")); + REQUIRE_THAT( + puml, HasCall(_A("tmain()"), _A("Adder"), "add")); + REQUIRE_THAT(puml, + HasCall(_A("tmain()"), _A("Adder"), + "add")); + + save_puml( + "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 79289f4b..51a822cf 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -253,6 +253,7 @@ using namespace clanguml::test::matchers; #include "t20004/test_case.h" #include "t20005/test_case.h" #include "t20006/test_case.h" +#include "t20007/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 72076e25..115abd8a 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -166,6 +166,9 @@ test_cases: - name: t20006 title: Class template specialization basic sequence diagram description: + - name: t20007 + title: Class template variadic argument list sequence diagram + description: Package diagrams: - name: t30001 title: Basic package diagram test case