Extended sequence diagram config type alias test case (#227)
This commit is contained in:
@@ -30,6 +30,10 @@ translation_unit_visitor::translation_unit_visitor(clang::SourceManager &sm,
|
|||||||
: common::visitor::translation_unit_visitor{sm, config}
|
: common::visitor::translation_unit_visitor{sm, config}
|
||||||
, diagram_{diagram}
|
, diagram_{diagram}
|
||||||
, config_{config}
|
, config_{config}
|
||||||
|
, template_builder_{diagram_, config_, *this,
|
||||||
|
[uns = config_.using_namespace()](const clang::NamedDecl * /*decl*/) {
|
||||||
|
return std::make_unique<sequence_diagram::model::class_>(uns);
|
||||||
|
}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,6 +375,7 @@ bool translation_unit_visitor::VisitFunctionTemplateDecl(
|
|||||||
process_comment(*declaration, *function_template_model);
|
process_comment(*declaration, *function_template_model);
|
||||||
|
|
||||||
set_source_location(*declaration, *function_template_model);
|
set_source_location(*declaration, *function_template_model);
|
||||||
|
set_owning_module(*declaration, *function_template_model);
|
||||||
|
|
||||||
function_template_model->is_void(
|
function_template_model->is_void(
|
||||||
declaration->getAsFunction()->getReturnType()->isVoidType());
|
declaration->getAsFunction()->getReturnType()->isVoidType());
|
||||||
@@ -1882,6 +1887,9 @@ translation_unit_visitor::process_template_specialization(
|
|||||||
clang::ClassTemplateSpecializationDecl *cls)
|
clang::ClassTemplateSpecializationDecl *cls)
|
||||||
{
|
{
|
||||||
auto c_ptr{std::make_unique<model::class_>(config_.using_namespace())};
|
auto c_ptr{std::make_unique<model::class_>(config_.using_namespace())};
|
||||||
|
|
||||||
|
tbuilder().build_from_class_template_specialization(*c_ptr, *cls);
|
||||||
|
|
||||||
auto &template_instantiation = *c_ptr;
|
auto &template_instantiation = *c_ptr;
|
||||||
|
|
||||||
// TODO: refactor to method get_qualified_name()
|
// TODO: refactor to method get_qualified_name()
|
||||||
@@ -1898,17 +1906,11 @@ translation_unit_visitor::process_template_specialization(
|
|||||||
|
|
||||||
process_comment(*cls, template_instantiation);
|
process_comment(*cls, template_instantiation);
|
||||||
set_source_location(*cls, template_instantiation);
|
set_source_location(*cls, template_instantiation);
|
||||||
|
set_owning_module(*cls, template_instantiation);
|
||||||
|
|
||||||
if (template_instantiation.skip())
|
if (template_instantiation.skip())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const auto template_args_count = cls->getTemplateArgs().size();
|
|
||||||
for (auto arg_it = 0U; arg_it < template_args_count; arg_it++) {
|
|
||||||
const auto arg = cls->getTemplateArgs().get(arg_it);
|
|
||||||
process_template_specialization_argument(
|
|
||||||
cls, template_instantiation, arg, arg_it);
|
|
||||||
}
|
|
||||||
|
|
||||||
template_instantiation.set_id(
|
template_instantiation.set_id(
|
||||||
common::to_id(template_instantiation.full_name(false)));
|
common::to_id(template_instantiation.full_name(false)));
|
||||||
|
|
||||||
@@ -2435,15 +2437,16 @@ translation_unit_visitor::create_method_model(clang::CXXMethodDecl *declaration)
|
|||||||
|
|
||||||
LOG_DBG("Getting method's class with local id {}", parent_decl->getID());
|
LOG_DBG("Getting method's class with local id {}", parent_decl->getID());
|
||||||
|
|
||||||
if (!get_participant<model::class_>(parent_decl)) {
|
const auto maybe_method_class = get_participant<model::class_>(parent_decl);
|
||||||
|
|
||||||
|
if (!maybe_method_class) {
|
||||||
LOG_DBG("Cannot find parent class_ for method {} in class {}",
|
LOG_DBG("Cannot find parent class_ for method {} in class {}",
|
||||||
declaration->getQualifiedNameAsString(),
|
declaration->getQualifiedNameAsString(),
|
||||||
declaration->getParent()->getQualifiedNameAsString());
|
declaration->getParent()->getQualifiedNameAsString());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &method_class =
|
const auto &method_class = maybe_method_class.value();
|
||||||
get_participant<model::class_>(parent_decl).value();
|
|
||||||
|
|
||||||
method_model_ptr->is_void(declaration->getReturnType()->isVoidType());
|
method_model_ptr->is_void(declaration->getReturnType()->isVoidType());
|
||||||
|
|
||||||
@@ -2459,9 +2462,12 @@ translation_unit_visitor::create_method_model(clang::CXXMethodDecl *declaration)
|
|||||||
declaration->getReturnType(), declaration->getASTContext()));
|
declaration->getReturnType(), declaration->getASTContext()));
|
||||||
|
|
||||||
for (const auto *param : declaration->parameters()) {
|
for (const auto *param : declaration->parameters()) {
|
||||||
|
auto parameter_type =
|
||||||
|
common::to_string(param->getType(), param->getASTContext());
|
||||||
|
common::ensure_lambda_type_is_relative(config(), parameter_type);
|
||||||
|
parameter_type = simplify_system_template(parameter_type);
|
||||||
method_model_ptr->add_parameter(config().using_namespace().relative(
|
method_model_ptr->add_parameter(config().using_namespace().relative(
|
||||||
simplify_system_template(common::to_string(
|
simplify_system_template(parameter_type)));
|
||||||
param->getType(), declaration->getASTContext(), false))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return method_model_ptr;
|
return method_model_ptr;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "call_expression_context.h"
|
#include "call_expression_context.h"
|
||||||
|
#include "common/visitor/template_builder.h"
|
||||||
#include "common/visitor/translation_unit_visitor.h"
|
#include "common/visitor/translation_unit_visitor.h"
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "sequence_diagram/model/diagram.h"
|
#include "sequence_diagram/model/diagram.h"
|
||||||
@@ -510,6 +511,13 @@ private:
|
|||||||
const clang::SourceManager &sm, const clang::ASTContext &context,
|
const clang::SourceManager &sm, const clang::ASTContext &context,
|
||||||
int64_t caller_id, const clang::Stmt *stmt);
|
int64_t caller_id, const clang::Stmt *stmt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get template builder reference
|
||||||
|
*
|
||||||
|
* @return Reference to 'template_builder' instance
|
||||||
|
*/
|
||||||
|
common::visitor::template_builder &tbuilder() { return template_builder_; }
|
||||||
|
|
||||||
// Reference to the output diagram model
|
// Reference to the output diagram model
|
||||||
clanguml::sequence_diagram::model::diagram &diagram_;
|
clanguml::sequence_diagram::model::diagram &diagram_;
|
||||||
|
|
||||||
@@ -549,5 +557,7 @@ private:
|
|||||||
|
|
||||||
mutable std::set<std::pair<int64_t, const clang::RawComment *>>
|
mutable std::set<std::pair<int64_t, const clang::RawComment *>>
|
||||||
processed_comments_;
|
processed_comments_;
|
||||||
|
|
||||||
|
common::visitor::template_builder template_builder_;
|
||||||
};
|
};
|
||||||
} // namespace clanguml::sequence_diagram::visitor
|
} // namespace clanguml::sequence_diagram::visitor
|
||||||
|
|||||||
@@ -59,9 +59,12 @@ TEST_CASE("t20012", "[test-case][sequence]")
|
|||||||
REQUIRE_THAT(src, HasCall(_A("C"), _A("C"), "ccc()"));
|
REQUIRE_THAT(src, HasCall(_A("C"), _A("C"), "ccc()"));
|
||||||
|
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:86:9)>"), "r()"));
|
HasCall(_A("tmain()"), _A("R<(lambda at t20012.cc:86:9)>"),
|
||||||
|
"R((lambda at t20012.cc:86:9) &&)"));
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("R<R::(lambda t20012.cc:86:9)>"),
|
HasCall(_A("tmain()"), _A("R<(lambda at t20012.cc:86:9)>"), "r()"));
|
||||||
|
REQUIRE_THAT(src,
|
||||||
|
HasCall(_A("R<(lambda at t20012.cc:86:9)>"),
|
||||||
_A("tmain()::(lambda t20012.cc:86:9)"), "operator()()"));
|
_A("tmain()::(lambda t20012.cc:86:9)"), "operator()()"));
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("tmain()::(lambda t20012.cc:86:9)"), _A("C"), "c()"));
|
HasCall(_A("tmain()::(lambda t20012.cc:86:9)"), _A("C"), "c()"));
|
||||||
@@ -88,8 +91,8 @@ TEST_CASE("t20012", "[test-case][sequence]")
|
|||||||
FindMessage(j, "C", "C", "cc()"), FindMessage(j, "C", "C", "ccc()"),
|
FindMessage(j, "C", "C", "cc()"), FindMessage(j, "C", "C", "ccc()"),
|
||||||
FindMessage(j, "tmain()::(lambda t20012.cc:80:20)",
|
FindMessage(j, "tmain()::(lambda t20012.cc:80:20)",
|
||||||
"tmain()::(lambda t20012.cc:67:20)", "operator()()"),
|
"tmain()::(lambda t20012.cc:67:20)", "operator()()"),
|
||||||
FindMessage(j, "tmain()", "R<R::(lambda t20012.cc:86:9)>", "r()"),
|
FindMessage(j, "tmain()", "R<(lambda at t20012.cc:86:9)>", "r()"),
|
||||||
FindMessage(j, "R<R::(lambda t20012.cc:86:9)>",
|
FindMessage(j, "R<(lambda at t20012.cc:86:9)>",
|
||||||
"tmain()::(lambda t20012.cc:86:9)", "operator()()"),
|
"tmain()::(lambda t20012.cc:86:9)", "operator()()"),
|
||||||
FindMessage(j, "tmain()::(lambda t20012.cc:86:9)", "C", "c()"),
|
FindMessage(j, "tmain()::(lambda t20012.cc:86:9)", "C", "c()"),
|
||||||
// @todo #168
|
// @todo #168
|
||||||
@@ -131,9 +134,9 @@ TEST_CASE("t20012", "[test-case][sequence]")
|
|||||||
REQUIRE_THAT(src, HasCall(_A("C"), _A("C"), "ccc()"));
|
REQUIRE_THAT(src, HasCall(_A("C"), _A("C"), "ccc()"));
|
||||||
|
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:86:9)>"), "r()"));
|
HasCall(_A("tmain()"), _A("R<(lambda at t20012.cc:86:9)>"), "r()"));
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("R<R::(lambda t20012.cc:86:9)>"),
|
HasCall(_A("R<(lambda at t20012.cc:86:9)>"),
|
||||||
_A("tmain()::(lambda t20012.cc:86:9)"), "operator()()"));
|
_A("tmain()::(lambda t20012.cc:86:9)"), "operator()()"));
|
||||||
REQUIRE_THAT(src,
|
REQUIRE_THAT(src,
|
||||||
HasCall(_A("tmain()::(lambda t20012.cc:86:9)"), _A("C"), "c()"));
|
HasCall(_A("tmain()::(lambda t20012.cc:86:9)"), _A("C"), "c()"));
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ diagrams:
|
|||||||
using_namespace: clanguml::t20039
|
using_namespace: clanguml::t20039
|
||||||
type_aliases:
|
type_aliases:
|
||||||
"std::vector<int>": int_vec_t
|
"std::vector<int>": int_vec_t
|
||||||
|
"std::vector<std::string>": string_vec_t
|
||||||
"std::map<int,int>": int_map_t
|
"std::map<int,int>": int_map_t
|
||||||
|
"std::map<std::string,std::string>": string_map_t
|
||||||
from:
|
from:
|
||||||
- function: "clanguml::t20039::tmain()"
|
- function: "clanguml::t20039::tmain()"
|
||||||
@@ -12,13 +12,17 @@ template <typename T> struct A {
|
|||||||
struct R {
|
struct R {
|
||||||
A<int> a_int;
|
A<int> a_int;
|
||||||
A<std::vector<int>> a_intvec;
|
A<std::vector<int>> a_intvec;
|
||||||
|
A<std::vector<std::string>> a_stringvec;
|
||||||
A<std::map<int, int>> a_intmap;
|
A<std::map<int, int>> a_intmap;
|
||||||
|
A<std::map<std::string, std::string>> a_stringmap;
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
a_int.a({});
|
a_int.a({});
|
||||||
a_intvec.a({});
|
a_intvec.a({});
|
||||||
|
a_stringvec.a({});
|
||||||
a_intmap.a({});
|
a_intmap.a({});
|
||||||
|
a_stringmap.a({});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ TEST_CASE("t20039", "[test-case][sequence]")
|
|||||||
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("R"), "run()"));
|
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("R"), "run()"));
|
||||||
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int>"), "a(int)"));
|
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int>"), "a(int)"));
|
||||||
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_vec_t>"), "a(int_vec_t)"));
|
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_vec_t>"), "a(int_vec_t)"));
|
||||||
|
REQUIRE_THAT(
|
||||||
|
src, HasCall(_A("R"), _A("A<string_vec_t>"), "a(string_vec_t)"));
|
||||||
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_map_t>"), "a(int_map_t)"));
|
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_map_t>"), "a(int_map_t)"));
|
||||||
|
REQUIRE_THAT(
|
||||||
|
src, HasCall(_A("R"), _A("A<string_map_t>"), "a(string_map_t)"));
|
||||||
|
|
||||||
save_puml(config.output_directory(), diagram->name + ".puml", src);
|
save_puml(config.output_directory(), diagram->name + ".puml", src);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user