Skip to content

Commit 612d2ee

Browse files
committed
Multiple cleanups.
1 parent 90a68cd commit 612d2ee

File tree

10 files changed

+42
-166
lines changed

10 files changed

+42
-166
lines changed

src/bin/bindgen.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,12 @@ extern crate env_logger;
77
extern crate log;
88
extern crate clang_sys;
99

10-
use bindgen::{Bindings, BindgenOptions, LinkType, Logger};
10+
use bindgen::{Bindings, BindgenOptions, LinkType};
1111
use std::io;
1212
use std::path;
1313
use std::env;
1414
use std::default::Default;
1515
use std::fs;
16-
use std::process::exit;
17-
18-
struct StdLogger;
19-
20-
impl Logger for StdLogger {
21-
fn error(&self, msg: &str) {
22-
println!("{}", msg);
23-
}
24-
25-
fn warn(&self, msg: &str) {
26-
println!("{}", msg);
27-
}
28-
}
2916

3017
enum ParseResult {
3118
CmdUsage,
@@ -255,17 +242,10 @@ pub fn main() {
255242
ParseResult::ParseErr(e) => panic!(e),
256243
ParseResult::CmdUsage => print_usage(bin),
257244
ParseResult::ParseOk(options, out) => {
258-
let logger = StdLogger;
259-
match Bindings::generate(&options, Some(&logger as &Logger), None) {
260-
Ok(bindings) => match bindings.write(out) {
261-
Ok(()) => (),
262-
Err(e) => {
263-
logger.error(&format!("Unable to write bindings to file. {}", e));
264-
exit(-1);
265-
}
266-
},
267-
Err(()) => exit(-1)
268-
}
245+
let bindings = Bindings::generate(&options, None)
246+
.expect("Failed to generate bindings!");
247+
248+
bindings.write(out).expect("Unable to write bindings!");
269249
}
270250
}
271251
}

src/codegen/mod.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,8 @@ use std::collections::hash_map::{HashMap, Entry};
1414

1515
use syntax::abi::Abi;
1616
use syntax::ast;
17-
use syntax::codemap::{Span, respan, ExpnInfo, NameAndSpan, MacroBang};
18-
use syntax::ext::base;
19-
use syntax::ext::build::AstBuilder;
20-
use syntax::ext::expand::ExpansionConfig;
21-
use syntax::ext::quote::rt::ToTokens;
22-
use syntax::feature_gate::Features;
23-
use syntax::parse;
24-
use syntax::parse::token::{InternedString, intern};
25-
use syntax::attr::mk_attr_id;
17+
use syntax::codemap::{Span, respan};
2618
use syntax::ptr::P;
27-
use syntax::print::pprust::tts_to_string;
2819
use aster;
2920

3021
macro_rules! repr {
@@ -96,6 +87,7 @@ impl ForeignModBuilder {
9687
self
9788
}
9889

90+
#[allow(dead_code)]
9991
fn with_foreign_items<I>(mut self, items: I) -> Self
10092
where I: IntoIterator<Item=ast::ForeignItem>
10193
{
@@ -252,7 +244,7 @@ impl ItemCanonicalName for Item {
252244
ItemKind::Var(ref var) => {
253245
var.name().to_owned()
254246
}
255-
ItemKind::Module(ref module) => unimplemented!(), // TODO
247+
ItemKind::Module(ref _module) => unimplemented!(), // TODO
256248
};
257249

258250
if self.is_toplevel(ctx) {
@@ -311,7 +303,6 @@ impl CodeGenerator for Var {
311303
let ty = self.ty().to_rust_ty(ctx);
312304

313305
if let Some(val) = self.val() {
314-
let val = self.val().unwrap();
315306
let const_item = aster::AstBuilder::new().item().pub_().const_(name)
316307
.expr().int(val).build(ty);
317308
result.push(const_item)
@@ -429,7 +420,7 @@ impl<'a> CodeGenerator for Vtable<'a> {
429420
}
430421

431422
impl<'a> ItemCanonicalName for Vtable<'a> {
432-
fn canonical_name(&self, ctx: &BindgenContext) -> String {
423+
fn canonical_name(&self, _ctx: &BindgenContext) -> String {
433424
format!("bindgen_vtable_{}", self.item_id)
434425
}
435426
}
@@ -455,10 +446,8 @@ impl CodeGenerator for CompInfo {
455446
attributes.push(repr!("C"));
456447

457448
let mut template_args_used = vec![false; self.template_args().len()];
458-
let is_union = self.kind() == CompKind::Union;
459-
460449
let canonical_name = item.canonical_name(ctx);
461-
let mut builder = aster::AstBuilder::new().item().pub_()
450+
let builder = aster::AstBuilder::new().item().pub_()
462451
.with_attrs(attributes)
463452
.struct_(&canonical_name);
464453

@@ -796,7 +785,6 @@ impl ToRustTy for Type {
796785
}
797786

798787
let name = item.canonical_name(ctx);
799-
let ident = ctx.rust_ident(&name);
800788
aster::AstBuilder::new().ty().path()
801789
.segment(&name)
802790
.with_tys(info.template_args().iter().map(|arg| {
@@ -819,7 +807,7 @@ impl ToRustTy for Type {
819807
impl ToRustTy for FunctionSig {
820808
type Extra = Item;
821809

822-
fn to_rust_ty(&self, ctx: &BindgenContext, item: &Item) -> P<ast::Ty> {
810+
fn to_rust_ty(&self, ctx: &BindgenContext, _item: &Item) -> P<ast::Ty> {
823811
// TODO: we might want to consider ignoring the reference return value.
824812
let return_item = ctx.resolve_item(self.return_type());
825813
let ret = if let TypeKind::Void = *return_item.kind().expect_type().kind() {
@@ -944,7 +932,7 @@ impl CodeGenerator for Function {
944932
pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> {
945933
context.gen(|context| {
946934
let mut result = CodegenResult::new();
947-
for (item_id, item) in context.items() {
935+
for (_item_id, item) in context.items() {
948936
// Non-toplevel item parents are the responsible one for generating
949937
// them.
950938
if item.is_toplevel(context) {
@@ -967,7 +955,6 @@ mod utils {
967955
use std::mem;
968956

969957
pub fn prepend_union_types(ctx: &BindgenContext, result: &mut Vec<P<ast::Item>>) {
970-
use std::mem;
971958
let union_field_decl = quote_item!(ctx.ext_cx(),
972959
#[derive(Copy, Debug)]
973960
#[repr(C)]

src/gen.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ pub fn gen_mods(links: &[(String, LinkType)],
297297
options: BindgenOptions,
298298
span: Span) -> Vec<P<ast::Item>> {
299299
// Create a dummy ExtCtxt. We only need this for string interning and that uses TLS.
300-
let mut features = Features::new();
301-
features.quote = true;
302-
303300
let cfg = ExpansionConfig::default("xxx".to_owned());
304301
let sess = parse::ParseSess::new();
305302
let mut loader = base::DummyMacroLoader;

src/ir/comp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use super::layout::Layout;
55
use super::item::{Item, ItemId};
66
use super::ty::Type;
77
use std::cell::Cell;
8-
use parse::{ClangItemParser, ClangSubItemParser, ParseError};
8+
use parse::{ClangItemParser, ParseError};
99
use clang;
10-
use clangll::Enum_CXCursorKind;
1110

1211
#[derive(Debug, Copy, Clone, PartialEq)]
1312
pub enum CompKind {
@@ -61,6 +60,8 @@ pub struct Field {
6160
ty: ItemId,
6261
/// The doc comment on the field if any.
6362
comment: Option<String>,
63+
/// Annotations for this field, or the default.
64+
annotations: Annotations,
6465
/// If this field is a bitfield, and how many bits does it contain if it is.
6566
bitfield: Option<u32>,
6667
/// If the C++ field is marked as `mutable`
@@ -78,6 +79,7 @@ impl Field {
7879
name: name,
7980
ty: ty,
8081
comment: comment,
82+
annotations: annotations.unwrap_or_default(),
8183
bitfield: bitfield,
8284
mutable: mutable,
8385
}

src/ir/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::borrow::{Cow, Borrow};
88
use std::collections::btree_map::{self, BTreeMap};
99
use std::collections::{HashSet, HashMap};
1010
use std::fmt;
11-
use syntax;
1211
use syntax::ast::Ident;
1312
use syntax::codemap::{DUMMY_SP, Span};
1413
use syntax::ext::base::ExtCtxt;
@@ -189,10 +188,9 @@ impl<'ctx> BindgenContext<'ctx> {
189188
pub fn gen<F, Out>(&mut self, cb: F) -> Out
190189
where F: FnOnce(&Self) -> Out
191190
{
192-
use syntax::codemap::{Span, respan, ExpnInfo, NameAndSpan, MacroBang};
193191
use syntax::ext::expand::ExpansionConfig;
192+
use syntax::codemap::{ExpnInfo, MacroBang, NameAndSpan};
194193
use syntax::ext::base;
195-
use syntax::ext;
196194
use syntax::parse;
197195
use std::mem;
198196

@@ -236,7 +234,7 @@ impl<'ctx> BindgenContext<'ctx> {
236234
}
237235

238236
fn build_root_module() -> Item {
239-
let module = Module::new(None, None);
237+
let module = Module::new(None);
240238
let id = ItemId::next();
241239
Item::new(id, None, None, id, ItemKind::Module(module))
242240
}

src/ir/enum_ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::int::IntKind;
21
use super::item::{Item, ItemId};
32
use super::ty::TypeKind;
43
use super::context::BindgenContext;

src/ir/item.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ impl ClangItemParser for Item {
110110
context: &mut BindgenContext) -> Result<ItemId, ParseError> {
111111
use ir::function::Function;
112112
use ir::module::Module;
113-
use ir::ty::Type;
114113
use ir::var::Var;
115-
use clangll::CXCursor_Namespace;
116114

117115
if !cursor.is_valid() {
118116
return Err(ParseError::Continue);
@@ -234,7 +232,7 @@ impl ClangItemParser for Item {
234232
context.currently_parsed_types.push((declaration_to_look_for, id));
235233
}
236234

237-
let mut result = Type::from_clang_ty(id, ty, location, parent_id, context);
235+
let result = Type::from_clang_ty(id, ty, location, parent_id, context);
238236
let ret = match result {
239237
Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty),
240238
Ok(ParseResult::New(item, declaration)) => {
@@ -260,7 +258,7 @@ impl ClangItemParser for Item {
260258
assert_eq!(popped_decl, declaration_to_look_for);
261259
}
262260

263-
location.visit(|cur, other| {
261+
location.visit(|cur, _other| {
264262
use clangll::*;
265263
result = Item::from_ty(ty, Some(*cur), parent_id, context);
266264
match result {

src/ir/module.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,25 @@ pub struct Module {
99
/// The name of the module, or none if it's the root or an anonymous
1010
/// namespace.
1111
name: Option<String>,
12-
/// The parent module of this.
13-
parent_id: Option<ItemId>,
1412
/// The children of this module, just here for convenience.
1513
children_ids: Vec<ItemId>,
1614
}
1715

1816
impl Module {
19-
pub fn new(name: Option<String>, parent_id: Option<ItemId>) -> Self {
17+
pub fn new(name: Option<String>) -> Self {
2018
Module {
2119
name: name,
22-
parent_id: None,
2320
children_ids: vec![],
2421
}
2522
}
2623

2724
pub fn name(&self) -> Option<&str> {
2825
self.name.as_ref().map(|s| &**s)
2926
}
30-
31-
pub fn parent(&self) -> Option<ItemId> {
32-
self.parent_id
33-
}
3427
}
3528

3629
impl ClangSubItemParser for Module {
37-
fn parse(cursor: clang::Cursor, ctx: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError> {
30+
fn parse(cursor: clang::Cursor, _ctx: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError> {
3831
use clangll::*;
3932
match cursor.kind() {
4033
CXCursor_Namespace => {

src/ir/ty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::int::IntKind;
66
use super::layout::Layout;
77
use super::context::BindgenContext;
88
use super::context::TypeResolver;
9-
use parse::{ClangItemParser, ClangSubItemParser, ParseResult, ParseError};
9+
use parse::{ClangItemParser, ParseResult, ParseError};
1010
use clang::{self, Cursor};
1111

1212
#[derive(Debug)]
@@ -263,7 +263,6 @@ impl Type {
263263
}
264264

265265
let layout = ty.fallible_layout().ok();
266-
let is_const = ty.is_const();
267266
let cursor = ty.declaration();
268267
let mut name = cursor.spelling();
269268

@@ -361,7 +360,7 @@ impl Type {
361360
TypeKind::Function(signature)
362361
}
363362
CXType_Typedef => {
364-
let mut inner = cursor.typedef_type();
363+
let inner = cursor.typedef_type();
365364
let inner = Item::from_ty(&inner, location, parent_id, ctx)
366365
.expect("Not able to resolve array element?");
367366
TypeKind::Alias(ty.spelling(), inner)
@@ -383,7 +382,8 @@ impl Type {
383382
}
384383
#[cfg(not(feature="llvm_stable"))]
385384
CXType_Elaborated => {
386-
return Self::from_clang_ty(potential_id, &ty.named(), ctx);
385+
return Self::from_clang_ty(potential_id, &ty.named(),
386+
location, parent_id, ctx);
387387
}
388388
_ => {
389389
warn!("unsupported type {:?}", ty);

0 commit comments

Comments
 (0)