Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
grovesNL committed Nov 12, 2018
1 parent 2a3c506 commit 5128653
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
18 changes: 10 additions & 8 deletions src/bindgen/ir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,18 @@ impl Constant {
return Err("Unhanded const definition".to_owned());
}

let expr = Literal::load(if let syn::Expr::Struct(syn::ExprStruct { ref fields, .. }) = item.expr {
if is_transparent && fields.len() == 1 {
&fields[0].expr
let expr = Literal::load(
if let syn::Expr::Struct(syn::ExprStruct { ref fields, .. }) = item.expr {
if is_transparent && fields.len() == 1 {
&fields[0].expr
} else {
&item.expr
}
} else {
&item.expr
}
} else {
&item.expr
})?;

},
)?;

let full_name = Path::new(format!("{}_{}", struct_path, name));

Ok(Constant::new(
Expand Down
60 changes: 34 additions & 26 deletions src/bindgen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use syn;
use bindgen::cargo::{Cargo, PackageRef};
use bindgen::error::Error;
use bindgen::ir::{
AnnotationSet, Cfg, Constant, Documentation, Enum, Function, GenericParams, ItemContainer, ItemMap,
OpaqueItem, Path, Static, Struct, Type, Typedef, Union,
AnnotationSet, Cfg, Constant, Documentation, Enum, Function, GenericParams, ItemContainer,
ItemMap, OpaqueItem, Path, Static, Struct, Type, Typedef, Union,
};
use bindgen::utilities::{SynAbiHelpers, SynItemHelpers};

Expand Down Expand Up @@ -533,13 +533,10 @@ impl Parse {
}

for item_impl in impls {
let associated_constants = item_impl
.items
.iter()
.filter_map(|item| match item {
syn::ImplItem::Const(ref associated_constant) => Some(associated_constant),
_ => None,
});
let associated_constants = item_impl.items.iter().filter_map(|item| match item {
syn::ImplItem::Const(ref associated_constant) => Some(associated_constant),
_ => None,
});
self.load_syn_assoc_consts(
binding_crate_name,
crate_name,
Expand Down Expand Up @@ -660,30 +657,35 @@ impl Parse {
if ty.is_none() {
return;
}

let impl_struct_path = ty.unwrap().get_root_path().unwrap();

let is_transparent = if let Some(ref impl_items) = self.structs.get_items(&impl_struct_path) {
if impl_items.len() != 1 {
error!("Expected one struct to match path {}, but found {}", impl_struct_path, impl_items.len());
return;
}
if let ItemContainer::Struct(ref s) = impl_items[0] {
s.is_transparent
} else {
info!(
let is_transparent = if let Some(ref impl_items) = self.structs.get_items(&impl_struct_path)
{
if impl_items.len() != 1 {
error!(
"Expected one struct to match path {}, but found {}",
impl_struct_path,
impl_items.len()
);
return;
}
if let ItemContainer::Struct(ref s) = impl_items[0] {
s.is_transparent
} else {
info!(
"Skip impl block for {}::{} (impl blocks for associated constants are only defined for structs).",
crate_name, impl_struct_path
);
return;
}
} else {
error!(
return;
}
} else {
error!(
"Cannot find type for {}::{} (impl blocks require the struct declaration to be known).",
crate_name, impl_struct_path
);
return;
};
return;
};

for item in items.into_iter() {
if crate_name != binding_crate_name {
Expand All @@ -696,7 +698,13 @@ impl Parse {

let const_name = item.ident.to_string();

match Constant::load_assoc(const_name.clone(), item, mod_cfg, is_transparent, &impl_struct_path) {
match Constant::load_assoc(
const_name.clone(),
item,
mod_cfg,
is_transparent,
&impl_struct_path,
) {
Ok(constant) => {
info!("Take {}::{}.", crate_name, &item.ident);

Expand Down

0 comments on commit 5128653

Please sign in to comment.