From af5672020ef19b96353c31280355345bad9f57e1 Mon Sep 17 00:00:00 2001 From: z78078 Date: Fri, 22 Jul 2022 10:41:23 +0800 Subject: [PATCH 1/2] nac3artiq: insert the constructor type to HashMap 'pyid_to_type' if class possess an __init__ method --- nac3artiq/src/symbol_resolver.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 434a724f..8981cc3b 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -545,6 +545,32 @@ impl InnerResolver { if let Some(ty) = self.pyid_to_type.read().get(&py_obj_id) { return Ok(Ok(*ty)) } + + // check if constructor function exists in the methods list + let pyid_to_def = self.pyid_to_def.read(); + let constructor_ty = pyid_to_def + .get(&py_obj_id) + .and_then(|def_id| { + defs.iter() + .find_map(|def| { + if let TopLevelDef::Class { + object_id, methods, constructor, .. + } = &*def.read() { + if object_id == def_id + || !constructor.is_none() + || methods.iter().any(|(s, _, _)| s == &"__init__".into()) { + return constructor.clone(); + } + } + None + }) + }); + + if let Some(ty) = constructor_ty { + self.pyid_to_type.write().insert(py_obj_id, ty); + return Ok(Ok(ty)) + } + let (extracted_ty, inst_check) = match self.get_pyty_obj_type( py, { -- 2.44.2 From 067da378c69691e1570630c58cc039f2677adeba Mon Sep 17 00:00:00 2001 From: z78078 Date: Fri, 22 Jul 2022 10:41:23 +0800 Subject: [PATCH 2/2] nac3artiq: insert the constructor type to table 'pyid_to_type' if class possess an __init__ method --- nac3artiq/src/symbol_resolver.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 434a724f..cff40af0 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -545,6 +545,30 @@ impl InnerResolver { if let Some(ty) = self.pyid_to_type.read().get(&py_obj_id) { return Ok(Ok(*ty)) } + + // check if constructor function exists in the methods list + let pyid_to_def = self.pyid_to_def.read(); + let constructor_ty = pyid_to_def + .get(&py_obj_id) + .and_then(|def_id| { + defs.iter() + .find_map(|def| { + if let TopLevelDef::Class { + object_id, methods, constructor, .. + } = &*def.read() { + if object_id == def_id && !constructor.is_none() && methods.iter().any(|(s, _, _)| s == &"__init__".into()) { + return constructor.clone(); + } + } + None + }) + }); + + if let Some(ty) = constructor_ty { + self.pyid_to_type.write().insert(py_obj_id, ty); + return Ok(Ok(ty)) + } + let (extracted_ty, inst_check) = match self.get_pyty_obj_type( py, { -- 2.44.2