summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <me@emiliocobos.me>2016-05-24 20:55:23 +0200
committerEmilio Cobos Álvarez <me@emiliocobos.me>2016-05-24 20:55:23 +0200
commit7bddcb274e5c4851e9e02b7973ea74b0b9d48eed (patch)
treed7db1987e60da861cf9179970ca4a7445707145f
parente24e134a89479149dd6ed4c20e00bb51306dbe06 (diff)
parser: Implement nocopy annotation.
-rw-r--r--src/parser.rs8
-rw-r--r--src/types.rs6
-rw-r--r--tests/expectations/no_copy.rs14
-rw-r--r--tests/headers/no_copy.hpp6
4 files changed, 34 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs
index aa6fcbdb..b104c2a3 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -517,6 +517,8 @@ struct Annotations {
opaque: bool,
hide: bool,
use_as: Option<String>,
+ /// Disable deriving copy/clone on this struct.
+ no_copy: bool,
}
impl Annotations {
@@ -525,6 +527,7 @@ impl Annotations {
opaque: false,
hide: false,
use_as: None,
+ no_copy: false,
};
anno.parse(&cursor.comment());
@@ -542,6 +545,7 @@ impl Annotations {
"opaque" => self.opaque = true,
"hide" => self.hide = true,
"replaces" => self.use_as = Some(comment.get_tag_attr_value(i)),
+ "nocopy" => self.no_copy = true,
_ => (),
}
}
@@ -1089,6 +1093,10 @@ fn visit_top(cursor: &Cursor,
ci.borrow_mut().hide = true;
}
+ if anno.no_copy {
+ ci.borrow_mut().no_copy = true;
+ }
+
// If we find a previous translation, we take it now and carry
// on.
//
diff --git a/src/types.rs b/src/types.rs
index 7d65c7d0..4527d710 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -429,6 +429,8 @@ pub struct CompInfo {
pub opaque: bool,
pub base_members: usize,
pub layout: Layout,
+ /// If this struct is explicitely marked as non-copiable.
+ pub no_copy: bool,
/// Typedef'd types names, that we'll resolve early to avoid name conflicts
pub typedefs: Vec<String>,
/// If this type has a template parameter which is not a type (e.g.: a size_t)
@@ -479,6 +481,7 @@ impl CompInfo {
hide: false,
parser_cursor: None,
opaque: false,
+ no_copy: false,
base_members: 0,
layout: layout,
typedefs: vec![],
@@ -570,6 +573,9 @@ impl CompInfo {
}
pub fn can_derive_copy(&self) -> bool {
+ if self.no_copy {
+ return false;
+ }
match self.kind {
CompKind::Union => true,
CompKind::Struct => {
diff --git a/tests/expectations/no_copy.rs b/tests/expectations/no_copy.rs
new file mode 100644
index 00000000..95a733b6
--- /dev/null
+++ b/tests/expectations/no_copy.rs
@@ -0,0 +1,14 @@
+/* automatically generated by rust-bindgen */
+
+
+#![feature(const_fn)]
+#![allow(non_snake_case)]
+
+
+/** <div rustbindgen nocopy></div> */
+#[repr(C)]
+#[derive(Debug)]
+pub struct Struct_CopiableButWait<T> {
+ pub whatever: ::std::os::raw::c_int,
+ pub _phantom0: ::std::marker::PhantomData<T>,
+}
diff --git a/tests/headers/no_copy.hpp b/tests/headers/no_copy.hpp
new file mode 100644
index 00000000..349e428e
--- /dev/null
+++ b/tests/headers/no_copy.hpp
@@ -0,0 +1,6 @@
+
+/** <div rustbindgen nocopy></div> */
+template<typename T>
+class CopiableButWait {
+ int whatever;
+};