Skip to content

Don't assume that base classes are already resolved. #360

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

Merged
merged 5 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion libbindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cexpr = "0.2"
cfg-if = "0.1.0"
clang-sys = { version = "0.12", features = ["runtime", "clang_3_9"] }
lazy_static = "0.2.1"
libc = "0.2"
rustc-serialize = "0.3.19"
syntex_syntax = "0.50"
regex = "0.1"
Expand Down
9 changes: 1 addition & 8 deletions libbindgen/src/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,7 @@ impl CompInfo {
return CXChildVisit_Continue;
}

let default_type = Item::from_ty(&cur.cur_type(),
Some(cur),
Some(potential_id),
ctx)
.ok();
let param = Item::named_type(cur.spelling(),
default_type,
potential_id,
ctx);
ci.template_args.push(param);
Expand All @@ -660,8 +654,7 @@ impl CompInfo {
ci.has_vtable = cur.is_virtual_base();
}
let type_id =
Item::from_ty(&cur.cur_type(), Some(cur), None, ctx)
.expect("BaseSpecifier");
Item::from_ty_or_ref(cur.cur_type(), Some(cur), None, ctx);
ci.base_members.push(type_id);
}
CXCursor_Constructor |
Expand Down
11 changes: 4 additions & 7 deletions libbindgen/src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ impl Item {
parent_template_args.iter().any(|parent_item| {
let parent_ty = ctx.resolve_type(*parent_item);
match (parent_ty.kind(), item_ty.kind()) {
(&TypeKind::Named(ref n, _),
&TypeKind::Named(ref i, _)) => n == i,
(&TypeKind::Named(ref n),
&TypeKind::Named(ref i)) => n == i,
_ => false,
}
})
Expand Down Expand Up @@ -1163,7 +1163,6 @@ impl ClangItemParser for Item {
ty.spelling());
Ok(Self::named_type_with_id(id,
ty.spelling(),
None,
relevant_parent_id,
ctx))
} else {
Expand All @@ -1189,7 +1188,6 @@ impl ClangItemParser for Item {
/// available yet.
fn named_type_with_id<S>(id: ItemId,
name: S,
default: Option<ItemId>,
parent_id: ItemId,
ctx: &mut BindgenContext)
-> ItemId
Expand All @@ -1203,22 +1201,21 @@ impl ClangItemParser for Item {
None,
None,
parent_id,
ItemKind::Type(Type::named(name, default))),
ItemKind::Type(Type::named(name))),
None,
None);

id
}

fn named_type<S>(name: S,
default: Option<ItemId>,
parent_id: ItemId,
ctx: &mut BindgenContext)
-> ItemId
where S: Into<String>,
{
let id = ctx.next_item_id();
Self::named_type_with_id(id, name, default, parent_id, ctx)
Self::named_type_with_id(id, name, parent_id, ctx)
}
}

Expand Down
22 changes: 7 additions & 15 deletions libbindgen/src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ impl Type {
}

/// Creates a new named type, with name `name`.
pub fn named(name: String, default: Option<ItemId>) -> Self {
pub fn named(name: String) -> Self {
assert!(!name.is_empty());
// TODO: stop duplicating the name, it's stupid.
let kind = TypeKind::Named(name.clone(), default);
let kind = TypeKind::Named(name.clone());
Self::new(Some(name), None, kind, false)
}

Expand Down Expand Up @@ -318,12 +318,12 @@ impl Type {
ty: &Type)
-> bool {
let name = match *ty.kind() {
TypeKind::Named(ref name, _) => name,
TypeKind::Named(ref name) => name,
ref other @ _ => unreachable!("Not a named type: {:?}", other),
};

match self.kind {
TypeKind::Named(ref this_name, _) => this_name == name,
TypeKind::Named(ref this_name) => this_name == name,
TypeKind::ResolvedTypeRef(t) |
TypeKind::Array(t, _) |
TypeKind::Pointer(t) |
Expand Down Expand Up @@ -478,9 +478,8 @@ pub enum TypeKind {
/// replace one type with another.
ResolvedTypeRef(ItemId),

/// A named type, that is, a template parameter, with an optional default
/// type.
Named(String, Option<ItemId>),
/// A named type, that is, a template parameter.
Named(String),
}

impl Type {
Expand Down Expand Up @@ -675,15 +674,8 @@ impl Type {
return CXChildVisit_Continue;
}

let default_type =
Item::from_ty(&cur.cur_type(),
Some(cur),
Some(potential_id),
ctx)
.ok();
let param =
Item::named_type(cur.spelling(),
default_type,
potential_id,
ctx);
args.push(param);
Expand Down Expand Up @@ -903,7 +895,6 @@ impl TypeCollector for Type {
TypeKind::Reference(inner) |
TypeKind::Array(inner, _) |
TypeKind::Alias(_, inner) |
TypeKind::Named(_, Some(inner)) |
TypeKind::ResolvedTypeRef(inner) => {
types.insert(inner);
}
Expand All @@ -919,6 +910,7 @@ impl TypeCollector for Type {
TypeKind::Function(ref sig) => {
sig.collect_types(context, types, item)
}
TypeKind::Named(_) => {},
// FIXME: Pending types!
ref other @ _ => {
debug!("<Type as TypeCollector>::collect_types: Ignoring: \
Expand Down
3 changes: 2 additions & 1 deletion libbindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#![deny(missing_docs)]
#![deny(warnings)]
#![deny(unused_extern_crates)]

// We internally use the deprecated BindgenOptions all over the place. Once we
// remove its `pub` declaration, we can un-deprecate it and remove this pragma.
Expand All @@ -17,13 +18,13 @@
#![allow(non_upper_case_globals)]

#[macro_use]
#[allow(unused_extern_crates)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still warns here despite #[macro_use] and our macro usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a known false positive from that lint.

extern crate cfg_if;
extern crate cexpr;
extern crate syntex_syntax as syntax;
extern crate aster;
extern crate quasi;
extern crate clang_sys;
extern crate libc;
extern crate regex;
#[macro_use]
extern crate lazy_static;
Expand Down
2 changes: 0 additions & 2 deletions libbindgen/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub trait ClangItemParser: Sized {

/// Create a named template type.
fn named_type<S>(name: S,
default: Option<ItemId>,
parent: ItemId,
context: &mut BindgenContext)
-> ItemId
Expand All @@ -92,7 +91,6 @@ pub trait ClangItemParser: Sized {
/// `ItemId`.
fn named_type_with_id<S>(id: ItemId,
name: S,
default: Option<ItemId>,
parent: ItemId,
context: &mut BindgenContext)
-> ItemId
Expand Down
14 changes: 7 additions & 7 deletions libbindgen/tests/expectations/tests/anon_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ pub struct TErrorResult__bindgen_ty_1<T> {
pub bindgen_union_field: u64,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() ,
24usize);
assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() ,
8usize);
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ErrorResult {
Expand All @@ -82,3 +75,10 @@ fn bindgen_test_layout_ErrorResult() {
impl Clone for ErrorResult {
fn clone(&self) -> Self { *self }
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() ,
24usize);
assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() ,
8usize);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_char_traits<_CharT> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct __gnu_cxx_char_traits {
pub _address: u8,
}
impl Clone for __gnu_cxx_char_traits {
fn clone(&self) -> Self { *self }
}
24 changes: 12 additions & 12 deletions libbindgen/tests/expectations/tests/crtp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ pub struct Base<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize);
assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize);
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Derived {
Expand All @@ -34,13 +29,6 @@ pub struct BaseWithDestructor<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
fn __bindgen_test_layout_template_2() {
assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
, 1usize);
assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
, 1usize);
}
#[repr(C)]
#[derive(Debug)]
pub struct DerivedFromBaseWithDestructor {
Expand All @@ -53,3 +41,15 @@ fn bindgen_test_layout_DerivedFromBaseWithDestructor() {
assert_eq!(::std::mem::align_of::<DerivedFromBaseWithDestructor>() ,
1usize);
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize);
assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize);
}
#[test]
fn __bindgen_test_layout_template_2() {
assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
, 1usize);
assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
, 1usize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RootedBase<T> {
pub foo: *mut T,
pub next: *mut Rooted<T>,
pub struct Rooted<T> {
pub _base: js_RootedBase<T>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rooted<T> {
pub _base: RootedBase<T>,
pub struct js_RootedBase<T> {
pub foo: *mut T,
pub next: *mut Rooted<T>,
}
4 changes: 2 additions & 2 deletions libbindgen/tests/expectations/tests/forward-inherit-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RootedBase<T> {
pub struct Rooted<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rooted<T> {
pub struct js_RootedBase<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
26 changes: 13 additions & 13 deletions libbindgen/tests/expectations/tests/vtable_recursive_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
#![allow(non_snake_case)]


#[repr(C)]
#[derive(Debug, Copy)]
pub struct Derived {
pub _base: Base,
}
#[test]
fn bindgen_test_layout_Derived() {
assert_eq!(::std::mem::size_of::<Derived>() , 8usize);
assert_eq!(::std::mem::align_of::<Derived>() , 8usize);
}
impl Clone for Derived {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
pub struct Base__bindgen_vtable {
}
Expand All @@ -20,16 +33,3 @@ fn bindgen_test_layout_Base() {
impl Clone for Base {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Derived {
pub _base: Base,
}
#[test]
fn bindgen_test_layout_Derived() {
assert_eq!(::std::mem::size_of::<Derived>() , 8usize);
assert_eq!(::std::mem::align_of::<Derived>() , 8usize);
}
impl Clone for Derived {
fn clone(&self) -> Self { *self }
}
15 changes: 15 additions & 0 deletions libbindgen/tests/headers/bad-namespace-parenthood-inheritance.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace std
{
template < typename > struct char_traits;
}
namespace __gnu_cxx
{
template < typename > struct char_traits;
}
namespace std
{
template < class _CharT > struct char_traits:__gnu_cxx::char_traits <
_CharT >
{
};
}