Generate using declarations for anonymous structs in WASM bindings.

PiperOrigin-RevId: 832359379
Change-Id: Ie5913c584c5605f512dbe423524a829043179b6f
This commit is contained in:
Matias Manevi
2025-11-14 10:02:20 -08:00
committed by Copybara-Service
parent 999344c998
commit 53e254b715
3 changed files with 14 additions and 10 deletions
+2 -3
View File
@@ -105,13 +105,12 @@ std::vector<WrapperType> InitWrapperArray(ArrayType* array, SizeType size) {
return result; return result;
} }
// Create the types for anonymous structs
using mjVisualGlobal = decltype(::mjVisual::global); using mjVisualGlobal = decltype(::mjVisual::global);
using mjVisualQuality = decltype(::mjVisual::quality);
using mjVisualHeadlight = decltype(::mjVisual::headlight); using mjVisualHeadlight = decltype(::mjVisual::headlight);
using mjVisualMap = decltype(::mjVisual::map); using mjVisualMap = decltype(::mjVisual::map);
using mjVisualScale = decltype(::mjVisual::scale); using mjVisualQuality = decltype(::mjVisual::quality);
using mjVisualRgba = decltype(::mjVisual::rgba); using mjVisualRgba = decltype(::mjVisual::rgba);
using mjVisualScale = decltype(::mjVisual::scale);
struct MjContact { struct MjContact {
explicit MjContact(mjContact *ptr); explicit MjContact(mjContact *ptr);
+11
View File
@@ -699,6 +699,17 @@ class Generator:
autogenned_struct_definitions = [] autogenned_struct_definitions = []
markers_and_content = [] markers_and_content = []
typedefs = []
for type_name in sorted(constants.ANONYMOUS_STRUCTS):
s = constants.ANONYMOUS_STRUCTS[type_name]
typedefs.append(
f"using {type_name} = decltype(::{s['parent']}::{s['field_name']});"
)
markers_and_content.append((
"// {{ ANONYMOUS_STRUCT_TYPEDEFS }}",
typedefs,
))
# Sort by struct name by dependency to ensure deterministic output order # Sort by struct name by dependency to ensure deterministic output order
sorted_struct_names = sort_structs_by_dependency(self.structs_to_bind_data) sorted_struct_names = sort_structs_by_dependency(self.structs_to_bind_data)
+1 -7
View File
@@ -105,13 +105,7 @@ std::vector<WrapperType> InitWrapperArray(ArrayType* array, SizeType size) {
return result; return result;
} }
// Create the types for anonymous structs // {{ ANONYMOUS_STRUCT_TYPEDEFS }}
using mjVisualGlobal = decltype(::mjVisual::global);
using mjVisualQuality = decltype(::mjVisual::quality);
using mjVisualHeadlight = decltype(::mjVisual::headlight);
using mjVisualMap = decltype(::mjVisual::map);
using mjVisualScale = decltype(::mjVisual::scale);
using mjVisualRgba = decltype(::mjVisual::rgba);
// {{ AUTOGENNED_STRUCTS_HEADER }} // {{ AUTOGENNED_STRUCTS_HEADER }}