Classes are now working!

This commit is contained in:
Alex Crichton
2017-12-18 14:31:01 -08:00
parent 7c510a8a7e
commit 6593b5ef69
8 changed files with 396 additions and 91 deletions

View File

@ -10,7 +10,6 @@ pub struct Program {
#[derive(Serialize, Deserialize)]
pub struct Struct {
pub name: String,
pub ctor: Function,
pub functions: Vec<Function>,
pub methods: Vec<Method>,
}
@ -28,6 +27,33 @@ pub struct Function {
pub ret: Option<Type>,
}
impl Struct {
pub fn free_function(&self) -> String {
let mut name = format!("__wbindgen_");
name.extend(self.name
.chars()
.flat_map(|s| s.to_lowercase()));
name.push_str("_free");
return name
}
}
impl Function {
pub fn free_function_export_name(&self) -> String {
self.name.clone()
}
pub fn struct_function_export_name(&self, struct_: &str) -> String {
let mut name = struct_
.chars()
.flat_map(|s| s.to_lowercase())
.collect::<String>();
name.push_str("_");
name.push_str(&self.name);
return name
}
}
#[derive(Serialize, Deserialize)]
pub enum Type {
Number,