unique method and field names for classes and structs

This commit is contained in:
Janis 2023-04-21 22:11:34 +02:00
parent b1945fda35
commit 0d4dbfe552

View file

@ -315,6 +315,8 @@ pub mod sdk {
) -> anyhow::Result<(Vec<ClassField>, Vec<ClassMethod>)> {
log::debug!("{} children:", strct.get_full_name_or_default());
let mut field_names = HashMap::new();
let mut method_names = HashMap::new();
let mut fields = Vec::new();
let mut methods = Vec::new();
@ -327,11 +329,26 @@ pub mod sdk {
match Self::find_type(any_type::AnyProperty::from_prop(prop)) {
Ok(ty) => {
log::debug!("field: {ty:?}: {prop}");
let field_name = canonicalize_name(&prop.name().get_name().context("failed to retrieve field name")?).to_string();
let name = match field_names.entry(field_name.clone()) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += 1;
format!("{}{}", entry.key(), entry.get())
},
Entry::Vacant(entry) => {
let name = format!("{}", entry.key());
entry.insert(1);
name
},
};
fields.push(
ClassField {
offset: *prop.offset() as u32,
size: *prop.element_size() as u32,
name: canonicalize_name(&prop.name().get_name().context("failed to retrieve field name")?).to_string(),
name,
ty,
});
},
@ -344,7 +361,18 @@ pub mod sdk {
log::debug!("function: {func}");
if let Ok(method) = Self::process_function(func) {
methods.push(method);
let name = match method_names.entry(method.name.clone()) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += 1;
format!("{}{}", entry.key(), entry.get())
},
Entry::Vacant(entry) => {
let name = format!("{}", entry.key());
entry.insert(1);
name
},
};
methods.push(ClassMethod { name ,..method });
}
},
_ => {