From e0906f36021ca3d31ace94876ba64f79c3ba44fc Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 10 Sep 2022 11:22:50 +0800 Subject: [PATCH] remove type hint in class define remove type hint in cmodule --- tools/pikaCompiler/src/method_info.rs | 38 ++++++++++++++++++++------- tools/pikaCompiler/src/py_type.rs | 6 ++--- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/tools/pikaCompiler/src/method_info.rs b/tools/pikaCompiler/src/method_info.rs index f2174c942..82ef21ac2 100644 --- a/tools/pikaCompiler/src/method_info.rs +++ b/tools/pikaCompiler/src/method_info.rs @@ -43,15 +43,35 @@ impl MethodInfo { }; return Some(method_info); } - pub fn get_define(&self) -> String { - let return_token = match &self.return_type { - Some(s) => format!("->{}", s.to_string()), - None => String::from(""), - }; + pub fn get_arg_list_define(&self) -> String { let arg_list = match &self.arg_list { - Some(t) => t.to_string(), - None => String::from(""), + Some(arg_list) => arg_list.to_string(), + None => "".to_string(), }; + /* filter for type hint */ + let arg_defs: Vec<&str> = arg_list.split(',').collect(); + let mut arg_list_filted = Vec::new(); + for arg_def in arg_defs { + let arg_def: Vec<&str> = arg_def.split(':').collect(); + arg_list_filted.push(arg_def[0].to_string()); + } + // arg_list_filted to arg_list + let mut arg_list = String::new(); + for arg in arg_list_filted.clone() { + arg_list.push_str(&arg); + if arg != arg_list_filted.last().unwrap().to_string() { + arg_list.push_str(","); + } + } + return arg_list; + } + + pub fn get_define(&self) -> String { + // let return_token = match &self.return_type { + // Some(s) => format!("->{}", s.to_string()), + // None => String::from(""), + // }; + let arg_list = self.get_arg_list_define(); let mut class_define_method = String::from("class_defineMethod"); if self.is_constructor { class_define_method = String::from("class_defineConstructor"); @@ -65,8 +85,8 @@ impl MethodInfo { define.push_str( format!( - " {}(self, \"{}({}){}\", {}_{}Method);\n", - class_define_method, self.name, arg_list, return_token, self.class_name, self.name + " {}(self, \"{}({})\", {}_{}Method);\n", + class_define_method, self.name, arg_list, self.class_name, self.name ) .as_str(), ); diff --git a/tools/pikaCompiler/src/py_type.rs b/tools/pikaCompiler/src/py_type.rs index 3eb54514f..b871ebc0d 100644 --- a/tools/pikaCompiler/src/py_type.rs +++ b/tools/pikaCompiler/src/py_type.rs @@ -60,9 +60,9 @@ impl PyType { return "PikaObj*".to_string(); } - pub fn to_string(&self) -> String { - return self.type_name.clone(); - } + // pub fn to_string(&self) -> String { + // return self.type_name.clone(); + // } pub fn new(type_name: &String) -> PyType { return PyType { type_name: type_name.clone(),