@@ -53,6 +53,34 @@ ReturnCode_t dyn_type_to_tree(
5353 // Create new tree node
5454 utilities::collections::TreeNode<TreeNodeType> parent (member_name, type->get_name ().to_string (), type);
5555
56+ // Get its base class
57+ TypeDescriptor::_ref_type type_descriptor {traits<TypeDescriptor>::make_shared ()};
58+ ret = type->get_descriptor (type_descriptor);
59+
60+ if (ret != RETCODE_OK )
61+ {
62+ return ret;
63+ }
64+
65+ // Add base class as a new branch
66+ const auto base_type = type_descriptor->base_type ();
67+
68+ if (base_type != nullptr )
69+ {
70+ utilities::collections::TreeNode<TreeNodeType> child;
71+ ret = dyn_type_to_tree (base_type, " PARENT" , child);
72+
73+ if (ret != RETCODE_OK )
74+ {
75+ return ret;
76+ }
77+
78+ child.info .is_base = true ;
79+
80+ // Add each member with its name as a new child in a branch (recursion)
81+ parent.add_branch (child);
82+ }
83+
5684 // Get all members of this struct
5785 std::vector<std::pair<std::string, MemberDescriptor::_ref_type>> members_by_name;
5886 ret = get_members_sorted (type, members_by_name);
@@ -246,12 +274,12 @@ ReturnCode_t type_kind_to_str(
246274 ret = map_kind_to_str (dyn_type, type_str);
247275 break ;
248276 }
249- case TK_STRUCTURE :
277+ case TK_ALIAS :
278+ case TK_BITMASK :
279+ case TK_BITSET :
250280 case TK_ENUM :
281+ case TK_STRUCTURE :
251282 case TK_UNION :
252- case TK_BITSET :
253- case TK_BITMASK :
254- case TK_ALIAS :
255283 {
256284 type_str = dyn_type->get_name ().to_string ();
257285 break ;
@@ -421,28 +449,47 @@ ReturnCode_t get_members_sorted(
421449{
422450 ReturnCode_t ret = RETCODE_OK ;
423451
424- std::map<MemberId, DynamicTypeMember::_ref_type> members;
425- ret = dyn_type->get_all_members (members);
452+ // Skip the inherited members
453+ TypeDescriptor::_ref_type type_descriptor {traits<TypeDescriptor>::make_shared ()};
454+ ret = dyn_type->get_descriptor (type_descriptor);
426455
427456 if (ret != RETCODE_OK )
428457 {
429458 return ret;
430459 }
431460
432- for (const auto & member : members)
461+ const auto base_type = type_descriptor->base_type ();
462+
463+ std::uint32_t first_member = 0 ;
464+
465+ if (base_type != nullptr )
433466 {
467+ // If the struct has a base type, the first member is the base type
468+ first_member = base_type->get_member_count ();
469+ }
470+
471+ // Collect its members
472+ for (std::uint32_t index = first_member; index < dyn_type->get_member_count (); index++)
473+ {
474+ traits<DynamicTypeMember>::ref_type member;
475+ ret = dyn_type->get_member_by_index (member, index);
476+
477+ if (ret != RETCODE_OK )
478+ {
479+ return ret;
480+ }
481+
434482 MemberDescriptor::_ref_type member_descriptor {traits<MemberDescriptor>::make_shared ()};
435- ret = member. second ->get_descriptor (member_descriptor);
483+ ret = member->get_descriptor (member_descriptor);
436484
437485 if (ret != RETCODE_OK )
438486 {
439487 return ret;
440488 }
441489
442- const auto dyn_name = member.second ->get_name ();
443490 result.emplace_back (
444491 std::make_pair<std::string, MemberDescriptor::_ref_type>(
445- dyn_name .to_string (),
492+ member_descriptor-> name () .to_string (),
446493 std::move (member_descriptor)));
447494 }
448495
@@ -875,11 +922,32 @@ ReturnCode_t struct_to_str(
875922 }
876923
877924 // Add types name
878- struct_str += " struct " + node.info .type_kind_name + TYPE_OPENING ;
925+ struct_str += " struct " + node.info .type_kind_name ;
926+
927+ // Add inheritance
928+ if (type_descriptor->base_type () != nullptr )
929+ {
930+ std::string base_type_str;
931+ ret = type_kind_to_str (type_descriptor->base_type (), base_type_str);
932+
933+ if (ret != RETCODE_OK )
934+ {
935+ return ret;
936+ }
937+
938+ struct_str += " : " + base_type_str;
939+ }
940+
941+ struct_str += TYPE_OPENING ;
879942
880943 // Add struct attributes
881944 for (auto const & child : node.branches ())
882945 {
946+ if (child.info .is_base )
947+ {
948+ continue ;
949+ }
950+
883951 std::string child_str;
884952 node_to_str (child.info , child_str);
885953
0 commit comments