Added template method specialization sequence diagram test case
This commit is contained in:
@@ -616,23 +616,28 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!process_function_call_expression(m, expr))
|
if (!process_function_call_expression(m, expr)) {
|
||||||
return true;
|
// expr->dump();
|
||||||
}
|
LOG_DBG("Skipping call to unsupported type of call expression "
|
||||||
|
"at: {}",
|
||||||
|
expr->getBeginLoc().printToString(source_manager()));
|
||||||
|
|
||||||
//
|
return true;
|
||||||
// This crashes on LLVM <= 12, for now just return empty type
|
}
|
||||||
//
|
}
|
||||||
// const auto &return_type =
|
|
||||||
// function_call_expr->getCallReturnType(current_ast_context);
|
|
||||||
// m.return_type = return_type.getAsString();
|
|
||||||
m.return_type = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This crashes on LLVM <= 12, for now just return empty type
|
||||||
|
//
|
||||||
|
// const auto &return_type =
|
||||||
|
// function_call_expr->getCallReturnType(current_ast_context);
|
||||||
|
// m.return_type = return_type.getAsString();
|
||||||
|
m.return_type = "";
|
||||||
|
|
||||||
if (m.from > 0 && m.to > 0) {
|
if (m.from > 0 && m.to > 0) {
|
||||||
if (diagram().sequences.find(m.from) == diagram().sequences.end()) {
|
if (diagram().sequences.find(m.from) == diagram().sequences.end()) {
|
||||||
activity a;
|
activity a;
|
||||||
// a.usr = m.from;
|
|
||||||
a.from = m.from;
|
a.from = m.from;
|
||||||
diagram().sequences.insert({m.from, std::move(a)});
|
diagram().sequences.insert({m.from, std::move(a)});
|
||||||
}
|
}
|
||||||
@@ -778,6 +783,10 @@ bool translation_unit_visitor::process_class_template_method_call_expression(
|
|||||||
diagram().add_active_participant(
|
diagram().add_active_participant(
|
||||||
get_unique_id(template_declaration->getID()).value());
|
get_unique_id(template_declaration->getID()).value());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
LOG_WARN("Cannot generate call due to unresolvable "
|
||||||
|
"CXXDependentScopeMemberExpr");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -845,14 +854,23 @@ bool translation_unit_visitor::process_unresolved_lookup_call_expression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool translation_unit_visitor::is_callee_valid_template_specialization(
|
bool translation_unit_visitor::is_callee_valid_template_specialization(
|
||||||
const clang::CXXDependentScopeMemberExpr *dependent_member_callee) const
|
const clang::CXXDependentScopeMemberExpr *dependent_member_expr) const
|
||||||
{
|
{
|
||||||
return !dependent_member_callee->getBaseType().isNull() &&
|
const bool base_type_is_not_null =
|
||||||
dependent_member_callee->getBaseType()
|
!dependent_member_expr->getBaseType().isNull();
|
||||||
->getAs<clang::TemplateSpecializationType>() &&
|
|
||||||
!dependent_member_callee->getBaseType()
|
const bool base_type_is_specialization_type =
|
||||||
|
dependent_member_expr->getBaseType()
|
||||||
|
->getAs<clang::TemplateSpecializationType>() != nullptr;
|
||||||
|
|
||||||
|
const bool base_type_is_not_pointer_type =
|
||||||
|
base_type_is_specialization_type &&
|
||||||
|
!dependent_member_expr->getBaseType()
|
||||||
->getAs<clang::TemplateSpecializationType>()
|
->getAs<clang::TemplateSpecializationType>()
|
||||||
->isPointerType();
|
->isPointerType();
|
||||||
|
|
||||||
|
return (base_type_is_not_null && base_type_is_specialization_type &&
|
||||||
|
base_type_is_not_pointer_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool translation_unit_visitor::is_smart_pointer(
|
bool translation_unit_visitor::is_smart_pointer(
|
||||||
@@ -898,8 +916,8 @@ translation_unit_visitor::create_class_declaration(clang::CXXRecordDecl *cls)
|
|||||||
int64_t local_id =
|
int64_t local_id =
|
||||||
static_cast<const clang::RecordDecl *>(parent)->getID();
|
static_cast<const clang::RecordDecl *>(parent)->getID();
|
||||||
|
|
||||||
// First check if the parent has been added to the diagram as regular
|
// First check if the parent has been added to the diagram as
|
||||||
// class
|
// regular class
|
||||||
id_opt = get_unique_id(local_id);
|
id_opt = get_unique_id(local_id);
|
||||||
|
|
||||||
// If not, check if the parent template declaration is in the model
|
// If not, check if the parent template declaration is in the model
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ private:
|
|||||||
bool is_smart_pointer(const clang::TemplateDecl *primary_template) const;
|
bool is_smart_pointer(const clang::TemplateDecl *primary_template) const;
|
||||||
|
|
||||||
bool is_callee_valid_template_specialization(
|
bool is_callee_valid_template_specialization(
|
||||||
const clang::CXXDependentScopeMemberExpr *dependent_member_callee)
|
const clang::CXXDependentScopeMemberExpr *dependent_member_expr)
|
||||||
const;
|
const;
|
||||||
|
|
||||||
bool process_operator_call_expression(model::message &m,
|
bool process_operator_call_expression(model::message &m,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
@@ -18,6 +20,8 @@ struct B {
|
|||||||
void bb() { bbb(); }
|
void bb() { bbb(); }
|
||||||
|
|
||||||
void bbb() { }
|
void bbb() { }
|
||||||
|
|
||||||
|
void eb() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct C {
|
struct C {
|
||||||
@@ -32,6 +36,14 @@ struct D {
|
|||||||
int add5(int arg) const { return arg + 5; }
|
int add5(int arg) const { return arg + 5; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class E {
|
||||||
|
std::optional<std::shared_ptr<B>> maybe_b;
|
||||||
|
std::shared_ptr<A> a;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template <typename F> void setup(F &&f) { f(maybe_b); }
|
||||||
|
};
|
||||||
|
|
||||||
template <typename F> struct R {
|
template <typename F> struct R {
|
||||||
R(F &&f)
|
R(F &&f)
|
||||||
: f_{std::move(f)}
|
: f_{std::move(f)}
|
||||||
@@ -79,6 +91,14 @@ void tmain()
|
|||||||
std::vector<int> ints{0, 1, 2, 3, 4};
|
std::vector<int> ints{0, 1, 2, 3, 4};
|
||||||
std::transform(ints.begin(), ints.end(), ints.begin(),
|
std::transform(ints.begin(), ints.end(), ints.begin(),
|
||||||
[&d](auto i) { return d.add5(i); });
|
[&d](auto i) { return d.add5(i); });
|
||||||
|
|
||||||
|
// TODO: Fix naming function call arguments which are lambdas
|
||||||
|
// E e;
|
||||||
|
//
|
||||||
|
// e.setup([](auto &&arg) mutable {
|
||||||
|
// // We cannot know here what 'arg' might be
|
||||||
|
// arg.value()->eb();
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,38 +36,39 @@ TEST_CASE("t20012", "[test-case][sequence]")
|
|||||||
|
|
||||||
// Check if all calls exist
|
// Check if all calls exist
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("tmain()"), _A("tmain()::(lambda t20012.cc:54:20)"),
|
HasCall(_A("tmain()"), _A("tmain()::(lambda t20012.cc:66:20)"),
|
||||||
"operator()()"));
|
"operator()()"));
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, HasCall(_A("tmain()::(lambda t20012.cc:54:20)"), _A("A"), "a()"));
|
puml, HasCall(_A("tmain()::(lambda t20012.cc:66:20)"), _A("A"), "a()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aa()"));
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aa()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aaa()"));
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aaa()"));
|
||||||
|
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, HasCall(_A("tmain()::(lambda t20012.cc:54:20)"), _A("B"), "b()"));
|
puml, HasCall(_A("tmain()::(lambda t20012.cc:66:20)"), _A("B"), "b()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bb()"));
|
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bb()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bbb()"));
|
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bbb()"));
|
||||||
|
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, HasCall(_A("tmain()::(lambda t20012.cc:67:20)"), _A("C"), "c()"));
|
puml, HasCall(_A("tmain()::(lambda t20012.cc:79:20)"), _A("C"), "c()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "cc()"));
|
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "cc()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
|
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("tmain()::(lambda t20012.cc:67:20)"),
|
HasCall(_A("tmain()::(lambda t20012.cc:79:20)"),
|
||||||
_A("tmain()::(lambda t20012.cc:54:20)"), "operator()()"));
|
_A("tmain()::(lambda t20012.cc:66:20)"), "operator()()"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
|
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:73:9)>"), "r()"));
|
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:85:9)>"), "r()"));
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("R<R::(lambda t20012.cc:73:9)>"),
|
HasCall(_A("R<R::(lambda t20012.cc:85:9)>"),
|
||||||
_A("tmain()::(lambda t20012.cc:73:9)"), "operator()()"));
|
_A("tmain()::(lambda t20012.cc:85:9)"), "operator()()"));
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, HasCall(_A("tmain()::(lambda t20012.cc:73:9)"), _A("C"), "c()"));
|
puml, HasCall(_A("tmain()::(lambda t20012.cc:85:9)"), _A("C"), "c()"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("D"), "add5(int)"));
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("D"), "add5(int)"));
|
||||||
|
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
namespace t20015 {
|
namespace t20015 {
|
||||||
|
|||||||
14
tests/t20016/.clang-uml
Normal file
14
tests/t20016/.clang-uml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t20016_sequence:
|
||||||
|
type: sequence
|
||||||
|
glob:
|
||||||
|
- ../../tests/t20016/t20016.cc
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t20016
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t20016
|
||||||
|
start_from:
|
||||||
|
- function: "clanguml::t20016::tmain()"
|
||||||
24
tests/t20016/t20016.cc
Normal file
24
tests/t20016/t20016.cc
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace clanguml {
|
||||||
|
namespace t20016 {
|
||||||
|
struct A {
|
||||||
|
void a1(int a) { }
|
||||||
|
template <typename T> T a2(const T &a) { return a;}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> struct B {
|
||||||
|
void b1(T b) { a_.a1(1); }
|
||||||
|
|
||||||
|
template <typename F> F b2(T t) { return a_.a2(t); }
|
||||||
|
|
||||||
|
A a_;
|
||||||
|
};
|
||||||
|
|
||||||
|
void tmain() {
|
||||||
|
B<long> b;
|
||||||
|
|
||||||
|
b.b1(1);
|
||||||
|
|
||||||
|
b.b2<int>(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
tests/t20016/test_case.h
Normal file
46
tests/t20016/test_case.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* tests/t20016/test_case.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
||||||
|
*
|
||||||
|
* 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("t20016", "[test-case][sequence]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t20016");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t20016_sequence"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t20016_sequence");
|
||||||
|
|
||||||
|
auto model = generate_sequence_diagram(*db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model->name() == "t20016_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("B<long>"), "b1(long)"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("B<long>"), _A("A"), "a1(int)"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<long>"), "b2(long)"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("B<long>"), _A("A"), "a2(const long &)"));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -262,6 +262,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t20013/test_case.h"
|
#include "t20013/test_case.h"
|
||||||
#include "t20014/test_case.h"
|
#include "t20014/test_case.h"
|
||||||
#include "t20015/test_case.h"
|
#include "t20015/test_case.h"
|
||||||
|
#include "t20016/test_case.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Package diagram tests
|
/// Package diagram tests
|
||||||
|
|||||||
@@ -193,6 +193,9 @@ test_cases:
|
|||||||
- name: t20015
|
- name: t20015
|
||||||
title: Class exclusion by namespace in sequence diagram test case
|
title: Class exclusion by namespace in sequence diagram test case
|
||||||
description:
|
description:
|
||||||
|
- name: t20016
|
||||||
|
title: Template method specialization sequence diagram test case
|
||||||
|
description:
|
||||||
Package diagrams:
|
Package diagrams:
|
||||||
- name: t30001
|
- name: t30001
|
||||||
title: Basic package diagram test case
|
title: Basic package diagram test case
|
||||||
|
|||||||
Reference in New Issue
Block a user