summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-14 12:01:04 -0600
committerGitHub <noreply@github.com>2016-11-14 12:01:04 -0600
commit004a19537f1f40e77aacdc13a2f56a8553e63dc9 (patch)
tree5ba2713d771291e8670b00a81d9cc2338bca9ad5
parentb7259deb35aae61d7d21875e3b3da55e3f4391cc (diff)
parent1001e3bcc835e1b01deef6c84f2163d67ff6d509 (diff)
Auto merge of #247 - emilio:macro-redef, r=fitzgen
Handle macro redefinition a bit more graciously. r? @fitzgen
-rw-r--r--src/ir/var.rs12
-rw-r--r--tests/expectations/tests/macro-redef.rs9
-rw-r--r--tests/headers/macro-redef.h5
3 files changed, 21 insertions, 5 deletions
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 0e7df618..1c7b2028 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -87,17 +87,19 @@ impl ClangSubItemParser for Var {
assert!(!id.is_empty(), "Empty macro name?");
- if ctx.parsed_macro(&id) {
- let name = String::from_utf8(id).unwrap();
- warn!("Duplicated macro definition: {}", name);
- return Err(ParseError::Continue);
- }
+ let previously_defined = ctx.parsed_macro(&id);
// NB: It's important to "note" the macro even if the result is
// not an integer, otherwise we might loose other kind of
// derived macros.
ctx.note_parsed_macro(id.clone(), value.clone());
+ if previously_defined {
+ let name = String::from_utf8(id).unwrap();
+ warn!("Duplicated macro definition: {}", name);
+ return Err(ParseError::Continue);
+ }
+
// NOTE: Unwrapping, here and above, is safe, because the
// identifier of a token comes straight from clang, and we
// enforce utf8 there, so we should have already panicked at
diff --git a/tests/expectations/tests/macro-redef.rs b/tests/expectations/tests/macro-redef.rs
new file mode 100644
index 00000000..881a44ae
--- /dev/null
+++ b/tests/expectations/tests/macro-redef.rs
@@ -0,0 +1,9 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+pub const FOO: ::std::os::raw::c_uint = 4;
+pub const BAR: ::std::os::raw::c_uint = 5;
+pub const BAZ: ::std::os::raw::c_uint = 6;
diff --git a/tests/headers/macro-redef.h b/tests/headers/macro-redef.h
new file mode 100644
index 00000000..0180d2ab
--- /dev/null
+++ b/tests/headers/macro-redef.h
@@ -0,0 +1,5 @@
+#define FOO 4
+#define BAR (1 + FOO)
+#undef FOO
+#define FOO 5
+#define BAZ (1 + FOO)