From 0d4dbfe552844d4ce8a6f234b8ab3457a30a4a17 Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 21 Apr 2023 22:11:34 +0200 Subject: [PATCH] unique method and field names for classes and structs --- src/lib.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6f7575a..4cf00a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,6 +315,8 @@ pub mod sdk { ) -> anyhow::Result<(Vec, Vec)> { 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 }); } }, _ => {