diff --git a/crates/libs/bindgen/src/winmd/from_reader.rs b/crates/libs/bindgen/src/winmd/from_reader.rs index 3bbeea503a..534c35ecc3 100644 --- a/crates/libs/bindgen/src/winmd/from_reader.rs +++ b/crates/libs/bindgen/src/winmd/from_reader.rs @@ -1,5 +1,5 @@ use super::*; -use metadata::{HasAttributes, AsRow}; +use metadata::{AsRow, HasAttributes}; pub fn from_reader(reader: &metadata::Reader, config: std::collections::BTreeMap<&str, &str>, output: &str) -> Result<()> { let mut writer = Writer::new(output); @@ -68,11 +68,7 @@ pub fn from_reader(reader: &metadata::Reader, config: std::collections::BTreeMap writer.tables.Field.push(Field { Flags: field.flags().0, Name: writer.strings.insert(field.name()), Signature: signature }); if let Some(constant) = field.constant() { - writer.tables.Constant.push(Constant { - Type: constant.usize(0) as u16, - Parent: HasConstant::Field(writer.tables.Field.len() as u32 -1), - Value: writer.blobs.insert(&constant.blob(2)), - }) + writer.tables.Constant.push(Constant { Type: constant.usize(0) as u16, Parent: HasConstant::Field(writer.tables.Field.len() as u32 - 1), Value: writer.blobs.insert(&constant.blob(2)) }) } } @@ -102,22 +98,14 @@ pub fn from_reader(reader: &metadata::Reader, config: std::collections::BTreeMap assert_eq!(attribute_ctor.name(), ".ctor"); let metadata::MemberRefParent::TypeRef(attribute_type) = attribute_ctor.parent(); - let attribute_type_ref = if let TypeDefOrRef::TypeRef(type_ref) = writer.insert_type_ref(attribute_type.namespace(), attribute_type.name()) { - MemberRefParent::TypeRef(type_ref) - } else { - panic!() - }; + let attribute_type_ref = if let TypeDefOrRef::TypeRef(type_ref) = writer.insert_type_ref(attribute_type.namespace(), attribute_type.name()) { MemberRefParent::TypeRef(type_ref) } else { panic!() }; let signature = attribute_ctor.signature(); let return_type = winmd_type(&signature.return_type); let param_types: Vec = signature.params.iter().map(winmd_type).collect(); let signature = writer.insert_method_sig(signature.call_flags, &return_type, ¶m_types); - - writer.tables.MemberRef.push(MemberRef { - Class: attribute_type_ref, - Name: writer.strings.insert(".ctor"), - Signature: signature, - }); + + writer.tables.MemberRef.push(MemberRef { Class: attribute_type_ref, Name: writer.strings.insert(".ctor"), Signature: signature }); let mut values = 1u16.to_le_bytes().to_vec(); // prolog let args = attribute.args(); @@ -140,11 +128,7 @@ pub fn from_reader(reader: &metadata::Reader, config: std::collections::BTreeMap let values = writer.blobs.insert(&values); - writer.tables.CustomAttribute.push(CustomAttribute { - Parent: HasAttribute::TypeDef(def_ref), - Type: AttributeType::MemberRef(writer.tables.MemberRef.len() as u32 - 1), - Value: values - }); + writer.tables.CustomAttribute.push(CustomAttribute { Parent: HasAttribute::TypeDef(def_ref), Type: AttributeType::MemberRef(writer.tables.MemberRef.len() as u32 - 1), Value: values }); } } @@ -156,13 +140,19 @@ pub fn from_reader(reader: &metadata::Reader, config: std::collections::BTreeMap // TODO: need a Blob type for writing fn value_blob(value: &metadata::Value, blob: &mut Vec) { match value { - metadata::Value::Bool(value) => if *value { blob.push(1) } else { blob.push(0 )}, + metadata::Value::Bool(value) => { + if *value { + blob.push(1) + } else { + blob.push(0) + } + } metadata::Value::U32(value) => blob.extend_from_slice(&value.to_le_bytes()), metadata::Value::I32(value) => blob.extend_from_slice(&value.to_le_bytes()), metadata::Value::U16(value) => blob.extend_from_slice(&value.to_le_bytes()), metadata::Value::U8(value) => blob.extend_from_slice(&value.to_le_bytes()), metadata::Value::EnumDef(_def, value) => value_blob(value, blob), - + metadata::Value::TypeName(value) => { let value = value.to_string(); usize_blob(value.len(), blob); @@ -174,7 +164,6 @@ fn value_blob(value: &metadata::Value, blob: &mut Vec) { } rest => unimplemented!("{rest:?}"), } - } // TODO: keep the basic type conversion diff --git a/crates/libs/bindgen/src/winmd/writer/codes.rs b/crates/libs/bindgen/src/winmd/writer/codes.rs index e1fd2ec5c8..16e2565c52 100644 --- a/crates/libs/bindgen/src/winmd/writer/codes.rs +++ b/crates/libs/bindgen/src/winmd/writer/codes.rs @@ -16,7 +16,6 @@ macro_rules! code { }; } - code! { AttributeType(3) (MemberRef, 3) } @@ -67,4 +66,4 @@ code! { ResolutionScope(2) (ModuleRef, 1) (AssemblyRef, 2) (TypeRef, 3) -} \ No newline at end of file +} diff --git a/crates/libs/bindgen/src/winmd/writer/mod.rs b/crates/libs/bindgen/src/winmd/writer/mod.rs index 3932dddd7a..1ad0086db3 100644 --- a/crates/libs/bindgen/src/winmd/writer/mod.rs +++ b/crates/libs/bindgen/src/winmd/writer/mod.rs @@ -36,7 +36,7 @@ impl Writer { type_specs: Default::default(), }; - writer.tables.TypeDef.push(TypeDef { TypeName: writer.strings.insert(""), Flags: 0, TypeNamespace: 0, Extends: TypeDefOrRef::none(), FieldList: 0, MethodList: 0 }); + writer.tables.TypeDef.push(TypeDef { TypeName: writer.strings.insert(""), Flags: 0, TypeNamespace: 0, Extends: TypeDefOrRef::none(), FieldList: 0, MethodList: 0 }); let name = name.rsplit_once(&['/', '\\']).map_or(name, |(_, name)| name); diff --git a/crates/libs/bindgen/src/winmd/writer/tables.rs b/crates/libs/bindgen/src/winmd/writer/tables.rs index 51a64563d4..474f9cce8d 100644 --- a/crates/libs/bindgen/src/winmd/writer/tables.rs +++ b/crates/libs/bindgen/src/winmd/writer/tables.rs @@ -3,9 +3,6 @@ use super::Write; use super::*; -// TODO: make these columns strongly types - - #[derive(Default)] pub struct Tables { // TODO: use BTreeSet for tables that have a primary key, unless they are naturally sorted. @@ -184,30 +181,7 @@ impl Tables { let type_or_method_def = metadata::coded_index_size(&[self.TypeDef.len(), self.MethodDef.len()]); let member_ref_parent = metadata::coded_index_size(&[self.TypeDef.len(), self.TypeRef.len(), self.ModuleRef.len(), self.MethodDef.len(), self.TypeSpec.len()]); let custom_attribute_type = metadata::coded_index_size(&[self.MethodDef.len(), self.MemberRef.len(), 0, 0, 0]); - - let has_custom_attribute = metadata::coded_index_size(&[ - self.MethodDef.len(), - self.Field.len(), - self.TypeRef.len(), - self.TypeDef.len(), - self.Param.len(), - self.InterfaceImpl.len(), - self.MemberRef.len(), - self.Module.len(), - 0, - 0, - 0, - self.ModuleRef.len(), - self.TypeSpec.len(), - 0, - self.AssemblyRef.len(), - 0, - 0, - 0, - self.GenericParam.len(), - 0, - 0, - ]); + let has_custom_attribute = metadata::coded_index_size(&[self.MethodDef.len(), self.Field.len(), self.TypeRef.len(), self.TypeDef.len(), self.Param.len(), self.InterfaceImpl.len(), self.MemberRef.len(), self.Module.len(), 0, 0, 0, self.ModuleRef.len(), self.TypeSpec.len(), 0, self.AssemblyRef.len(), 0, 0, 0, self.GenericParam.len(), 0, 0]); let valid_tables: u64 = 1 << 0 | // Module 1 << 0x01 | // TypeRef diff --git a/crates/libs/metadata/src/type_name.rs b/crates/libs/metadata/src/type_name.rs index 13a578df7e..de0fce9258 100644 --- a/crates/libs/metadata/src/type_name.rs +++ b/crates/libs/metadata/src/type_name.rs @@ -62,10 +62,6 @@ impl TypeName { let index = full_name.rfind('.').expect("Expected full name separated with `.`"); Self::new(&full_name[0..index], &full_name[index + 1..]) } - - pub fn to_string(&self) -> String { - format!("{}.{}", self.namespace, self.name) - } } impl std::fmt::Display for TypeName {