summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-12-23 09:51:23 -0800
committerGitHub <noreply@github.com>2016-12-23 09:51:23 -0800
commit3ba3a76f8c7f393c81bc14eb497ae2b3047ead98 (patch)
treee08ab5ab12af804ac33a11cf6947f719a13d67e7
parentcbc03042403029d3709290304b8804fec1d21bb9 (diff)
parentb93faf9015e91303a9cfb14281c1ebe5ca877acd (diff)
Auto merge of #360 - emilio:base, r=fitzgen
Don't assume that base classes are already resolved. Since it may not be the case. Fixes #359 Also fixes a few other test cases in the codebase that had the wrong namespace relationship. r? @fitzgen
-rw-r--r--libbindgen/Cargo.toml3
-rw-r--r--libbindgen/src/ir/comp.rs9
-rw-r--r--libbindgen/src/ir/item.rs11
-rw-r--r--libbindgen/src/ir/ty.rs22
-rw-r--r--libbindgen/src/lib.rs3
-rw-r--r--libbindgen/src/parse.rs2
-rw-r--r--libbindgen/tests/expectations/tests/anon_union.rs14
-rw-r--r--libbindgen/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs20
-rw-r--r--libbindgen/tests/expectations/tests/crtp.rs24
-rw-r--r--libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs10
-rw-r--r--libbindgen/tests/expectations/tests/forward-inherit-struct.rs4
-rw-r--r--libbindgen/tests/expectations/tests/issue-358.rs20
-rw-r--r--libbindgen/tests/expectations/tests/vtable_recursive_sig.rs26
-rw-r--r--libbindgen/tests/headers/bad-namespace-parenthood-inheritance.hpp15
-rw-r--r--libbindgen/tests/headers/issue-358.hpp8
15 files changed, 117 insertions, 74 deletions
diff --git a/libbindgen/Cargo.toml b/libbindgen/Cargo.toml
index 408d9fc1..e6e9a5db 100644
--- a/libbindgen/Cargo.toml
+++ b/libbindgen/Cargo.toml
@@ -12,7 +12,7 @@ license = "BSD-3-Clause"
name = "libbindgen"
readme = "README.md"
repository = "https://github.com/servo/rust-bindgen"
-version = "0.1.3"
+version = "0.1.4"
workspace = ".."
[dev-dependencies]
@@ -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"
diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs
index d5d34262..1c69e618 100644
--- a/libbindgen/src/ir/comp.rs
+++ b/libbindgen/src/ir/comp.rs
@@ -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);
@@ -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 |
diff --git a/libbindgen/src/ir/item.rs b/libbindgen/src/ir/item.rs
index 0d5e6ba2..932b06fc 100644
--- a/libbindgen/src/ir/item.rs
+++ b/libbindgen/src/ir/item.rs
@@ -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,
}
})
@@ -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 {
@@ -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
@@ -1203,7 +1201,7 @@ impl ClangItemParser for Item {
None,
None,
parent_id,
- ItemKind::Type(Type::named(name, default))),
+ ItemKind::Type(Type::named(name))),
None,
None);
@@ -1211,14 +1209,13 @@ impl ClangItemParser for Item {
}
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)
}
}
diff --git a/libbindgen/src/ir/ty.rs b/libbindgen/src/ir/ty.rs
index 60092d54..b04afeb6 100644
--- a/libbindgen/src/ir/ty.rs
+++ b/libbindgen/src/ir/ty.rs
@@ -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)
}
@@ -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) |
@@ -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 {
@@ -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);
@@ -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);
}
@@ -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: \
diff --git a/libbindgen/src/lib.rs b/libbindgen/src/lib.rs
index a74c1799..5054cd13 100644
--- a/libbindgen/src/lib.rs
+++ b/libbindgen/src/lib.rs
@@ -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.
@@ -17,13 +18,13 @@
#![allow(non_upper_case_globals)]
#[macro_use]
+#[allow(unused_extern_crates)]
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;
diff --git a/libbindgen/src/parse.rs b/libbindgen/src/parse.rs
index 28e65759..0e4164f0 100644
--- a/libbindgen/src/parse.rs
+++ b/libbindgen/src/parse.rs
@@ -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
@@ -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
diff --git a/libbindgen/tests/expectations/tests/anon_union.rs b/libbindgen/tests/expectations/tests/anon_union.rs
index 8ae92b31..f8559ca9 100644
--- a/libbindgen/tests/expectations/tests/anon_union.rs
+++ b/libbindgen/tests/expectations/tests/anon_union.rs
@@ -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 {
@@ -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);
+}
diff --git a/libbindgen/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/libbindgen/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs
new file mode 100644
index 00000000..553879b7
--- /dev/null
+++ b/libbindgen/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs
@@ -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 }
+}
diff --git a/libbindgen/tests/expectations/tests/crtp.rs b/libbindgen/tests/expectations/tests/crtp.rs
index 109a768a..cc488fd6 100644
--- a/libbindgen/tests/expectations/tests/crtp.rs
+++ b/libbindgen/tests/expectations/tests/crtp.rs
@@ -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 {
@@ -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 {
@@ -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);
+}
diff --git a/libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs
index fc24e989..e377b3ad 100644
--- a/libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs
+++ b/libbindgen/tests/expectations/tests/forward-inherit-struct-with-fields.rs
@@ -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>,
}
diff --git a/libbindgen/tests/expectations/tests/forward-inherit-struct.rs b/libbindgen/tests/expectations/tests/forward-inherit-struct.rs
index a58058b0..5de70fa9 100644
--- a/libbindgen/tests/expectations/tests/forward-inherit-struct.rs
+++ b/libbindgen/tests/expectations/tests/forward-inherit-struct.rs
@@ -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>,
}
diff --git a/libbindgen/tests/expectations/tests/issue-358.rs b/libbindgen/tests/expectations/tests/issue-358.rs
new file mode 100644
index 00000000..1b933d34
--- /dev/null
+++ b/libbindgen/tests/expectations/tests/issue-358.rs
@@ -0,0 +1,20 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct JS_PersistentRooted<c> {
+ pub _base: a,
+ pub _phantom_0: ::std::marker::PhantomData<c>,
+}
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct a {
+ pub b: *mut a,
+}
+impl Clone for a {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/libbindgen/tests/expectations/tests/vtable_recursive_sig.rs b/libbindgen/tests/expectations/tests/vtable_recursive_sig.rs
index 77312336..ce62eeb0 100644
--- a/libbindgen/tests/expectations/tests/vtable_recursive_sig.rs
+++ b/libbindgen/tests/expectations/tests/vtable_recursive_sig.rs
@@ -5,6 +5,19 @@
#[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 {
}
#[repr(C)]
@@ -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 }
-}
diff --git a/libbindgen/tests/headers/bad-namespace-parenthood-inheritance.hpp b/libbindgen/tests/headers/bad-namespace-parenthood-inheritance.hpp
new file mode 100644
index 00000000..ce21a401
--- /dev/null
+++ b/libbindgen/tests/headers/bad-namespace-parenthood-inheritance.hpp
@@ -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 >
+ {
+ };
+}
diff --git a/libbindgen/tests/headers/issue-358.hpp b/libbindgen/tests/headers/issue-358.hpp
new file mode 100644
index 00000000..b14521b7
--- /dev/null
+++ b/libbindgen/tests/headers/issue-358.hpp
@@ -0,0 +1,8 @@
+// bindgen-flags: -- -std=c++11
+namespace JS {
+template <typename> class PersistentRooted;
+}
+template <typename> class a { a *b; };
+namespace JS {
+template <typename c> class PersistentRooted : a<PersistentRooted<c>> {};
+}