Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use track_caller in more places #3424

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions crates/libs/bindgen/src/tables/method_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,48 @@ impl MethodDef {
self.impl_map().map_or("", |map| map.scope().name())
}

#[track_caller]
pub fn signature(&self, namespace: &str, generics: &[Type]) -> Signature {
let mut blob = self.blob(4);
let call_flags = MethodCallAttributes(blob.read_usize() as u8);
let _param_count = blob.read_usize();
let mut return_type = Type::from_blob(&mut blob, None, generics);
let mut return_param = None;

let params = self
.params()
.filter_map(|param| {
if param.sequence() == 0 {
if param.has_attribute("ConstAttribute") {
return_type = return_type.to_const_type();
}
let mut params = vec![];

return_param = Some(param);
None
} else {
let param_is_const = param.has_attribute("ConstAttribute");
let param_is_output = param.flags().contains(ParamAttributes::Out);
let mut ty = Type::from_blob(&mut blob, None, generics);
for param in self.params() {
if param.sequence() == 0 {
if param.has_attribute("ConstAttribute") {
return_type = return_type.to_const_type();
}

if param_is_const || !param_is_output {
ty = ty.to_const_type();
}
if !param_is_output {
ty = ty.to_const_ptr();
}
return_param = Some(param);
} else {
let param_is_const = param.has_attribute("ConstAttribute");
let param_is_output = param.flags().contains(ParamAttributes::Out);
let mut ty = Type::from_blob(&mut blob, None, generics);

if param_is_const || !param_is_output {
ty = ty.to_const_type();
}
if !param_is_output {
ty = ty.to_const_ptr();
}

if !param_is_output {
if let Some(attribute) = param.find_attribute("AssociatedEnumAttribute") {
if let Some((_, Value::Str(name))) = attribute.args().first() {
let overload = param.reader().unwrap_full_name(namespace, name);
if !param_is_output {
if let Some(attribute) = param.find_attribute("AssociatedEnumAttribute") {
if let Some((_, Value::Str(name))) = attribute.args().first() {
let overload = param.reader().unwrap_full_name(namespace, name);

ty = Type::PrimitiveOrEnum(Box::new(ty), Box::new(overload));
}
ty = Type::PrimitiveOrEnum(Box::new(ty), Box::new(overload));
}
}

Some((ty, param))
}
})
.collect();

params.push((ty, param));
}
}

Signature {
call_flags,
Expand Down
1 change: 1 addition & 0 deletions crates/libs/bindgen/src/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl TypeMap {
Self(HashMap::new())
}

#[track_caller]
pub fn filter(reader: &'static Reader, filter: &Filter, references: &References) -> Self {
let mut dependencies = Self::new();

Expand Down
1 change: 1 addition & 0 deletions crates/libs/bindgen/src/types/cpp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ impl CppInterface {
quote! { #namespace #name }
}

#[track_caller]
pub fn dependencies(&self, dependencies: &mut TypeMap) {
let base_interfaces = self.base_interfaces();

Expand Down
4 changes: 4 additions & 0 deletions crates/libs/bindgen/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl Type {
}
}

#[track_caller]
pub fn from_ref(code: TypeDefOrRef, enclosing: Option<&CppStruct>, generics: &[Self]) -> Self {
if let TypeDefOrRef::TypeSpec(def) = code {
let mut blob = def.blob(0);
Expand All @@ -227,6 +228,7 @@ impl Type {
.unwrap_full_name(code_name.namespace(), code_name.name())
}

#[track_caller]
pub fn from_blob(blob: &mut Blob, enclosing: Option<&CppStruct>, generics: &[Self]) -> Self {
// Used by WinRT to indicate that a struct input parameter is passed by reference rather than by value on the ABI.
let is_const = blob.read_modifiers().iter().any(|def| {
Expand Down Expand Up @@ -267,6 +269,7 @@ impl Type {
}
}

#[track_caller]
fn from_blob_impl(blob: &mut Blob, enclosing: Option<&CppStruct>, generics: &[Self]) -> Self {
let code = blob.read_usize();

Expand Down Expand Up @@ -600,6 +603,7 @@ impl Type {
}
}

#[track_caller]
pub fn dependencies(&self, dependencies: &mut TypeMap) {
let ty = self.decay();

Expand Down