summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-01 14:36:53 -0500
committerGitHub <noreply@github.com>2016-09-01 14:36:53 -0500
commit89e272581dae736c0751aecef29593ab21340ae6 (patch)
tree38c471a953703cfc70b7feaeb1a3aca412ecb02f
parent1e26a8a0ef76656dc3567eb68a954a701fbb42c8 (diff)
parent5210a9f4583dafeeb8c34295d01e20a306fb044b (diff)
Auto merge of #52 - servo:dedup-virtual-overloaded-names, r=emilio
Deduplicate names of virtual overloaded methods. Fix #48 r? @emilio
-rw-r--r--src/gen.rs15
-rw-r--r--src/parser.rs2
-rw-r--r--tests/expectations/virtual_overloaded.rs26
-rw-r--r--tests/headers/virtual_overloaded.hpp5
4 files changed, 47 insertions, 1 deletions
diff --git a/src/gen.rs b/src/gen.rs
index fc2cadb8..eab4478a 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -968,6 +968,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo,
vffields.push(field);
}
+ let mut counts: HashMap<String, isize> = HashMap::new();
for vm in ci.vmethods.iter() {
let ty = match vm.ty {
TFuncPtr(ref sig) => {
@@ -977,7 +978,19 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo,
_ => unreachable!()
};
- let name = first(rust_id(ctx, &vm.name));
+ let mut name = vm.name.clone();
+ let mut count = 0;
+ match counts.get(&vm.name) {
+ Some(x) => {
+ count = *x;
+ name.push_str(&x.to_string());
+ },
+ None => ()
+ }
+ count += 1;
+ counts.insert(vm.name.clone(), count);
+
+ let name = first(rust_id(ctx, &name));
vffields.push(ast::StructField {
span: ctx.span,
diff --git a/src/parser.rs b/src/parser.rs
index 68578723..d8227f3a 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1490,6 +1490,7 @@ pub fn parse(options: ClangParserOptions, logger: &Logger) -> Result<ModuleMap,
}
if ctx.err_count > 0 {
+ logger.error(&format!("{} errors after diagnostics", ctx.err_count));
return Err(())
}
@@ -1510,6 +1511,7 @@ pub fn parse(options: ClangParserOptions, logger: &Logger) -> Result<ModuleMap,
ix.dispose();
if ctx.err_count > 0 {
+ logger.error(&format!("{} errors after translation", ctx.err_count));
return Err(())
}
diff --git a/tests/expectations/virtual_overloaded.rs b/tests/expectations/virtual_overloaded.rs
new file mode 100644
index 00000000..a59f9c27
--- /dev/null
+++ b/tests/expectations/virtual_overloaded.rs
@@ -0,0 +1,26 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct Struct_C {
+ pub _vftable: *const _vftable_Struct_C,
+}
+#[repr(C)]
+pub struct _vftable_Struct_C {
+ pub do_thing: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
+ arg1: ::std::os::raw::c_char),
+ pub do_thing1: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
+ arg1: ::std::os::raw::c_int),
+}
+impl ::std::clone::Clone for Struct_C {
+ fn clone(&self) -> Self { *self }
+}
+#[test]
+fn bindgen_test_layout_Struct_C() {
+ assert_eq!(::std::mem::size_of::<Struct_C>() , 8usize);
+ assert_eq!(::std::mem::align_of::<Struct_C>() , 8usize);
+}
diff --git a/tests/headers/virtual_overloaded.hpp b/tests/headers/virtual_overloaded.hpp
new file mode 100644
index 00000000..8aea8a19
--- /dev/null
+++ b/tests/headers/virtual_overloaded.hpp
@@ -0,0 +1,5 @@
+class C {
+public:
+ virtual void do_thing(char) { };
+ virtual void do_thing(int) { };
+};