Skip to content

Commit

Permalink
signature
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Sep 11, 2024
1 parent e1a8481 commit f09cb7e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/rust/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ pub fn signature_cfg(writer: &Writer, method: metadata::MethodDef) -> Cfg {
cfg_add_attributes(&mut cfg, method);
cfg
}
fn signature_cfg_combine(writer: &Writer, signature: &metadata::MethodDefSig, cfg: &mut Cfg) {
type_cfg_combine(writer, &signature.return_type, cfg);
fn signature_cfg_combine(writer: &Writer, signature: &windows_metadata::Signature, cfg: &mut Cfg) {
type_cfg_combine(writer, &signature.return_type.0, cfg);
signature
.params
.iter()
.for_each(|param| type_cfg_combine(writer, param, cfg));
.for_each(|param| type_cfg_combine(writer, &param.0, cfg));
}

fn cfg_add_attributes<R: AsRow + Into<metadata::HasAttribute>>(cfg: &mut Cfg, row: R) {
Expand Down
10 changes: 5 additions & 5 deletions crates/libs/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ pub enum Value {
}

#[derive(Debug)]
pub struct MethodDefSig {
pub struct Signature {
pub call_flags: MethodCallAttributes,
pub return_type: Type,
pub params: Vec<Type>,
pub return_type: (Type, Option<Param>),
pub params: Vec<(Type, Param)>,
}

impl MethodDefSig {
impl Signature {
pub fn size(&self) -> usize {
self.params
.iter()
.fold(0, |sum, param| sum + std::cmp::max(4, param.size()))
.fold(0, |sum, param| sum + std::cmp::max(4, param.0.size()))
}
}

Expand Down
41 changes: 18 additions & 23 deletions crates/libs/metadata/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,6 @@ impl MemberRef {
pub fn name(&self) -> &'static str {
self.str(1)
}

pub fn signature(&self) -> MethodDefSig {
let reader = self.reader();
let mut blob = self.blob(2);
let call_flags = MethodCallAttributes(blob.read_usize() as u8);
let params = blob.read_usize();
let return_type = reader.type_from_blob(&mut blob, None, &[]);

MethodDefSig {
call_flags,
return_type,
params: (0..params)
.map(|_| reader.type_from_blob(&mut blob, None, &[]))
.collect(),
}
}
}

impl MethodDef {
Expand Down Expand Up @@ -275,19 +259,30 @@ impl MethodDef {
self.impl_map().map_or("", |map| map.scope().name())
}

pub fn signature(&self, generics: &[Type]) -> MethodDefSig {
pub fn signature(&self, generics: &[Type]) -> Signature {
let reader = self.reader();
let mut blob = self.blob(4);
let call_flags = MethodCallAttributes(blob.read_usize() as u8);
let params = blob.read_usize();
let _param_count = blob.read_usize();
let return_type = reader.type_from_blob(&mut blob, None, generics);
let mut return_param = None;

let params = self
.params()
.filter_map(|param| {
if param.sequence() == 0 {
return_param = Some(param);
None
} else {
Some((reader.type_from_blob(&mut blob, None, generics), param))
}
})
.collect();

MethodDefSig {
Signature {
call_flags,
return_type,
params: (0..params)
.map(|_| reader.type_from_blob(&mut blob, None, generics))
.collect(),
return_type: (return_type, return_param),
params,
}
}
}
Expand Down

0 comments on commit f09cb7e

Please sign in to comment.