#![allow(dead_code)]
#[derive(Debug, Clone)]
pub enum AbiType {
Struct(AbiStruct),
Enum(AbiEnum),
Union(AbiUnion),
Const(AbiConst),
}
#[derive(Debug, Clone)]
pub struct AbiStruct {
pub name: String,
pub fields: Vec<AbiField>,
pub doc: Option<String>,
pub repr_c: bool,
pub size_hint: Option<usize>,
}
#[derive(Debug, Clone)]
pub struct AbiField {
pub name: String,
pub rust_type: String,
pub doc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AbiEnum {
pub name: String,
pub repr: String,
pub variants: Vec<AbiVariant>,
pub doc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AbiVariant {
pub name: String,
pub value: Option<u64>,
pub doc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AbiUnion {
pub name: String,
pub variants: Vec<AbiUnionVariant>,
pub doc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AbiUnionVariant {
pub name: String,
pub rust_type: String,
pub doc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AbiConst {
pub name: String,
pub rust_type: String,
pub value: String,
pub doc: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct AbiTypes {
pub structs: Vec<AbiStruct>,
pub enums: Vec<AbiEnum>,
pub unions: Vec<AbiUnion>,
pub consts: Vec<AbiConst>,
}
impl AbiTypes {
pub fn new() -> AbiTypes {
AbiTypes::default()
}
pub fn add_struct(&mut self, struct_info: AbiStruct) {
self.structs.push(struct_info);
}
pub fn add_enum(&mut self, enum_info: AbiEnum) {
self.enums.push(enum_info);
}
pub fn add_union(&mut self, union_info: AbiUnion) {
self.unions.push(union_info);
}
pub fn add_const(&mut self, const_info: AbiConst) {
self.consts.push(const_info);
}
pub fn merge(&mut self, other: AbiTypes) {
self.structs.extend(other.structs);
self.enums.extend(other.enums);
self.unions.extend(other.unions);
self.consts.extend(other.consts);
}
pub fn types(&self) -> Vec<AbiType> {
let mut types: Vec<AbiType> = Vec::new();
for s in &self.structs {
types.push(AbiType::Struct(s.clone()));
}
for e in &self.enums {
types.push(AbiType::Enum(e.clone()));
}
for u in &self.unions {
types.push(AbiType::Union(u.clone()));
}
for c in &self.consts {
types.push(AbiType::Const(c.clone()));
}
types
}
}