|
|
@@ -11,6 +11,7 @@ pub enum Type { |
|
|
|
U16, |
|
|
|
U32, |
|
|
|
U64, |
|
|
|
Interface(Interface), |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
@@ -19,18 +20,82 @@ pub struct TypeDef { |
|
|
|
ty: Type, |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
pub struct Interface { |
|
|
|
fields: std::collections::HashMap<String, Type>, |
|
|
|
} |
|
|
|
|
|
|
|
enum SplitType { |
|
|
|
Native(SplitTypeNative), |
|
|
|
Interface(Interface), |
|
|
|
} |
|
|
|
|
|
|
|
impl From<Type> for SplitType { |
|
|
|
fn from(ty: Type) -> SplitType { |
|
|
|
match ty { |
|
|
|
Type::I8 => SplitType::Native(SplitTypeNative::I8), |
|
|
|
Type::I16 => SplitType::Native(SplitTypeNative::I16), |
|
|
|
Type::I32 => SplitType::Native(SplitTypeNative::I32), |
|
|
|
Type::I64 => SplitType::Native(SplitTypeNative::I64), |
|
|
|
Type::U8 => SplitType::Native(SplitTypeNative::U8), |
|
|
|
Type::U16 => SplitType::Native(SplitTypeNative::U16), |
|
|
|
Type::U32 => SplitType::Native(SplitTypeNative::U32), |
|
|
|
Type::U64 => SplitType::Native(SplitTypeNative::U64), |
|
|
|
Type::Interface(interface) => SplitType::Interface(interface), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
enum SplitTypeNative { |
|
|
|
I8, |
|
|
|
I16, |
|
|
|
I32, |
|
|
|
I64, |
|
|
|
U8, |
|
|
|
U16, |
|
|
|
U32, |
|
|
|
U64, |
|
|
|
} |
|
|
|
|
|
|
|
fn print_interface(name: &str, interface: Interface) { |
|
|
|
println!("struct {} {{", name); |
|
|
|
for (field, ty) in interface.fields { |
|
|
|
match ty.into() { |
|
|
|
SplitType::Interface(_sub) => { |
|
|
|
unimplemented!(); |
|
|
|
} |
|
|
|
SplitType::Native(native) => { |
|
|
|
println!("{}: {}", field, native_to_rs(native)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
println!("}}"); |
|
|
|
} |
|
|
|
|
|
|
|
fn native_to_rs(native: SplitTypeNative) -> &'static str { |
|
|
|
use SplitTypeNative::*; |
|
|
|
match native { |
|
|
|
I8 => "i8", |
|
|
|
I16 => "i16", |
|
|
|
I32 => "i32", |
|
|
|
I64 => "i64", |
|
|
|
U8 => "u8", |
|
|
|
U16 => "u16", |
|
|
|
U32 => "u32", |
|
|
|
U64 => "u64", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn main() { |
|
|
|
let result = parser::TypeFileParser::new().parse("Test = uint8\nTestAgain = int32").unwrap(); |
|
|
|
let result = parser::TypeFileParser::new().parse("Test = uint8\nTestAgain = int32\nInterface = {hmm: uint32}").unwrap(); |
|
|
|
for def in result { |
|
|
|
println!("type {} = {};", def.name, match def.ty { |
|
|
|
Type::I8 => "i8", |
|
|
|
Type::I16 => "i16", |
|
|
|
Type::I32 => "i32", |
|
|
|
Type::I64 => "i64", |
|
|
|
Type::U8 => "u8", |
|
|
|
Type::U16 => "u16", |
|
|
|
Type::U32 => "u32", |
|
|
|
Type::U64 => "u64", |
|
|
|
}); |
|
|
|
match def.ty.into() { |
|
|
|
SplitType::Interface(interface) => { |
|
|
|
print_interface(&def.name, interface); |
|
|
|
}, |
|
|
|
SplitType::Native(native) => { |
|
|
|
println!("type {} = {};", def.name, native_to_rs(native)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |