Fixed class diagram test cases on LLVM 16
This commit is contained in:
@@ -34,8 +34,12 @@ common::model::access_t class_element::access() const { return access_; }
|
|||||||
|
|
||||||
std::string class_element::name() const { return name_; }
|
std::string class_element::name() const { return name_; }
|
||||||
|
|
||||||
|
void class_element::set_name(const std::string &name) { name_ = name; }
|
||||||
|
|
||||||
std::string class_element::type() const { return type_; }
|
std::string class_element::type() const { return type_; }
|
||||||
|
|
||||||
|
void class_element::set_type(const std::string &type) { type_ = type; }
|
||||||
|
|
||||||
inja::json class_element::context() const
|
inja::json class_element::context() const
|
||||||
{
|
{
|
||||||
inja::json ctx;
|
inja::json ctx;
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ public:
|
|||||||
|
|
||||||
common::model::access_t access() const;
|
common::model::access_t access() const;
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
void set_name(const std::string &name);
|
||||||
|
|
||||||
std::string type() const;
|
std::string type() const;
|
||||||
|
void set_type(const std::string &type);
|
||||||
|
|
||||||
virtual inja::json context() const;
|
virtual inja::json context() const;
|
||||||
|
|
||||||
|
|||||||
@@ -986,14 +986,17 @@ bool translation_unit_visitor::process_template_parameters(
|
|||||||
const auto *template_nontype_parameter =
|
const auto *template_nontype_parameter =
|
||||||
clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>(
|
clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>(
|
||||||
parameter);
|
parameter);
|
||||||
|
|
||||||
std::optional<std::string> default_arg;
|
std::optional<std::string> default_arg;
|
||||||
|
|
||||||
if (template_nontype_parameter->hasDefaultArgument())
|
if (template_nontype_parameter->hasDefaultArgument())
|
||||||
default_arg = common::to_string(
|
default_arg = common::to_string(
|
||||||
template_nontype_parameter->getDefaultArgument());
|
template_nontype_parameter->getDefaultArgument());
|
||||||
|
|
||||||
auto ct = template_parameter::make_non_type_template(
|
auto ct = template_parameter::make_non_type_template(
|
||||||
template_nontype_parameter->getType().getAsString(),
|
template_nontype_parameter->getType().getAsString(),
|
||||||
template_nontype_parameter->getNameAsString(), default_arg,
|
template_nontype_parameter->getNameAsString(),
|
||||||
template_nontype_parameter->isParameterPack());
|
default_arg, template_nontype_parameter->isParameterPack());
|
||||||
|
|
||||||
c.add_template(std::move(ct));
|
c.add_template(std::move(ct));
|
||||||
}
|
}
|
||||||
@@ -1082,6 +1085,7 @@ void translation_unit_visitor::process_class_bases(
|
|||||||
if (const auto *record_type =
|
if (const auto *record_type =
|
||||||
base.getType()->getAs<clang::RecordType>();
|
base.getType()->getAs<clang::RecordType>();
|
||||||
record_type != nullptr) {
|
record_type != nullptr) {
|
||||||
|
cp.set_name(record_type->getDecl()->getQualifiedNameAsString());
|
||||||
cp.set_id(common::to_id(*record_type->getDecl()));
|
cp.set_id(common::to_id(*record_type->getDecl()));
|
||||||
}
|
}
|
||||||
else if (const auto *tsp =
|
else if (const auto *tsp =
|
||||||
@@ -2543,7 +2547,9 @@ void translation_unit_visitor::
|
|||||||
record_type_decl != nullptr) {
|
record_type_decl != nullptr) {
|
||||||
|
|
||||||
argument.set_id(common::to_id(arg));
|
argument.set_id(common::to_id(arg));
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
argument.set_type(record_type_decl->getQualifiedNameAsString());
|
argument.set_type(record_type_decl->getQualifiedNameAsString());
|
||||||
|
#endif
|
||||||
if (diagram().should_include(full_template_specialization_name)) {
|
if (diagram().should_include(full_template_specialization_name)) {
|
||||||
// Add dependency relationship to the parent
|
// Add dependency relationship to the parent
|
||||||
// template
|
// template
|
||||||
|
|||||||
@@ -118,30 +118,11 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
|
|||||||
clang::PrintingPolicy print_policy(ctx.getLangOpts());
|
clang::PrintingPolicy print_policy(ctx.getLangOpts());
|
||||||
print_policy.SuppressScope = false;
|
print_policy.SuppressScope = false;
|
||||||
print_policy.PrintCanonicalTypes = false;
|
print_policy.PrintCanonicalTypes = false;
|
||||||
// print_policy.FullyQualifiedName = true;
|
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 16
|
|
||||||
print_policy.AlwaysIncludeTypeForTemplateArgument = true;
|
|
||||||
print_policy.SplitTemplateClosers = false;
|
|
||||||
print_policy.SuppressDefaultTemplateArgs = false;
|
|
||||||
print_policy.SuppressInlineNamespace = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
result = type.getAsString(print_policy);
|
result = type.getAsString(print_policy);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 16
|
|
||||||
// Why do I have to this LLVM16?
|
|
||||||
if (const auto *decl = type->getAsCXXRecordDecl();
|
|
||||||
decl && !decl->isTemplated() && result.find('<') == std::string::npos) {
|
|
||||||
// This is a workaround for LLVM >= 16
|
|
||||||
const auto tag_namespace = get_tag_namespace(*decl).to_string();
|
|
||||||
if (result.find(tag_namespace) != 0)
|
|
||||||
result = fmt::format("{}::{}", tag_namespace, result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (try_canonical && result.find('<') != std::string::npos) {
|
if (try_canonical && result.find('<') != std::string::npos) {
|
||||||
auto canonical_type_name =
|
auto canonical_type_name =
|
||||||
type.getCanonicalType().getAsString(print_policy);
|
type.getCanonicalType().getAsString(print_policy);
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ void inheritable_diagram_options::inherit(
|
|||||||
std::string inheritable_diagram_options::simplify_template_type(
|
std::string inheritable_diagram_options::simplify_template_type(
|
||||||
std::string full_name) const
|
std::string full_name) const
|
||||||
{
|
{
|
||||||
const auto &aliases = type_aliases();
|
type_aliases_longer_first_t aliases;
|
||||||
|
aliases.insert(type_aliases().begin(), type_aliases().end());
|
||||||
|
|
||||||
for (const auto &[pattern, replacement] : aliases) {
|
for (const auto &[pattern, replacement] : aliases) {
|
||||||
util::replace_all(full_name, pattern, replacement);
|
util::replace_all(full_name, pattern, replacement);
|
||||||
@@ -176,12 +177,6 @@ std::optional<std::string> diagram::get_together_group(
|
|||||||
|
|
||||||
void diagram::initialize_type_aliases()
|
void diagram::initialize_type_aliases()
|
||||||
{
|
{
|
||||||
if (type_aliases().count("std::__cxx11::basic_string<char,std::char_traits<"
|
|
||||||
"char>,std::allocator<char>>") == 0U) {
|
|
||||||
type_aliases().insert({"std::__cxx11::basic_string<char,std::char_"
|
|
||||||
"traits<char>,std::allocator<char>>",
|
|
||||||
"std::string"});
|
|
||||||
}
|
|
||||||
if (type_aliases().count("std::basic_string<char>") == 0U) {
|
if (type_aliases().count("std::basic_string<char>") == 0U) {
|
||||||
type_aliases().insert({"std::basic_string<char>", "std::string"});
|
type_aliases().insert({"std::basic_string<char>", "std::string"});
|
||||||
}
|
}
|
||||||
@@ -210,11 +205,11 @@ void diagram::initialize_type_aliases()
|
|||||||
type_aliases().insert(
|
type_aliases().insert(
|
||||||
{"std::integral_constant<bool,false>", "std::false_type"});
|
{"std::integral_constant<bool,false>", "std::false_type"});
|
||||||
}
|
}
|
||||||
// #if LLVM_VERSION_MAJOR >= 16
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
// if (type_aliases().count("std::basic_string") == 0U) {
|
if (type_aliases().count("std::basic_string") == 0U) {
|
||||||
// type_aliases().insert({"std::basic_string", "std::string"});
|
type_aliases().insert({"std::basic_string", "std::string"});
|
||||||
// }
|
}
|
||||||
// #endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
common::model::diagram_t class_diagram::type() const
|
common::model::diagram_t class_diagram::type() const
|
||||||
|
|||||||
@@ -132,7 +132,10 @@ struct relationship_hint_t {
|
|||||||
|
|
||||||
using relationship_hints_t = std::map<std::string, relationship_hint_t>;
|
using relationship_hints_t = std::map<std::string, relationship_hint_t>;
|
||||||
|
|
||||||
using type_aliases_t = std::map<std::string, std::string>;
|
using type_aliases_t =
|
||||||
|
std::map<std::string, std::string>;
|
||||||
|
using type_aliases_longer_first_t =
|
||||||
|
std::map<std::string, std::string, std::greater<std::string>>;
|
||||||
|
|
||||||
enum class location_t { marker, fileline, function };
|
enum class location_t { marker, fileline, function };
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,13 @@ TEST_CASE("t00008", "[test-case][class]")
|
|||||||
|
|
||||||
using namespace json;
|
using namespace json;
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
REQUIRE(IsClassTemplate(
|
||||||
|
j, "A<T,P=T,CMP=nullptr,int N=3>"));
|
||||||
|
#else
|
||||||
REQUIRE(IsClassTemplate(
|
REQUIRE(IsClassTemplate(
|
||||||
j, "A<T,P=T,clanguml::t00008::CMP=nullptr,int N=3>"));
|
j, "A<T,P=T,clanguml::t00008::CMP=nullptr,int N=3>"));
|
||||||
|
#endif
|
||||||
REQUIRE(IsClassTemplate(j, "E::nested_template<ET>"));
|
REQUIRE(IsClassTemplate(j, "E::nested_template<ET>"));
|
||||||
REQUIRE(IsClass(j, "E::nested_template<char>"));
|
REQUIRE(IsClass(j, "E::nested_template<char>"));
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,13 @@ TEST_CASE("t00014", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, IsField<Public>("cb", "SimpleCallback<ACharString>"));
|
puml, IsField<Public>("cb", "SimpleCallback<ACharString>"));
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
REQUIRE_THAT(
|
||||||
|
puml, IsField<Public>("gcb", "GenericCallback<AWCharString>"));
|
||||||
|
#else
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
puml, IsField<Public>("gcb", "GenericCallback<R::AWCharString>"));
|
puml, IsField<Public>("gcb", "GenericCallback<R::AWCharString>"));
|
||||||
|
#endif
|
||||||
REQUIRE_THAT(puml, IsField<Public>("vcb", "VoidCallback"));
|
REQUIRE_THAT(puml, IsField<Public>("vcb", "VoidCallback"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
|
|||||||
Reference in New Issue
Block a user