Refactor: Group autogenerated structs source in bindings.cc
This change modifies the code generation for structs in `bindings.cc`. Instead of placing each struct's constructor and member functions under individual markers, all autogenerated struct source code is now grouped together under a single `// {{ AUTOGENNED_STRUCTS_SOURCE }}` marker. This improves the organization of the generated file and simplifies the template.
Future work would move the rest of the structs into this pattern
PiperOrigin-RevId: 828390272
Change-Id: Iee9d0e8766db86b2c1d4296a37ac7a8e6e05428b
This commit is contained in:
committed by
Copybara-Service
parent
5b00b033af
commit
fe1b6b7c80
+614
-659
File diff suppressed because it is too large
Load Diff
@@ -57,17 +57,23 @@ class Generator:
|
||||
autogenned_struct_definitions,
|
||||
))
|
||||
|
||||
for _, struct_data in self.structs_to_bind_data.items():
|
||||
# Bindings
|
||||
autogenned_struct_source = []
|
||||
for struct_name in sorted_struct_names:
|
||||
struct_data = self.structs_to_bind_data[struct_name]
|
||||
if struct_data.wrapped_source:
|
||||
autogenned_struct_source.append(
|
||||
struct_data.wrapped_source + "\n"
|
||||
)
|
||||
|
||||
# Bindings with markers
|
||||
markers_and_content.append((
|
||||
f"// INSERT-GENERATED-{struct_data.wrap_name}-BINDINGS",
|
||||
[l.binding for l in struct_data.wrapped_fields],
|
||||
))
|
||||
|
||||
# Special member functions
|
||||
markers_and_content.append((
|
||||
f"// INSERT-GENERATED-{struct_data.wrap_name}-CONSTRUCTOR",
|
||||
[struct_data.wrapped_source],
|
||||
))
|
||||
markers_and_content.append((
|
||||
"// {{ AUTOGENNED_STRUCTS_SOURCE }}",
|
||||
autogenned_struct_source,
|
||||
))
|
||||
|
||||
return markers_and_content
|
||||
|
||||
@@ -592,6 +592,16 @@ def build_struct_source(
|
||||
wrapped_fields: List[WrappedFieldData],
|
||||
):
|
||||
"""Builds the C++ .cc file code for a struct."""
|
||||
# These structs require specific function calls for creation and/or deletion
|
||||
# which, for now, are hardcoded in the template file.
|
||||
if struct_name in [
|
||||
"mjData",
|
||||
"mjModel",
|
||||
"mjvScene",
|
||||
"mjSpec",
|
||||
]:
|
||||
return ""
|
||||
|
||||
s = struct_name
|
||||
w = common.uppercase_first_letter(s)
|
||||
is_mjs = "Mjs" in w
|
||||
|
||||
@@ -447,41 +447,7 @@ EMSCRIPTEN_BINDINGS(mujoco_enums) {
|
||||
}
|
||||
|
||||
// STRUCTS
|
||||
// =============== MjLROpt =============== //
|
||||
// INSERT-GENERATED-MjLROpt-CONSTRUCTOR
|
||||
|
||||
// =============== MjOption =============== //
|
||||
// INSERT-GENERATED-MjOption-CONSTRUCTOR
|
||||
|
||||
// =============== MjStatistic =============== //
|
||||
// INSERT-GENERATED-MjStatistic-CONSTRUCTOR
|
||||
|
||||
// =============== MjVisual... =============== //
|
||||
// INSERT-GENERATED-MjVisualGlobal-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisualQuality-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisualHeadlight-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisualMap-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisualScale-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisualRgba-CONSTRUCTOR
|
||||
|
||||
// INSERT-GENERATED-MjVisual-CONSTRUCTOR
|
||||
|
||||
// =============== MjSolverStat =============== //
|
||||
// INSERT-GENERATED-MjSolverStat-CONSTRUCTOR
|
||||
|
||||
// =============== MjTimerStat =============== //
|
||||
// INSERT-GENERATED-MjTimerStat-CONSTRUCTOR
|
||||
|
||||
// =============== MjWarningStat =============== //
|
||||
// INSERT-GENERATED-MjWarningStat-CONSTRUCTOR
|
||||
|
||||
// =============== MjContact =============== //
|
||||
// INSERT-GENERATED-MjContact-CONSTRUCTOR
|
||||
// {{ AUTOGENNED_STRUCTS_SOURCE }}
|
||||
|
||||
// =============== MjModel =============== //
|
||||
MjModel::MjModel(mjModel *m)
|
||||
@@ -559,25 +525,7 @@ std::vector<MjContact> MjData::contact() const {
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
// =============== MjvPerturb =============== //
|
||||
// INSERT-GENERATED-MjvPerturb-CONSTRUCTOR
|
||||
|
||||
// =============== MjvCamera =============== //
|
||||
// INSERT-GENERATED-MjvCamera-CONSTRUCTOR
|
||||
|
||||
// =============== MjvGLCamera =============== //
|
||||
// INSERT-GENERATED-MjvGLCamera-CONSTRUCTOR
|
||||
|
||||
// =============== MjvGeom =============== //
|
||||
// INSERT-GENERATED-MjvGeom-CONSTRUCTOR
|
||||
|
||||
// =============== MjvLight =============== //
|
||||
// INSERT-GENERATED-MjvLight-CONSTRUCTOR
|
||||
|
||||
// =============== MjvOption =============== //
|
||||
// INSERT-GENERATED-MjvOption-CONSTRUCTOR
|
||||
|
||||
// =============== MjvScene =============== //
|
||||
MjvScene::MjvScene() {
|
||||
owned_ = true;
|
||||
ptr_ = new mjvScene;
|
||||
@@ -667,16 +615,6 @@ std::vector<MjvGeom> MjvScene::geoms() const {
|
||||
return geoms;
|
||||
}
|
||||
|
||||
// =============== MjvFigure =============== //
|
||||
// INSERT-GENERATED-MjvFigure-CONSTRUCTOR
|
||||
|
||||
// =============== MjsElement =============== //
|
||||
// INSERT-GENERATED-MjsElement-CONSTRUCTOR
|
||||
|
||||
// =============== MjsCompiler =============== //
|
||||
// INSERT-GENERATED-MjsCompiler-CONSTRUCTOR
|
||||
|
||||
// =============== MjSpec =============== //
|
||||
MjSpec::MjSpec()
|
||||
: ptr_(mj_makeSpec()),
|
||||
option(&ptr_->option),
|
||||
@@ -732,90 +670,6 @@ MjSpec::~MjSpec() {
|
||||
mjSpec *MjSpec::get() const { return ptr_; }
|
||||
void MjSpec::set(mjSpec *ptr) { ptr_ = ptr; }
|
||||
|
||||
// =============== MjsOrientation =============== //
|
||||
// INSERT-GENERATED-MjsOrientation-CONSTRUCTOR
|
||||
|
||||
// =============== MjsBody =============== //
|
||||
// INSERT-GENERATED-MjsBody-CONSTRUCTOR
|
||||
|
||||
// =============== MjsGeom =============== //
|
||||
// INSERT-GENERATED-MjsGeom-CONSTRUCTOR
|
||||
|
||||
// =============== MjsFrame =============== //
|
||||
// INSERT-GENERATED-MjsFrame-CONSTRUCTOR
|
||||
|
||||
// =============== MjsJoint =============== //
|
||||
// INSERT-GENERATED-MjsJoint-CONSTRUCTOR
|
||||
|
||||
// =============== MjsSite =============== //
|
||||
// INSERT-GENERATED-MjsSite-CONSTRUCTOR
|
||||
|
||||
// =============== MjsCamera =============== //
|
||||
// INSERT-GENERATED-MjsCamera-CONSTRUCTOR
|
||||
|
||||
// =============== MjsLight =============== //
|
||||
// INSERT-GENERATED-MjsLight-CONSTRUCTOR
|
||||
|
||||
// =============== MjsFlex =============== //
|
||||
// INSERT-GENERATED-MjsFlex-CONSTRUCTOR
|
||||
|
||||
// =============== MjsMesh =============== //
|
||||
// INSERT-GENERATED-MjsMesh-CONSTRUCTOR
|
||||
|
||||
// =============== MjsHField =============== //
|
||||
// INSERT-GENERATED-MjsHField-CONSTRUCTOR
|
||||
|
||||
// =============== MjsSkin =============== //
|
||||
// INSERT-GENERATED-MjsSkin-CONSTRUCTOR
|
||||
|
||||
// =============== MjsTexture =============== //
|
||||
// INSERT-GENERATED-MjsTexture-CONSTRUCTOR
|
||||
|
||||
// =============== MjsMaterial =============== //
|
||||
// INSERT-GENERATED-MjsMaterial-CONSTRUCTOR
|
||||
|
||||
// =============== MjsPair =============== //
|
||||
// INSERT-GENERATED-MjsPair-CONSTRUCTOR
|
||||
|
||||
// =============== MjsExclude =============== //
|
||||
// INSERT-GENERATED-MjsExclude-CONSTRUCTOR
|
||||
|
||||
// =============== MjsEquality =============== //
|
||||
// INSERT-GENERATED-MjsEquality-CONSTRUCTOR
|
||||
|
||||
// =============== MjsTendon =============== //
|
||||
// INSERT-GENERATED-MjsTendon-CONSTRUCTOR
|
||||
|
||||
// =============== MjsWrap =============== //
|
||||
// INSERT-GENERATED-MjsWrap-CONSTRUCTOR
|
||||
|
||||
// =============== MjsActuator =============== //
|
||||
// INSERT-GENERATED-MjsActuator-CONSTRUCTOR
|
||||
|
||||
// =============== MjsSensor =============== //
|
||||
// INSERT-GENERATED-MjsSensor-CONSTRUCTOR
|
||||
|
||||
// =============== MjsNumeric =============== //
|
||||
// INSERT-GENERATED-MjsNumeric-CONSTRUCTOR
|
||||
|
||||
// =============== MjsText =============== //
|
||||
// INSERT-GENERATED-MjsText-CONSTRUCTOR
|
||||
|
||||
// =============== MjsTuple =============== //
|
||||
// INSERT-GENERATED-MjsTuple-CONSTRUCTOR
|
||||
|
||||
// =============== MjsKey =============== //
|
||||
// INSERT-GENERATED-MjsKey-CONSTRUCTOR
|
||||
|
||||
// =============== MjsDefault =============== //
|
||||
// INSERT-GENERATED-MjsDefault-CONSTRUCTOR
|
||||
|
||||
// =============== MjsPlugin =============== //
|
||||
// INSERT-GENERATED-MjsPlugin-CONSTRUCTOR
|
||||
|
||||
// =============== MjVFS =============== //
|
||||
// INSERT-GENERATED-MjVFS-CONSTRUCTOR
|
||||
|
||||
// ======= FACTORY AND HELPER FUNCTIONS ========= //
|
||||
std::unique_ptr<MjModel> loadFromXML(std::string filename) {
|
||||
char error[1000];
|
||||
|
||||
Reference in New Issue
Block a user