remove type hint in class define

remove type hint in cmodule
This commit is contained in:
pikastech 2022-09-10 11:22:50 +08:00
parent 779f94c529
commit e0906f3602
2 changed files with 32 additions and 12 deletions

View File

@ -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(),
);

View File

@ -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(),