Added support for anonymous nested structs

This commit is contained in:
Bartek Kryza
2022-03-06 00:21:46 +01:00
parent 17de8b7ded
commit ebe39fe3cf
3 changed files with 27 additions and 11 deletions

View File

@@ -33,12 +33,16 @@ void generator::generate_alias(const class_ &c, std::ostream &ostr) const
if (c.is_abstract())
class_type = "abstract";
auto full_name = c.full_name();
std::string full_name;
if (m_config.generate_packages())
ostr << class_type << " \"" << c.full_name_no_ns();
full_name = c.full_name_no_ns();
else
ostr << class_type << " \"" << c.full_name();
full_name = c.full_name();
if (full_name.empty())
full_name = "<<anonymous>>";
ostr << class_type << " \"" << full_name;
ostr << "\" as " << c.alias() << '\n';
}

View File

@@ -119,11 +119,19 @@ std::string class_::full_name(bool relative) const
ostr << name_and_ns();
render_template_params(ostr);
std::string res;
if (relative)
return using_namespace().relative(ostr.str());
res = using_namespace().relative(ostr.str());
else
return ostr.str();
res = ostr.str();
if(res.empty())
return "<<anonymous>>";
return res;
}
std::ostringstream &class_::render_template_params(
std::ostringstream &ostr) const
{

View File

@@ -313,7 +313,7 @@ void translation_unit_visitor::process_class_declaration(
auto c_ptr = std::make_unique<class_>(ctx.config().using_namespace());
auto &c = *c_ptr;
c.is_struct(cls.class_kind() == cppast::cpp_class_kind::struct_t);
// c.set_name(cx::util::full_name(ctx.get_namespace(), cls));
c.set_name(cls.name());
c.set_namespace(ctx.get_namespace());
@@ -711,8 +711,12 @@ void translation_unit_visitor::process_field(
{
bool template_instantiation_added_as_aggregation{false};
class_member m{detail::cpp_access_specifier_to_scope(as), mv.name(),
cppast::to_string(mv.type())};
auto type_name = cppast::to_string(mv.type());
if (type_name.empty())
type_name = "<<anonymous>>";
class_member m{
detail::cpp_access_specifier_to_scope(as), mv.name(), type_name};
if (mv.comment().has_value())
m.add_decorators(decorators::parse(mv.comment().value()));
@@ -722,6 +726,8 @@ void translation_unit_visitor::process_field(
auto &tr = cx::util::unreferenced(cppast::remove_cv(mv.type()));
auto tr_declaration = cppast::to_string(tr);
#ifndef __APPLE__
LOG_DBG("Processing field {} with unreferenced type of kind {}", mv.name(),
tr.kind());
@@ -748,8 +754,6 @@ void translation_unit_visitor::process_field(
// TODO
}
auto tr_declaration = cppast::to_string(tr);
if (!m.skip_relationship() &&
!template_instantiation_added_as_aggregation &&
(tr.kind() != cppast::cpp_type_kind::builtin_t) &&