@@ -34,9 +34,10 @@ namespace dds {
34
34
35
35
using namespace eprosima ::utilities::collections;
36
36
37
- constexpr auto TYPE_OPENING = " \n {\n " ;
37
+ constexpr auto TYPE_OPENING = " {\n " ;
38
38
constexpr auto TYPE_CLOSURE = " };\n " ;
39
39
constexpr auto TAB_SEPARATOR = " " ;
40
+ constexpr auto MODULE_SEPARATOR = " ::" ;
40
41
41
42
// ////////////////////////
42
43
// DYNAMIC TYPE TO TREE //
@@ -667,6 +668,10 @@ ReturnCode_t alias_to_idl(
667
668
return ret;
668
669
}
669
670
671
+ // Open modules definition (if any) and get type name
672
+ std::string type_name = node.info .type_kind_name ;
673
+ unsigned int n_modules = open_modules_definition (type_name, idl);
674
+
670
675
idl << " typedef " ;
671
676
672
677
// Find the base type of the alias
@@ -678,7 +683,10 @@ ReturnCode_t alias_to_idl(
678
683
return ret;
679
684
}
680
685
681
- idl << " " << node.info .type_kind_name << " ;\n " ;
686
+ idl << " " << type_name << " ;\n " ;
687
+
688
+ // Close modules definition (if any)
689
+ close_modules_definition (n_modules, idl);
682
690
683
691
return ret;
684
692
}
@@ -706,6 +714,10 @@ ReturnCode_t bitmask_to_idl(
706
714
return RETCODE_BAD_PARAMETER;
707
715
}
708
716
717
+ // Open modules definition (if any) and get type name
718
+ std::string type_name = node.info .type_kind_name ;
719
+ unsigned int n_modules = open_modules_definition (type_name, idl);
720
+
709
721
// Annotation with the bitmask size
710
722
static constexpr std::uint32_t DEFAULT_BITMASK_SIZE = 32 ;
711
723
const auto bitmask_size = bounds[0 ];
@@ -715,7 +727,9 @@ ReturnCode_t bitmask_to_idl(
715
727
idl << " @bit_bound(" << std::to_string (bitmask_size) << " )\n " ;
716
728
}
717
729
718
- idl << " bitmask " << node.info .type_kind_name << TYPE_OPENING;
730
+ idl << tabulate_n (n_modules) << " bitmask " << type_name << " \n " ;
731
+
732
+ idl << tabulate_n (n_modules) << TYPE_OPENING;
719
733
720
734
const auto member_count = node.info .dynamic_type ->get_member_count ();
721
735
@@ -732,7 +746,7 @@ ReturnCode_t bitmask_to_idl(
732
746
return ret;
733
747
}
734
748
735
- idl << TAB_SEPARATOR;
749
+ idl << TAB_SEPARATOR << tabulate_n (n_modules) ;
736
750
737
751
// Annotation with the position
738
752
const auto id = member->get_id ();
@@ -756,8 +770,11 @@ ReturnCode_t bitmask_to_idl(
756
770
pos = id + 1 ;
757
771
}
758
772
759
- // Close definition
760
- idl << TYPE_CLOSURE;
773
+ // Close type definition
774
+ idl << tabulate_n (n_modules) << TYPE_CLOSURE;
775
+
776
+ // Close modules definition (if any)
777
+ close_modules_definition (n_modules, idl);
761
778
762
779
return ret;
763
780
}
@@ -770,7 +787,13 @@ ReturnCode_t bitset_to_idl(
770
787
771
788
ReturnCode_t ret = RETCODE_OK;
772
789
773
- idl << " bitset " << node.info .type_kind_name << TYPE_OPENING;
790
+ // Open modules definition (if any) and get type name
791
+ std::string type_name = node.info .type_kind_name ;
792
+ unsigned int n_modules = open_modules_definition (type_name, idl);
793
+
794
+ idl << " bitset " << type_name << " \n " ;
795
+
796
+ idl << tabulate_n (n_modules) << TYPE_OPENING;
774
797
775
798
// Find the bits that each bitfield occupies
776
799
BoundSeq bounds;
@@ -814,10 +837,10 @@ ReturnCode_t bitset_to_idl(
814
837
const auto gap = id - bits_set;
815
838
bits_set += gap;
816
839
817
- idl << TAB_SEPARATOR << " bitfield<" << std::to_string (gap) << " >;\n " ;
840
+ idl << tabulate_n (n_modules) << TAB_SEPARATOR << " bitfield<" << std::to_string (gap) << " >;\n " ;
818
841
}
819
842
820
- idl << TAB_SEPARATOR << " bitfield<" << std::to_string (bounds[index ]);
843
+ idl << tabulate_n (n_modules) << TAB_SEPARATOR << " bitfield<" << std::to_string (bounds[index ]);
821
844
822
845
MemberDescriptor::_ref_type member_descriptor {traits<MemberDescriptor>::make_shared ()};
823
846
ret = member->get_descriptor (member_descriptor);
@@ -852,8 +875,11 @@ ReturnCode_t bitset_to_idl(
852
875
bits_set += bounds[index ];
853
876
}
854
877
855
- // Close definition
856
- idl << TYPE_CLOSURE;
878
+ // Close type definition
879
+ idl << tabulate_n (n_modules) << TYPE_CLOSURE;
880
+
881
+ // Close modules definition (if any)
882
+ close_modules_definition (n_modules, idl);
857
883
858
884
return ret;
859
885
}
@@ -866,7 +892,13 @@ ReturnCode_t enum_to_idl(
866
892
867
893
ReturnCode_t ret = RETCODE_OK;
868
894
869
- idl << " enum " << node.info .type_kind_name << TYPE_OPENING << TAB_SEPARATOR;
895
+ // Open modules definition (if any) and get type name
896
+ std::string type_name = node.info .type_kind_name ;
897
+ unsigned int n_modules = open_modules_definition (type_name, idl);
898
+
899
+ idl << " enum " << type_name << " \n " ;
900
+
901
+ idl << tabulate_n (n_modules) << TYPE_OPENING << TAB_SEPARATOR;
870
902
871
903
for (std::uint32_t index = 0 ; index < node.info .dynamic_type ->get_member_count (); index ++)
872
904
{
@@ -879,16 +911,23 @@ ReturnCode_t enum_to_idl(
879
911
return ret;
880
912
}
881
913
882
- if (0 != index )
914
+ idl << tabulate_n (n_modules) << member->get_name ().to_string ();
915
+
916
+ if (node.info .dynamic_type ->get_member_count () - 1 != index )
883
917
{
884
918
idl << " ,\n " << TAB_SEPARATOR;
885
919
}
886
-
887
- idl << member->get_name ().to_string ();
920
+ else
921
+ {
922
+ idl << " \n " ;
923
+ }
888
924
}
889
925
890
- // Close definition
891
- idl << " \n " << TYPE_CLOSURE;
926
+ // Close type definition
927
+ idl << tabulate_n (n_modules) << TYPE_CLOSURE;
928
+
929
+ // Close modules definition (if any)
930
+ close_modules_definition (n_modules, idl);
892
931
893
932
return ret;
894
933
}
@@ -911,6 +950,10 @@ ReturnCode_t struct_to_idl(
911
950
return ret;
912
951
}
913
952
953
+ // Open modules definition (if any) and get type name
954
+ std::string type_name = node.info .type_kind_name ;
955
+ unsigned int n_modules = open_modules_definition (type_name, idl);
956
+
914
957
switch (type_descriptor->extensibility_kind ())
915
958
{
916
959
case ExtensibilityKind::FINAL:
@@ -925,7 +968,7 @@ ReturnCode_t struct_to_idl(
925
968
}
926
969
case ExtensibilityKind::APPENDABLE:
927
970
{
928
- // Appendable is the default extensibility kind
971
+ idl << " @ extensibility(APPENDABLE) \n " ;
929
972
break ;
930
973
}
931
974
default :
@@ -935,8 +978,8 @@ ReturnCode_t struct_to_idl(
935
978
}
936
979
}
937
980
938
- // Add types name
939
- idl << " struct " << node. info . type_kind_name ;
981
+ // Add type name
982
+ idl << tabulate_n (n_modules) << " struct " << type_name ;
940
983
941
984
const auto base_type = type_descriptor->base_type ();
942
985
@@ -955,11 +998,13 @@ ReturnCode_t struct_to_idl(
955
998
}
956
999
}
957
1000
958
- idl << TYPE_OPENING;
1001
+ idl << " \n " << tabulate_n (n_modules) << TYPE_OPENING;
959
1002
960
1003
// Add struct attributes
961
1004
for (auto const & child : node.branches ())
962
1005
{
1006
+ idl << tabulate_n (n_modules);
1007
+
963
1008
if (child.info .is_base )
964
1009
{
965
1010
continue ;
@@ -970,8 +1015,11 @@ ReturnCode_t struct_to_idl(
970
1015
idl << " ;\n " ;
971
1016
}
972
1017
973
- // Close definition
974
- idl << TYPE_CLOSURE;
1018
+ // Close type definition
1019
+ idl << tabulate_n (n_modules) << TYPE_CLOSURE;
1020
+
1021
+ // Close modules definition (if any)
1022
+ close_modules_definition (n_modules, idl);
975
1023
976
1024
return ret;
977
1025
}
@@ -993,7 +1041,11 @@ ReturnCode_t union_to_idl(
993
1041
return ret;
994
1042
}
995
1043
996
- idl << " union " << node.info .type_kind_name << " switch (" ;
1044
+ // Open modules definition (if any) and get type name
1045
+ std::string type_name = node.info .type_kind_name ;
1046
+ unsigned int n_modules = open_modules_definition (type_name, idl);
1047
+
1048
+ idl << " union " << type_name << " switch (" ;
997
1049
998
1050
ret = type_kind_to_idl (type_descriptor->discriminator_type (), idl);
999
1051
@@ -1002,7 +1054,7 @@ ReturnCode_t union_to_idl(
1002
1054
return ret;
1003
1055
}
1004
1056
1005
- idl << " )" << TYPE_OPENING;
1057
+ idl << " )\n " << tabulate_n (n_modules) << TYPE_OPENING;
1006
1058
1007
1059
for (std::uint32_t index = 1 ; index < node.info .dynamic_type ->get_member_count (); index ++)
1008
1060
{
@@ -1022,15 +1074,15 @@ ReturnCode_t union_to_idl(
1022
1074
1023
1075
for (const auto & label : labels)
1024
1076
{
1025
- idl << TAB_SEPARATOR << " case " << std::to_string (label) << " :\n " ;
1077
+ idl << tabulate_n (n_modules) << TAB_SEPARATOR << " case " << std::to_string (label) << " :\n " ;
1026
1078
}
1027
1079
1028
1080
if (member_descriptor->is_default_label ())
1029
1081
{
1030
- idl << TAB_SEPARATOR << " default:\n " ;
1082
+ idl << tabulate_n (n_modules) << TAB_SEPARATOR << " default:\n " ;
1031
1083
}
1032
1084
1033
- idl << TAB_SEPARATOR << TAB_SEPARATOR;
1085
+ idl << TAB_SEPARATOR << TAB_SEPARATOR << tabulate_n (n_modules) ;
1034
1086
1035
1087
ret = type_kind_to_idl (member_descriptor->type (), idl);
1036
1088
@@ -1042,8 +1094,11 @@ ReturnCode_t union_to_idl(
1042
1094
idl << " " << member->get_name ().to_string () << " ;\n " ;
1043
1095
}
1044
1096
1045
- // Close definition
1046
- idl << TYPE_CLOSURE;
1097
+ // Close type definition
1098
+ idl << tabulate_n (n_modules) << TYPE_CLOSURE;
1099
+
1100
+ // Close modules definition (if any)
1101
+ close_modules_definition (n_modules, idl);
1047
1102
1048
1103
return ret;
1049
1104
}
@@ -1082,6 +1137,56 @@ ReturnCode_t node_to_idl(
1082
1137
return RETCODE_OK;
1083
1138
}
1084
1139
1140
+ unsigned int open_modules_definition (
1141
+ std::string& type_name,
1142
+ std::ostream& idl) noexcept
1143
+ {
1144
+ unsigned int n_modules = 0 ;
1145
+
1146
+ while (type_name.find (MODULE_SEPARATOR) != std::string::npos)
1147
+ {
1148
+ size_t pos_start = 0 ;
1149
+ size_t pos_end = type_name.find (MODULE_SEPARATOR);
1150
+
1151
+ std::string module_name = type_name.substr (0 , pos_end);
1152
+ type_name.erase (pos_start, pos_end - pos_start + std::strlen (MODULE_SEPARATOR));
1153
+
1154
+ idl << tabulate_n (n_modules) << " module " << module_name << " \n " ;
1155
+
1156
+ idl << tabulate_n (n_modules) << TYPE_OPENING;
1157
+
1158
+ n_modules++;
1159
+ }
1160
+
1161
+ idl << tabulate_n (n_modules);
1162
+
1163
+ return n_modules;
1164
+ }
1165
+
1166
+ void close_modules_definition (
1167
+ unsigned int & n_modules,
1168
+ std::ostream& idl) noexcept
1169
+ {
1170
+ while (n_modules > 0 )
1171
+ {
1172
+ idl << tabulate_n (--n_modules) << TYPE_CLOSURE;
1173
+ }
1174
+ }
1175
+
1176
+ std::string tabulate_n (
1177
+ const unsigned int & n_tabs) noexcept
1178
+ {
1179
+ std::string tabs;
1180
+
1181
+ tabs.reserve (std::strlen (TAB_SEPARATOR) * n_tabs);
1182
+ for (unsigned int i = 0 ; i < n_tabs; i++)
1183
+ {
1184
+ tabs += TAB_SEPARATOR;
1185
+ }
1186
+
1187
+ return tabs;
1188
+ }
1189
+
1085
1190
// /////////////////////
1086
1191
// AUXILIARY METHODS //
1087
1192
// /////////////////////
0 commit comments