diff options
author | Mikko Lehtonen <scoopr@iki.fi> | 2018-11-13 00:03:30 +0200 |
---|---|---|
committer | Mikko Lehtonen <scoopr@iki.fi> | 2018-11-13 22:25:40 +0200 |
commit | d5883c677d0ffc57ec38e8483428d9ab8b516623 (patch) | |
tree | d774d2db11d15f4663a537ad4eb5e66fc8f7cf55 | |
parent | d5dac094954b017468866129ed502655476d92ef (diff) |
Fix namespaces with macro names
-rw-r--r-- | src/ir/context.rs | 17 | ||||
-rw-r--r-- | tests/expectations/tests/namespace.rs | 27 | ||||
-rw-r--r-- | tests/headers/namespace.hpp | 9 | ||||
-rw-r--r-- | tests/headers/namespace/nsbegin.h | 1 | ||||
-rw-r--r-- | tests/headers/namespace/nsend.h | 1 |
5 files changed, 47 insertions, 8 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index bdf38428..c0f92464 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2160,16 +2160,21 @@ If you encounter an error missing from this list, please file an issue or a PR!" ::clang_sys::CXCursor_Namespace, "Be a nice person" ); + + let mut module_name = None; + let spelling = cursor.spelling(); + if !spelling.is_empty() + { + module_name = Some(spelling) + } + let tokens = match cursor.tokens() { Some(tokens) => tokens, - None => return (None, ModuleKind::Normal), + None => return (module_name, ModuleKind::Normal), }; - let mut iter = tokens.iter(); let mut kind = ModuleKind::Normal; let mut found_namespace_keyword = false; - let mut module_name = None; - while let Some(token) = iter.next() { match &*token.spelling { "inline" => { @@ -2195,7 +2200,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" break; } name if found_namespace_keyword => { - module_name = Some(name.to_owned()); + if module_name.is_none() { + module_name = Some(name.to_owned()); + } break; } _ => { diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 726383d0..dc51640e 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { @@ -19,7 +24,7 @@ pub mod root { pub fn in_whatever(); } } - pub mod _bindgen_mod_id_13 { + pub mod _bindgen_mod_id_17 { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] @@ -49,7 +54,7 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct C<T> { - pub _base: root::_bindgen_mod_id_13::A, + pub _base: root::_bindgen_mod_id_17::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], @@ -88,4 +93,20 @@ pub mod root { pub fn barr() -> root::C<f32>; } } + pub mod foobar { + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN6foobar3fooEv"] + pub fn foo(); + } + } + pub mod faraway { + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN7faraway3barEv"] + pub fn bar(); + } + } } diff --git a/tests/headers/namespace.hpp b/tests/headers/namespace.hpp index 408207f2..a8e6f8ec 100644 --- a/tests/headers/namespace.hpp +++ b/tests/headers/namespace.hpp @@ -40,3 +40,12 @@ namespace w { C<float> barr(); // <- This is the problematic one } + +#define NAMESPACE foobar +namespace NAMESPACE { + void foo(); +} + +#include "namespace/nsbegin.h" +void bar(); +#include "namespace/nsend.h" diff --git a/tests/headers/namespace/nsbegin.h b/tests/headers/namespace/nsbegin.h new file mode 100644 index 00000000..47a51c93 --- /dev/null +++ b/tests/headers/namespace/nsbegin.h @@ -0,0 +1 @@ +namespace faraway { diff --git a/tests/headers/namespace/nsend.h b/tests/headers/namespace/nsend.h new file mode 100644 index 00000000..5c34318c --- /dev/null +++ b/tests/headers/namespace/nsend.h @@ -0,0 +1 @@ +} |