Fixed handling of nested anonymous arrays of structs

This commit is contained in:
Bartek Kryza
2024-06-01 14:16:05 +02:00
parent c9b3f92dbe
commit d599bb6715
4 changed files with 21 additions and 2 deletions

View File

@@ -1795,6 +1795,10 @@ void translation_unit_visitor::process_field(
relationship_hint = relationship_t::kAssociation; relationship_hint = relationship_t::kAssociation;
field_type = field_type.getNonReferenceType(); field_type = field_type.getNonReferenceType();
} }
else if (field_type->isArrayType()) {
relationship_hint = relationship_t::kAggregation;
field_type = field_type->getAsArrayTypeUnsafe()->getElementType();
}
else if (field_type->isRValueReferenceType()) { else if (field_type->isRValueReferenceType()) {
field_type = field_type.getNonReferenceType(); field_type = field_type.getNonReferenceType();
} }

View File

@@ -116,6 +116,12 @@ std::string get_tag_name(const clang::TagDecl &declaration)
std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx, std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
bool try_canonical) bool try_canonical)
{ {
if (type->isArrayType()) {
return fmt::format("{}[]",
to_string(type->getAsArrayTypeUnsafe()->getElementType(), ctx,
try_canonical));
}
clang::PrintingPolicy print_policy(ctx.getLangOpts()); clang::PrintingPolicy print_policy(ctx.getLangOpts());
print_policy.SuppressScope = 0; print_policy.SuppressScope = 0;
print_policy.PrintCanonicalTypes = 0; print_policy.PrintCanonicalTypes = 0;
@@ -150,8 +156,8 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
result = "(anonymous)"; result = "(anonymous)";
else if (util::contains(result, "unnamed struct") || else if (util::contains(result, "unnamed struct") ||
util::contains(result, "unnamed union")) { util::contains(result, "unnamed union")) {
auto declarationTag = type->getAsTagDecl(); const auto *declarationTag = type->getAsTagDecl();
if (declarationTag == NULL) { if (declarationTag == nullptr) {
result = "(unnamed undeclared)"; result = "(unnamed undeclared)";
} }
else { else {

View File

@@ -1,6 +1,8 @@
namespace clanguml { namespace clanguml {
namespace t00037 { namespace t00037 {
constexpr auto LENGTH{10ULL};
class ST { class ST {
public: public:
struct { struct {
@@ -10,6 +12,11 @@ public:
double z; double z;
} dimensions; } dimensions;
struct {
int len;
int flags;
} __attribute__((packed)) bars[LENGTH];
private: private:
struct { struct {
double c{1.0}; double c{1.0};

View File

@@ -30,9 +30,11 @@ TEST_CASE("t00037")
REQUIRE(IsClass(src, "A")); REQUIRE(IsClass(src, "A"));
REQUIRE(IsClass(src, "ST::(units)")); REQUIRE(IsClass(src, "ST::(units)"));
REQUIRE(IsClass(src, "ST::(dimensions)")); REQUIRE(IsClass(src, "ST::(dimensions)"));
REQUIRE(IsClass(src, "ST::(bars)"));
REQUIRE( REQUIRE(
IsAggregation<Public>(src, "ST", "ST::(dimensions)", "dimensions")); IsAggregation<Public>(src, "ST", "ST::(dimensions)", "dimensions"));
REQUIRE(IsAggregation<Private>(src, "ST", "ST::(units)", "units")); REQUIRE(IsAggregation<Private>(src, "ST", "ST::(units)", "units"));
REQUIRE(IsAggregation<Public>(src, "ST", "ST::(bars)", "bars"));
}); });
} }