Skip to content

Commit

Permalink
Support metadata with MethodDef constructor parent resolution (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 12, 2025
1 parent 7269206 commit 91cfd28
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
7 changes: 2 additions & 5 deletions crates/libs/bindgen/src/tables/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ impl Attribute {
}

pub fn name(&self) -> &'static str {
let AttributeType::MemberRef(ctor) = self.ty();
let MemberRefParent::TypeRef(ty) = ctor.parent();
ty.name()
self.ty().parent().name()
}

pub fn args(&self) -> Vec<(&'static str, Value)> {
let AttributeType::MemberRef(member) = self.ty();
let mut sig = member.blob(2);
let mut sig = self.ty().signature();
let mut values = self.blob(2);
let prolog = values.read_u16();
std::debug_assert_eq!(prolog, 1);
Expand Down
4 changes: 4 additions & 0 deletions crates/libs/bindgen/src/tables/method_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl MethodDef {
self.list(5)
}

pub fn parent(&self) -> MemberRefParent {
MemberRefParent::TypeDef(self.file().parent(5, *self))
}

pub fn impl_map(&self) -> Option<ImplMap> {
self.file()
.equal_range(1, MemberForwarded::MethodDef(*self).encode())
Expand Down
27 changes: 27 additions & 0 deletions crates/libs/bindgen/src/winmd/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,26 @@ macro_rules! code {
}

code! { AttributeType(3)
(MethodDef, 2)
(MemberRef, 3)
}

impl AttributeType {
pub fn parent(&self) -> MemberRefParent {
match self {
Self::MethodDef(row) => row.parent(),
Self::MemberRef(row) => row.parent(),
}
}

pub fn signature(&self) -> Blob {
match self {
Self::MethodDef(row) => row.blob(4),
Self::MemberRef(row) => row.blob(2),
}
}
}

code! { HasAttribute(5)
(MethodDef, 0)
(Field, 1)
Expand All @@ -62,9 +79,19 @@ code! { MemberForwarded(1)
}

code! { MemberRefParent(3)
(TypeDef, 0)
(TypeRef, 1)
}

impl MemberRefParent {
pub fn name(&self) -> &'static str {
match self {
Self::TypeDef(row) => row.name(),
Self::TypeRef(row) => row.name(),
}
}
}

code! { TypeDefOrRef(2)
(TypeDef, 0)
(TypeRef, 1)
Expand Down
13 changes: 13 additions & 0 deletions crates/libs/bindgen/src/winmd/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ impl File {
RowIterator::new(self, first..last)
}

pub(crate) fn parent<P: AsRow, C: AsRow>(&'static self, column: usize, child: C) -> P {
P::from_row(Row::new(
self,
self.upper_bound_of(
P::TABLE,
0,
self.tables[P::TABLE].len,
column,
child.index() + 1,
) - 1,
))
}

fn lower_bound_of(
&self,
table: usize,
Expand Down

0 comments on commit 91cfd28

Please sign in to comment.