summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chooser.rs2
-rw-r--r--src/clang.rs110
-rw-r--r--src/codegen/mod.rs141
-rw-r--r--src/ir/comp.rs37
-rw-r--r--src/ir/context.rs23
-rw-r--r--src/ir/enum_ty.rs38
-rw-r--r--src/ir/function.rs18
-rw-r--r--src/ir/item.rs37
-rw-r--r--src/ir/layout.rs8
-rw-r--r--src/ir/module.rs2
-rw-r--r--src/ir/objc.rs4
-rw-r--r--src/ir/ty.rs4
-rw-r--r--src/ir/type_collector.rs2
-rw-r--r--src/ir/var.rs41
-rw-r--r--src/lib.rs13
-rw-r--r--src/main.rs4
-rw-r--r--src/options.rs2
-rw-r--r--src/regex_set.rs8
-rw-r--r--tests/tests.rs3
19 files changed, 273 insertions, 224 deletions
diff --git a/src/chooser.rs b/src/chooser.rs
index 51392d70..bf610b28 100644
--- a/src/chooser.rs
+++ b/src/chooser.rs
@@ -1,7 +1,7 @@
//! A public API for more fine-grained customization of bindgen behavior.
+pub use ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
pub use ir::int::IntKind;
-pub use ir::enum_ty::{EnumVariantValue, EnumVariantCustomBehavior};
use std::fmt;
/// A trait to allow configuring different kinds of types in different
diff --git a/src/clang.rs b/src/clang.rs
index 63f9123e..c008effe 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -208,7 +208,8 @@ impl Cursor {
/// Is the referent a fully specialized template specialization without any
/// remaining free template arguments?
pub fn is_fully_specialized_template(&self) -> bool {
- self.is_template_specialization() && self.num_template_args().unwrap_or(0) > 0
+ self.is_template_specialization() &&
+ self.num_template_args().unwrap_or(0) > 0
}
/// Is the referent a template specialization that still has remaining free
@@ -349,13 +350,11 @@ impl Cursor {
pub fn contains_cursor(&self, kind: CXCursorKind) -> bool {
let mut found = false;
- self.visit(|c| {
- if c.kind() == kind {
- found = true;
- CXChildVisit_Break
- } else {
- CXChildVisit_Continue
- }
+ self.visit(|c| if c.kind() == kind {
+ found = true;
+ CXChildVisit_Break
+ } else {
+ CXChildVisit_Continue
});
found
@@ -846,8 +845,8 @@ impl SourceLocation {
&mut col,
&mut off);
(File {
- x: file,
- },
+ x: file,
+ },
line as usize,
col as usize,
off as usize)
@@ -1282,17 +1281,32 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
fn print_cursor<S: AsRef<str>>(depth: isize, prefix: S, c: &Cursor) {
let prefix = prefix.as_ref();
- print_indent(depth, format!(" {}kind = {}", prefix, kind_to_str(c.kind())));
- print_indent(depth, format!(" {}spelling = \"{}\"", prefix, c.spelling()));
+ print_indent(depth,
+ format!(" {}kind = {}", prefix, kind_to_str(c.kind())));
+ print_indent(depth,
+ format!(" {}spelling = \"{}\"", prefix, c.spelling()));
print_indent(depth, format!(" {}location = {}", prefix, c.location()));
- print_indent(depth, format!(" {}is-definition? {}", prefix, c.is_definition()));
- print_indent(depth, format!(" {}is-declaration? {}", prefix, c.is_declaration()));
- print_indent(depth, format!(" {}is-anonymous? {}", prefix, c.is_anonymous()));
- print_indent(depth, format!(" {}is-inlined-function? {}", prefix, c.is_inlined_function()));
+ print_indent(depth,
+ format!(" {}is-definition? {}",
+ prefix,
+ c.is_definition()));
+ print_indent(depth,
+ format!(" {}is-declaration? {}",
+ prefix,
+ c.is_declaration()));
+ print_indent(depth,
+ format!(" {}is-anonymous? {}", prefix, c.is_anonymous()));
+ print_indent(depth,
+ format!(" {}is-inlined-function? {}",
+ prefix,
+ c.is_inlined_function()));
let templ_kind = c.template_kind();
if templ_kind != CXCursor_NoDeclFound {
- print_indent(depth, format!(" {}template-kind = {}", prefix, kind_to_str(templ_kind)));
+ print_indent(depth,
+ format!(" {}template-kind = {}",
+ prefix,
+ kind_to_str(templ_kind)));
}
if let Some(usr) = c.usr() {
print_indent(depth, format!(" {}usr = \"{}\"", prefix, usr));
@@ -1301,38 +1315,53 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
print_indent(depth, format!(" {}number-of-args = {}", prefix, num));
}
if let Some(num) = c.num_template_args() {
- print_indent(depth, format!(" {}number-of-template-args = {}", prefix, num));
+ print_indent(depth,
+ format!(" {}number-of-template-args = {}",
+ prefix,
+ num));
}
if let Some(width) = c.bit_width() {
print_indent(depth, format!(" {}bit-width = {}", prefix, width));
}
if let Some(ty) = c.enum_type() {
- print_indent(depth, format!(" {}enum-type = {}", prefix, type_to_str(ty.kind())));
+ print_indent(depth,
+ format!(" {}enum-type = {}",
+ prefix,
+ type_to_str(ty.kind())));
}
if let Some(val) = c.enum_val_signed() {
print_indent(depth, format!(" {}enum-val = {}", prefix, val));
}
if let Some(ty) = c.typedef_type() {
- print_indent(depth, format!(" {}typedef-type = {}", prefix, type_to_str(ty.kind())));
+ print_indent(depth,
+ format!(" {}typedef-type = {}",
+ prefix,
+ type_to_str(ty.kind())));
}
if let Some(refd) = c.referenced() {
if refd != *c {
println!();
- print_cursor(depth, String::from(prefix) + "referenced.", &refd);
+ print_cursor(depth,
+ String::from(prefix) + "referenced.",
+ &refd);
}
}
let canonical = c.canonical();
if canonical != *c {
println!();
- print_cursor(depth, String::from(prefix) + "canonical.", &canonical);
+ print_cursor(depth,
+ String::from(prefix) + "canonical.",
+ &canonical);
}
if let Some(specialized) = c.specialized() {
if specialized != *c {
println!();
- print_cursor(depth, String::from(prefix) + "specialized.", &specialized);
+ print_cursor(depth,
+ String::from(prefix) + "specialized.",
+ &specialized);
}
}
}
@@ -1346,19 +1375,22 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
return;
}
- print_indent(depth, format!(" {}spelling = \"{}\"", prefix, ty.spelling()));
- let num_template_args = unsafe {
- clang_Type_getNumTemplateArguments(ty.x)
- };
+ print_indent(depth,
+ format!(" {}spelling = \"{}\"", prefix, ty.spelling()));
+ let num_template_args =
+ unsafe { clang_Type_getNumTemplateArguments(ty.x) };
if num_template_args >= 0 {
- print_indent(depth, format!(" {}number-of-template-args = {}",
- prefix,
- num_template_args));
+ print_indent(depth,
+ format!(" {}number-of-template-args = {}",
+ prefix,
+ num_template_args));
}
if let Some(num) = ty.num_elements() {
- print_indent(depth, format!(" {}number-of-elements = {}", prefix, num));
+ print_indent(depth,
+ format!(" {}number-of-elements = {}", prefix, num));
}
- print_indent(depth, format!(" {}is-variadic? {}", prefix, ty.is_variadic()));
+ print_indent(depth,
+ format!(" {}is-variadic? {}", prefix, ty.is_variadic()));
let canonical = ty.canonical_type();
if canonical != *ty {
@@ -1449,14 +1481,12 @@ impl EvalResult {
// unexposed type. Our solution is to just flat out ban all
// `CXType_Unexposed` from evaluation.
let mut found_cant_eval = false;
- cursor.visit(|c| {
- if c.kind() == CXCursor_TypeRef &&
- c.cur_type().kind() == CXType_Unexposed {
- found_cant_eval = true;
- CXChildVisit_Break
- } else {
- CXChildVisit_Recurse
- }
+ cursor.visit(|c| if c.kind() == CXCursor_TypeRef &&
+ c.cur_type().kind() == CXType_Unexposed {
+ found_cant_eval = true;
+ CXChildVisit_Break
+ } else {
+ CXChildVisit_Recurse
});
if found_cant_eval {
return None;
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 9dd3b6b9..9c71e993 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1,5 +1,6 @@
mod helpers;
+use self::helpers::{BlobTyBuilder, attributes};
use aster;
use ir::annotations::FieldAccessorKind;
@@ -17,7 +18,6 @@ use ir::objc::ObjCInterface;
use ir::ty::{Type, TypeKind};
use ir::type_collector::ItemSet;
use ir::var::Var;
-use self::helpers::{BlobTyBuilder, attributes};
use std::borrow::Cow;
use std::cell::Cell;
@@ -301,7 +301,8 @@ impl CodeGenerator for Item {
_extra: &()) {
if self.is_hidden(ctx) || result.seen(self.id()) {
debug!("<Item as CodeGenerator>::codegen: Ignoring hidden or seen: \
- self = {:?}", self);
+ self = {:?}",
+ self);
return;
}
@@ -376,7 +377,7 @@ impl CodeGenerator for Module {
};
if !ctx.options().enable_cxx_namespaces ||
- (self.is_inline() && !ctx.options().conservative_inline_namespaces) {
+ (self.is_inline() && !ctx.options().conservative_inline_namespaces) {
codegen_self(result, &mut false);
return;
}
@@ -574,11 +575,13 @@ impl CodeGenerator for Type {
// with invalid template parameters, and at least this way
// they can be replaced, instead of generating plain invalid
// code.
- let inner_canon_type =
- inner_item.expect_type().canonical_type(ctx);
+ let inner_canon_type = inner_item.expect_type()
+ .canonical_type(ctx);
if inner_canon_type.is_invalid_named_type() {
warn!("Item contained invalid named type, skipping: \
- {:?}, {:?}", item, inner_item);
+ {:?}, {:?}",
+ item,
+ inner_item);
return;
}
}
@@ -597,22 +600,25 @@ impl CodeGenerator for Type {
let simple_enum_path = match inner_rust_type.node {
ast::TyKind::Path(None, ref p) => {
if applicable_template_args.is_empty() &&
- inner_item.expect_type().canonical_type(ctx).is_enum() &&
- p.segments.iter().all(|p| p.parameters.is_none()) {
+ inner_item.expect_type()
+ .canonical_type(ctx)
+ .is_enum() &&
+ p.segments.iter().all(|p| p.parameters.is_none()) {
Some(p.clone())
} else {
None
}
- },
+ }
_ => None,
};
let typedef = if let Some(mut p) = simple_enum_path {
for ident in top_level_path(ctx, item).into_iter().rev() {
- p.segments.insert(0, ast::PathSegment {
- identifier: ident,
- parameters: None,
- });
+ p.segments.insert(0,
+ ast::PathSegment {
+ identifier: ident,
+ parameters: None,
+ });
}
typedef.use_().build(p).as_(rust_name)
} else {
@@ -622,7 +628,8 @@ impl CodeGenerator for Type {
if template_arg.is_named() {
if template_arg.is_invalid_named_type() {
warn!("Item contained invalid template \
- parameter: {:?}", item);
+ parameter: {:?}",
+ item);
return;
}
generics =
@@ -823,7 +830,8 @@ impl CodeGenerator for CompInfo {
// generate tuple struct if struct or union is a forward declaration,
// skip for now if template parameters are needed.
- if self.is_forward_declaration() && applicable_template_args.is_empty(){
+ if self.is_forward_declaration() &&
+ applicable_template_args.is_empty() {
let struct_name = item.canonical_name(ctx);
let struct_name = ctx.rust_ident_raw(&struct_name);
let tuple_struct = quote_item!(ctx.ext_cx(),
@@ -1012,10 +1020,12 @@ impl CodeGenerator for CompInfo {
// Try to catch a bitfield contination early.
if let (Some(ref mut bitfield_width), Some(width)) =
- (current_bitfield_width, field.bitfield()) {
+ (current_bitfield_width, field.bitfield()) {
let layout = current_bitfield_layout.unwrap();
debug!("Testing bitfield continuation {} {} {:?}",
- *bitfield_width, width, layout);
+ *bitfield_width,
+ width,
+ layout);
if *bitfield_width + width <= (layout.size * 8) as u32 {
*bitfield_width += width;
current_bitfield_fields.push(field);
@@ -1061,7 +1071,8 @@ impl CodeGenerator for CompInfo {
} else {
quote_ty!(ctx.ext_cx(), __BindgenUnionField<$ty>)
}
- } else if let Some(item) = field_ty.is_incomplete_array(ctx) {
+ } else if let Some(item) =
+ field_ty.is_incomplete_array(ctx) {
result.saw_incomplete_array();
let inner = item.to_rust_ty(ctx);
@@ -1239,10 +1250,10 @@ impl CodeGenerator for CompInfo {
let prefix = ctx.trait_prefix();
let phantom = quote_ty!(ctx.ext_cx(),
::$prefix::marker::PhantomData<$ident>);
- let field =
- StructFieldBuilder::named(format!("_phantom_{}", i))
- .pub_()
- .build_ty(phantom);
+ let field = StructFieldBuilder::named(format!("_phantom_{}",
+ i))
+ .pub_()
+ .build_ty(phantom);
fields.push(field)
}
}
@@ -1482,8 +1493,8 @@ impl MethodCodegen for Method {
// return-type = void.
if self.is_constructor() {
fndecl.inputs.remove(0);
- fndecl.output =
- ast::FunctionRetTy::Ty(quote_ty!(ctx.ext_cx(), Self));
+ fndecl.output = ast::FunctionRetTy::Ty(quote_ty!(ctx.ext_cx(),
+ Self));
}
let sig = ast::MethodSig {
@@ -1564,7 +1575,7 @@ enum EnumBuilder<'a> {
canonical_name: &'a str,
aster: P<ast::Item>,
},
- Consts { aster: P<ast::Item>, }
+ Consts { aster: P<ast::Item> },
}
impl<'a> EnumBuilder<'a> {
@@ -1825,12 +1836,11 @@ impl CodeGenerator for Enum {
.map(|repr| repr.to_rust_ty(ctx))
.unwrap_or_else(|| helpers::ast_ty::raw_type(ctx, repr_name));
- let mut builder =
- EnumBuilder::new(builder,
- &name,
- repr,
- is_bitfield,
- is_constified_enum);
+ let mut builder = EnumBuilder::new(builder,
+ &name,
+ repr,
+ is_bitfield,
+ is_constified_enum);
// A map where we keep a value -> variant relation.
let mut seen_values = HashMap::<_, String>::new();
@@ -1856,7 +1866,8 @@ impl CodeGenerator for Enum {
let mut constified_variants = VecDeque::new();
let mut iter = self.variants().iter().peekable();
- while let Some(variant) = iter.next().or_else(|| constified_variants.pop_front()) {
+ while let Some(variant) = iter.next()
+ .or_else(|| constified_variants.pop_front()) {
if variant.hidden() {
continue;
}
@@ -1877,8 +1888,9 @@ impl CodeGenerator for Enum {
let parent_name = parent_canonical_name.as_ref()
.unwrap();
- Cow::Owned(
- format!("{}_{}", parent_name, variant_name))
+ Cow::Owned(format!("{}_{}",
+ parent_name,
+ variant_name))
};
let existing_variant_name = entry.get();
@@ -1909,15 +1921,16 @@ impl CodeGenerator for Enum {
// we also generate a constant so it can be properly
// accessed.
if (is_rust_enum && enum_ty.name().is_none()) ||
- variant.force_constification() {
+ variant.force_constification() {
let mangled_name = if is_toplevel {
variant_name.clone()
} else {
let parent_name = parent_canonical_name.as_ref()
.unwrap();
- Cow::Owned(
- format!("{}_{}", parent_name, variant_name))
+ Cow::Owned(format!("{}_{}",
+ parent_name,
+ variant_name))
};
add_constant(enum_ty,
@@ -2044,7 +2057,8 @@ impl ToRustTy for Type {
.map(|arg| arg.to_rust_ty(ctx))
.collect::<Vec<_>>();
- path.segments.last_mut().unwrap().parameters = if template_args.is_empty() {
+ path.segments.last_mut().unwrap().parameters = if
+ template_args.is_empty() {
None
} else {
Some(P(ast::PathParameters::AngleBracketed(
@@ -2062,11 +2076,10 @@ impl ToRustTy for Type {
TypeKind::ResolvedTypeRef(inner) => inner.to_rust_ty(ctx),
TypeKind::TemplateAlias(inner, _) |
TypeKind::Alias(inner) => {
- let applicable_named_args =
- item.applicable_template_args(ctx)
- .into_iter()
- .filter(|arg| ctx.resolve_type(*arg).is_named())
- .collect::<Vec<_>>();
+ let applicable_named_args = item.applicable_template_args(ctx)
+ .into_iter()
+ .filter(|arg| ctx.resolve_type(*arg).is_named())
+ .collect::<Vec<_>>();
let spelling = self.name().expect("Unnamed alias?");
if item.is_opaque(ctx) && !applicable_named_args.is_empty() {
@@ -2086,7 +2099,7 @@ impl ToRustTy for Type {
TypeKind::Comp(ref info) => {
let template_args = item.applicable_template_args(ctx);
if info.has_non_type_template_params() ||
- (item.is_opaque(ctx) && !template_args.is_empty()) {
+ (item.is_opaque(ctx) && !template_args.is_empty()) {
return match self.layout(ctx) {
Some(layout) => BlobTyBuilder::new(layout).build(),
None => {
@@ -2127,9 +2140,7 @@ impl ToRustTy for Type {
let ident = ctx.rust_ident(&name);
quote_ty!(ctx.ext_cx(), $ident)
}
- TypeKind::ObjCInterface(..) => {
- quote_ty!(ctx.ext_cx(), id)
- },
+ TypeKind::ObjCInterface(..) => quote_ty!(ctx.ext_cx(), id),
ref u @ TypeKind::UnresolvedTypeRef(..) => {
unreachable!("Should have been resolved after parsing {:?}!", u)
}
@@ -2397,12 +2408,12 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> {
}
mod utils {
+ use super::ItemToRustTy;
use aster;
use ir::context::{BindgenContext, ItemId};
use ir::item::{Item, ItemCanonicalPath};
use ir::ty::TypeKind;
use std::mem;
- use super::ItemToRustTy;
use syntax::ast;
use syntax::ptr::P;
@@ -2412,12 +2423,14 @@ mod utils {
let use_objc = if ctx.options().objc_extern_crate {
quote_item!(ctx.ext_cx(),
use objc;
- ).unwrap()
+ )
+ .unwrap()
} else {
quote_item!(ctx.ext_cx(),
#[macro_use]
extern crate objc;
- ).unwrap()
+ )
+ .unwrap()
};
@@ -2500,13 +2513,12 @@ mod utils {
)
.unwrap();
- let items = vec![
- union_field_decl, union_field_impl,
- union_field_default_impl,
- union_field_clone_impl,
- union_field_copy_impl,
- union_field_debug_impl,
- ];
+ let items = vec![union_field_decl,
+ union_field_impl,
+ union_field_default_impl,
+ union_field_clone_impl,
+ union_field_copy_impl,
+ union_field_debug_impl];
let old_items = mem::replace(result, items);
result.extend(old_items.into_iter());
@@ -2578,13 +2590,11 @@ mod utils {
)
.unwrap();
- let items = vec![
- incomplete_array_decl,
- incomplete_array_impl,
- incomplete_array_debug_impl,
- incomplete_array_clone_impl,
- incomplete_array_copy_impl,
- ];
+ let items = vec![incomplete_array_decl,
+ incomplete_array_impl,
+ incomplete_array_debug_impl,
+ incomplete_array_clone_impl,
+ incomplete_array_copy_impl];
let old_items = mem::replace(result, items);
result.extend(old_items.into_iter());
@@ -2614,8 +2624,7 @@ mod utils {
let path = item.namespace_aware_canonical_path(ctx);
let builder = aster::AstBuilder::new().ty().path();
- let template_args = template_args
- .iter()
+ let template_args = template_args.iter()
.map(|arg| arg.to_rust_ty(ctx))
.collect::<Vec<_>>();
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index bad661da..34bd7a54 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1,8 +1,5 @@
//! Compound types (unions and structs) in our intermediate representation.
-use clang;
-use parse::{ClangItemParser, ParseError};
-use std::cell::Cell;
use super::annotations::Annotations;
use super::context::{BindgenContext, ItemId};
use super::derive::{CanDeriveCopy, CanDeriveDebug};
@@ -10,6 +7,9 @@ use super::item::Item;
use super::layout::Layout;
use super::ty::Type;
use super::type_collector::{ItemSet, TypeCollector};
+use clang;
+use parse::{ClangItemParser, ParseError};
+use std::cell::Cell;
/// The kind of compound type.
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -486,14 +486,13 @@ impl CompInfo {
debug!("CompInfo::from_ty({:?}, {:?})", kind, cursor);
let mut ci = CompInfo::new(kind);
- ci.is_forward_declaration = location.map_or(true, |cur| {
- match cur.kind() {
+ ci.is_forward_declaration =
+ location.map_or(true, |cur| match cur.kind() {
CXCursor_StructDecl |
CXCursor_UnionDecl |
CXCursor_ClassDecl => !cur.is_definition(),
_ => false,
- }
- });
+ });
ci.is_anonymous = cursor.is_anonymous();
ci.template_args = match ty.template_args() {
// In forward declarations and not specializations,
@@ -506,13 +505,12 @@ impl CompInfo {
let mut specialization = true;
let args = arg_types.filter(|t| t.kind() != CXType_Invalid)
- .filter_map(|t| {
- if t.spelling().starts_with("type-parameter") {
- specialization = false;
- None
- } else {
- Some(Item::from_ty_or_ref(t, None, None, ctx))
- }
+ .filter_map(|t| if t.spelling()
+ .starts_with("type-parameter") {
+ specialization = false;
+ None
+ } else {
+ Some(Item::from_ty_or_ref(t, None, None, ctx))
})
.collect::<Vec<_>>();
@@ -681,10 +679,13 @@ impl CompInfo {
// NB: This gets us an owned `Function`, not a
// `FunctionSig`.
- let signature = match Item::parse(cur, Some(potential_id), ctx) {
- Ok(item) if ctx.resolve_item(item).kind().is_function() => item,
- _ => return CXChildVisit_Continue,
- };
+ let signature =
+ match Item::parse(cur, Some(potential_id), ctx) {
+ Ok(item) if ctx.resolve_item(item)
+ .kind()
+ .is_function() => item,
+ _ => return CXChildVisit_Continue,
+ };
match cur.kind() {
CXCursor_Constructor => {
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 50774a43..38ecdf17 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1,5 +1,12 @@
//! Common context that is passed around during parsing and codegen.
+use super::derive::{CanDeriveCopy, CanDeriveDebug};
+use super::int::IntKind;
+use super::item::{Item, ItemCanonicalPath};
+use super::item_kind::ItemKind;
+use super::module::{Module, ModuleKind};
+use super::ty::{FloatKind, Type, TypeKind};
+use super::type_collector::{ItemSet, TypeCollector};
use BindgenOptions;
use cexpr;
use chooser::TypeChooser;
@@ -10,13 +17,6 @@ use std::cell::Cell;
use std::collections::{HashMap, VecDeque, hash_map};
use std::collections::btree_map::{self, BTreeMap};
use std::fmt;
-use super::derive::{CanDeriveCopy, CanDeriveDebug};
-use super::int::IntKind;
-use super::item::{Item, ItemCanonicalPath};
-use super::item_kind::ItemKind;
-use super::module::{Module, ModuleKind};
-use super::ty::{FloatKind, Type, TypeKind};
-use super::type_collector::{ItemSet, TypeCollector};
use syntax::ast::Ident;
use syntax::codemap::{DUMMY_SP, Span};
use syntax::ext::base::ExtCtxt;
@@ -254,8 +254,8 @@ impl<'ctx> BindgenContext<'ctx> {
TypeKey::USR(usr)
} else {
warn!("Valid declaration with no USR: {:?}, {:?}",
- declaration,
- location);
+ declaration,
+ location);
TypeKey::Declaration(declaration)
};
@@ -961,7 +961,8 @@ impl<'ctx> BindgenContext<'ctx> {
fn tokenize_namespace(&self,
cursor: &clang::Cursor)
-> (Option<String>, ModuleKind) {
- assert_eq!(cursor.kind(), ::clang_sys::CXCursor_Namespace,
+ assert_eq!(cursor.kind(),
+ ::clang_sys::CXCursor_Namespace,
"Be a nice person");
let tokens = match self.translation_unit.tokens(&cursor) {
Some(tokens) => tokens,
@@ -995,7 +996,7 @@ impl<'ctx> BindgenContext<'ctx> {
token);
}
}
- };
+ }
(module_name, kind)
}
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs
index ca4e77db..8ea7a8dc 100644
--- a/src/ir/enum_ty.rs
+++ b/src/ir/enum_ty.rs
@@ -1,11 +1,11 @@
//! Intermediate representation for C/C++ enumerations.
-use clang;
-use ir::annotations::Annotations;
-use parse::{ClangItemParser, ParseError};
use super::context::{BindgenContext, ItemId};
use super::item::Item;
use super::ty::TypeKind;
+use clang;
+use ir::annotations::Annotations;
+use parse::{ClangItemParser, ParseError};
/// An enum representing custom handling that can be given to a variant.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -66,18 +66,20 @@ impl Enum {
// Assume signedness since the default type by the C standard is an int.
let is_signed =
repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx))
- .map_or(true, |ty| {
- match *ty.kind() {
- TypeKind::Int(ref int_kind) => int_kind.is_signed(),
- ref other => {
- panic!("Since when enums can be non-integers? {:?}",
+ .map_or(true, |ty| match *ty.kind() {
+ TypeKind::Int(ref int_kind) => int_kind.is_signed(),
+ ref other => {
+ panic!("Since when enums can be non-integers? {:?}",
other)
- }
}
});
let type_name = ty.spelling();
- let type_name = if type_name.is_empty() { None } else { Some(type_name) };
+ let type_name = if type_name.is_empty() {
+ None
+ } else {
+ Some(type_name)
+ };
let type_name = type_name.as_ref().map(String::as_str);
declaration.visit(|cursor| {
@@ -94,20 +96,22 @@ impl Enum {
t.enum_variant_behavior(type_name, &name, val)
})
.or_else(|| {
- Annotations::new(&cursor).and_then(|anno| {
- if anno.hide() {
+ Annotations::new(&cursor)
+ .and_then(|anno| if anno.hide() {
Some(EnumVariantCustomBehavior::Hide)
- } else if anno.constify_enum_variant() {
+ } else if
+ anno.constify_enum_variant() {
Some(EnumVariantCustomBehavior::Constify)
} else {
None
- }
- })
+ })
});
let comment = cursor.raw_comment();
- variants.push(
- EnumVariant::new(name, comment, val, custom_behavior));
+ variants.push(EnumVariant::new(name,
+ comment,
+ val,
+ custom_behavior));
}
}
CXChildVisit_Continue
diff --git a/src/ir/function.rs b/src/ir/function.rs
index a50edfde..cc318679 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -1,12 +1,12 @@
//! Intermediate representation for C/C++ functions and methods.
-use clang;
-use clang_sys::CXCallingConv;
-use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
use super::context::{BindgenContext, ItemId};
use super::item::Item;
use super::ty::TypeKind;
use super::type_collector::{ItemSet, TypeCollector};
+use clang;
+use clang_sys::CXCallingConv;
+use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
use syntax::abi;
/// A function declaration, with a signature, arguments, and argument names.
@@ -165,7 +165,8 @@ impl FunctionSig {
let name = arg.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
- let ty = Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx);
+ let ty =
+ Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx);
(name, ty)
})
.collect()
@@ -176,8 +177,10 @@ impl FunctionSig {
let mut args = vec![];
cursor.visit(|c| {
if c.kind() == CXCursor_ParmDecl {
- let ty =
- Item::from_ty_or_ref(c.cur_type(), Some(c), None, ctx);
+ let ty = Item::from_ty_or_ref(c.cur_type(),
+ Some(c),
+ None,
+ ctx);
let name = c.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
@@ -275,7 +278,8 @@ impl ClangSubItemParser for Function {
}
let linkage = cursor.linkage();
- if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal {
+ if linkage != CXLinkage_External &&
+ linkage != CXLinkage_UniqueExternal {
return Err(ParseError::Continue);
}
diff --git a/src/ir/item.rs b/src/ir/item.rs
index aef35d0b..a5d10e41 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -1,11 +1,5 @@
//! Bindgen's core intermediate representation type.
-use clang;
-use clang_sys;
-use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
-use std::cell::{Cell, RefCell};
-use std::fmt::Write;
-use std::iter;
use super::annotations::Annotations;
use super::context::{BindgenContext, ItemId};
use super::derive::{CanDeriveCopy, CanDeriveDebug};
@@ -14,6 +8,12 @@ use super::item_kind::ItemKind;
use super::module::Module;
use super::ty::{Type, TypeKind};
use super::type_collector::{ItemSet, TypeCollector};
+use clang;
+use clang_sys;
+use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
+use std::cell::{Cell, RefCell};
+use std::fmt::Write;
+use std::iter;
/// A trait to get the canonical name from an item.
///
@@ -193,7 +193,8 @@ impl TypeCollector for Item {
// There are some types, like resolved type references, where we
// don't want to stop collecting types even though they may be
// opaque.
- if ty.should_be_traced_unconditionally() || !self.is_opaque(ctx) {
+ if ty.should_be_traced_unconditionally() ||
+ !self.is_opaque(ctx) {
ty.collect_types(ctx, types, self);
}
}
@@ -219,7 +220,8 @@ impl CanDeriveDebug for Item {
type Extra = ();
fn can_derive_debug(&self, ctx: &BindgenContext, _: ()) -> bool {
- ctx.options().derive_debug && match self.kind {
+ ctx.options().derive_debug &&
+ match self.kind {
ItemKind::Type(ref ty) => {
if self.is_opaque(ctx) {
ty.layout(ctx)
@@ -255,7 +257,9 @@ impl<'a> CanDeriveCopy<'a> for Item {
ItemKind::Type(ref ty) => {
if self.is_opaque(ctx) {
ty.layout(ctx)
- .map_or(true, |l| l.opaque().can_derive_copy_in_array(ctx, ()))
+ .map_or(true, |l| {
+ l.opaque().can_derive_copy_in_array(ctx, ())
+ })
} else {
ty.can_derive_copy_in_array(ctx, self)
}
@@ -759,9 +763,7 @@ impl Item {
}
ItemKind::Type(ref ty) => {
let name = match *ty.kind() {
- TypeKind::ResolvedTypeRef(..) => {
- panic!("should have resolved this in name_target()")
- }
+ TypeKind::ResolvedTypeRef(..) => panic!("should have resolved this in name_target()"),
_ => ty.name(),
};
name.map(ToOwned::to_owned)
@@ -1136,7 +1138,7 @@ impl ClangItemParser for Item {
}
if let Some(ty) =
- ctx.builtin_or_resolved_ty(id, parent_id, ty, location) {
+ ctx.builtin_or_resolved_ty(id, parent_id, ty, location) {
return Ok(ty);
}
@@ -1154,9 +1156,10 @@ impl ClangItemParser for Item {
};
if valid_decl {
- if let Some(&(_, item_id)) = ctx.currently_parsed_types
- .iter()
- .find(|&&(d, _)| d == declaration_to_look_for) {
+ if let Some(&(_, item_id)) =
+ ctx.currently_parsed_types
+ .iter()
+ .find(|&&(d, _)| d == declaration_to_look_for) {
debug!("Avoiding recursion parsing type: {:?}", ty);
return Ok(item_id);
}
@@ -1325,7 +1328,7 @@ impl ItemCanonicalPath for Item {
item.id() == target.id() ||
item.as_module().map_or(false, |module| {
!module.is_inline() ||
- ctx.options().conservative_inline_namespaces
+ ctx.options().conservative_inline_namespaces
})
})
.map(|item| {
diff --git a/src/ir/layout.rs b/src/ir/layout.rs
index 033fff62..e8c6c32b 100644
--- a/src/ir/layout.rs
+++ b/src/ir/layout.rs
@@ -1,9 +1,9 @@
//! Intermediate representation for the physical layout of some type.
-use std::cmp;
use super::context::BindgenContext;
use super::derive::{CanDeriveCopy, CanDeriveDebug};
use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
+use std::cmp;
/// A type that represents the struct layout of a type.
#[derive(Debug, Clone, Copy)]
@@ -74,7 +74,8 @@ impl CanDeriveDebug for Opaque {
type Extra = ();
fn can_derive_debug(&self, _: &BindgenContext, _: ()) -> bool {
- self.array_size().map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
+ self.array_size()
+ .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
}
}
@@ -82,7 +83,8 @@ impl<'a> CanDeriveCopy<'a> for Opaque {
type Extra = ();
fn can_derive_copy(&self, _: &BindgenContext, _: ()) -> bool {
- self.array_size().map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
+ self.array_size()
+ .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
}
fn can_derive_copy_in_array(&self, ctx: &BindgenContext, _: ()) -> bool {
diff --git a/src/ir/module.rs b/src/ir/module.rs
index 002fe36e..6b6c535b 100644
--- a/src/ir/module.rs
+++ b/src/ir/module.rs
@@ -1,9 +1,9 @@
//! Intermediate representation for modules (AKA C++ namespaces).
+use super::context::{BindgenContext, ItemId};
use clang;
use parse::{ClangSubItemParser, ParseError, ParseResult};
use parse_one;
-use super::context::{BindgenContext, ItemId};
/// Whether this module is inline or not.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
diff --git a/src/ir/objc.rs b/src/ir/objc.rs
index b9fe280b..92356d92 100644
--- a/src/ir/objc.rs
+++ b/src/ir/objc.rs
@@ -1,10 +1,10 @@
//! Objective C types
+// use clang_sys::CXCursor_ObjCSuperClassRef;
+use super::context::BindgenContext;
use clang;
use clang_sys::CXChildVisit_Continue;
use clang_sys::CXCursor_ObjCInstanceMethodDecl;
-// use clang_sys::CXCursor_ObjCSuperClassRef;
-use super::context::BindgenContext;
/// Objective C interface as used in TypeKind
///
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 1246057b..3a9d5082 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1,7 +1,5 @@
//! Everything related to types in our intermediate representation.
-use clang::{self, Cursor};
-use parse::{ClangItemParser, ParseError, ParseResult};
use super::comp::CompInfo;
use super::context::{BindgenContext, ItemId};
use super::derive::{CanDeriveCopy, CanDeriveDebug};
@@ -12,6 +10,8 @@ use super::item::Item;
use super::layout::Layout;
use super::objc::ObjCInterface;
use super::type_collector::{ItemSet, TypeCollector};
+use clang::{self, Cursor};
+use parse::{ClangItemParser, ParseError, ParseResult};
/// The base representation of a type in bindgen.
///
diff --git a/src/ir/type_collector.rs b/src/ir/type_collector.rs
index 0f10152d..25285b23 100644
--- a/src/ir/type_collector.rs
+++ b/src/ir/type_collector.rs
@@ -1,7 +1,7 @@
//! Collecting type items.
-use std::collections::BTreeSet;
use super::context::{BindgenContext, ItemId};
+use std::collections::BTreeSet;
/// A set of items.
pub type ItemSet = BTreeSet<ItemId>;
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 329393fa..6cfcdae7 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -1,14 +1,14 @@
//! Intermediate representation of variables.
-use cexpr;
-use clang;
-use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
-use std::num::Wrapping;
use super::context::{BindgenContext, ItemId};
use super::function::cursor_mangling;
use super::int::IntKind;
use super::item::Item;
use super::ty::{FloatKind, TypeKind};
+use cexpr;
+use clang;
+use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
+use std::num::Wrapping;
/// The type for a constant variable.
#[derive(Debug)]
@@ -149,18 +149,18 @@ impl ClangSubItemParser for Var {
EvalResult::Int(Wrapping(value)) => {
let kind = ctx.type_chooser()
.and_then(|c| c.int_macro(&name, value))
- .unwrap_or_else(|| {
- if value < 0 {
- if value < i32::min_value() as i64 {
- IntKind::LongLong
- } else {
- IntKind::Int
- }
- } else if value > u32::max_value() as i64 {
- IntKind::ULongLong
+ .unwrap_or_else(|| if value < 0 {
+ if value < i32::min_value() as i64 {
+ IntKind::LongLong
} else {
- IntKind::UInt
+ IntKind::Int
}
+ } else if value >
+ u32::max_value() as
+ i64 {
+ IntKind::ULongLong
+ } else {
+ IntKind::UInt
});
(TypeKind::Int(kind), VarType::Int(value))
@@ -187,7 +187,8 @@ impl ClangSubItemParser for Var {
let ty = match Item::from_ty(&ty, Some(cursor), None, ctx) {
Ok(ty) => ty,
Err(e) => {
- assert_eq!(ty.kind(), CXType_Auto,
+ assert_eq!(ty.kind(),
+ CXType_Auto,
"Couldn't resolve constant type, and it \
wasn't an nondeductible auto type!");
return Err(e);
@@ -222,12 +223,10 @@ impl ClangSubItemParser for Var {
val = get_integer_literal_from_cursor(&cursor, tu);
}
- val.map(|val| {
- if kind == IntKind::Bool {
- VarType::Bool(val != 0)
- } else {
- VarType::Int(val)
- }
+ val.map(|val| if kind == IntKind::Bool {
+ VarType::Bool(val != 0)
+ } else {
+ VarType::Int(val)
})
} else if is_float {
cursor.evaluate()
diff --git a/src/lib.rs b/src/lib.rs
index d6f3c66e..84a2ee67 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -525,7 +525,6 @@ pub struct BindgenOptions {
/// The input header file.
pub input_header: Option<String>,
-
/// Generate a dummy C/C++ file that includes the header and has dummy uses
/// of all types defined therein. See the `uses` module for more.
pub dummy_uses: Option<String>,
@@ -754,16 +753,16 @@ impl<'ctx> Bindings<'ctx> {
///
/// See the `uses` module for more information.
pub fn write_dummy_uses(&mut self) -> io::Result<()> {
- let file =
- if let Some(ref dummy_path) = self.context.options().dummy_uses {
- Some(try!(OpenOptions::new()
+ let file = if let Some(ref dummy_path) =
+ self.context.options().dummy_uses {
+ Some(try!(OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(dummy_path)))
- } else {
- None
- };
+ } else {
+ None
+ };
if let Some(file) = file {
try!(uses::generate_dummy_uses(&mut self.context, file));
diff --git a/src/main.rs b/src/main.rs
index a7bd9618..9b037ef8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -35,9 +35,7 @@ pub fn main() {
match version.parsed {
None => warn!("Couldn't parse libclang version"),
Some(version) if version != expected_version => {
- warn!("Using clang {:?}, expected {:?}",
- version,
- expected_version);
+ warn!("Using clang {:?}, expected {:?}", version, expected_version);
}
_ => {}
}
diff --git a/src/options.rs b/src/options.rs
index 535eac4b..8d11be2d 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,5 +1,5 @@
-use clap::{App, Arg};
use bindgen::{Builder, CodegenConfig, builder};
+use clap::{App, Arg};
use std::fs::File;
use std::io::{self, Error, ErrorKind};
diff --git a/src/regex_set.rs b/src/regex_set.rs
index dbdb6565..2eff740b 100644
--- a/src/regex_set.rs
+++ b/src/regex_set.rs
@@ -21,7 +21,7 @@ impl RegexSet {
/// Extend this set with every regex in the iterator.
pub fn extend<I, S>(&mut self, iter: I)
where I: IntoIterator<Item = S>,
- S: AsRef<str>
+ S: AsRef<str>,
{
for s in iter.into_iter() {
self.insert(s)
@@ -30,7 +30,7 @@ impl RegexSet {
/// Insert a new regex into this set.
pub fn insert<S>(&mut self, string: S)
- where S: AsRef<str>
+ where S: AsRef<str>,
{
self.items.push(format!("^{}$", string.as_ref()));
self.set = None;
@@ -46,13 +46,13 @@ impl RegexSet {
Err(e) => {
error!("Invalid regex in {:?}: {:?}", self.items, e);
None
- },
+ }
}
}
/// Does the given `string` match any of the regexes in this set?
pub fn matches<S>(&self, string: S) -> bool
- where S: AsRef<str>
+ where S: AsRef<str>,
{
let s = string.as_ref();
self.set.as_ref().map(|set| set.is_match(s)).unwrap_or(false)
diff --git a/tests/tests.rs b/tests/tests.rs
index 2886f8db..5b0ccd11 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -68,8 +68,7 @@ fn compare_generated_header(header: &PathBuf,
Err(Error::new(ErrorKind::Other, "Header and binding differ!"))
}
-fn create_bindgen_builder(header: &PathBuf)
- -> Result<Option<Builder>, Error> {
+fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {
let source = try!(fs::File::open(header));
let reader = BufReader::new(source);