diff options
Diffstat (limited to 'libbindgen/src')
-rw-r--r-- | libbindgen/src/clang.rs | 12 | ||||
-rw-r--r-- | libbindgen/src/ir/context.rs | 22 | ||||
-rw-r--r-- | libbindgen/src/ir/item.rs | 3 |
3 files changed, 18 insertions, 19 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs index 7c6d3199..a81a8cfb 100644 --- a/libbindgen/src/clang.rs +++ b/libbindgen/src/clang.rs @@ -173,6 +173,18 @@ impl Cursor { semantic_parent == tu.fallible_semantic_parent() } + /// There are a few kinds of types that we need to treat specially, mainly + /// not tracking the type declaration but the location of the cursor, given + /// clang doesn't expose a proper declaration for these types. + pub fn is_template_like(&self) -> bool { + match self.kind() { + CXCursor_ClassTemplate | + CXCursor_ClassTemplatePartialSpecialization | + CXCursor_TypeAliasTemplateDecl => true, + _ => false, + } + } + /// Get the kind of referent this cursor is pointing to. pub fn kind(&self) -> Enum_CXCursorKind { unsafe { clang_getCursorKind(self.x) } diff --git a/libbindgen/src/ir/context.rs b/libbindgen/src/ir/context.rs index 1d658e7d..b1c40cb3 100644 --- a/libbindgen/src/ir/context.rs +++ b/libbindgen/src/ir/context.rs @@ -171,9 +171,6 @@ impl<'ctx> BindgenContext<'ctx> { item: Item, declaration: Option<Cursor>, location: Option<Cursor>) { - use clangll::{CXCursor_ClassTemplate, - CXCursor_ClassTemplatePartialSpecialization, - CXCursor_TypeAliasTemplateDecl}; debug!("BindgenContext::add_item({:?}, declaration: {:?}, loc: {:?}", item, declaration, @@ -206,10 +203,7 @@ impl<'ctx> BindgenContext<'ctx> { let mut declaration = declaration.unwrap(); if !declaration.is_valid() { if let Some(location) = location { - if location.kind() == CXCursor_ClassTemplate || - location.kind() == - CXCursor_ClassTemplatePartialSpecialization || - location.kind() == CXCursor_TypeAliasTemplateDecl { + if location.is_template_like() { declaration = location; } } @@ -645,9 +639,7 @@ impl<'ctx> BindgenContext<'ctx> { ty: &clang::Type, location: Option<clang::Cursor>) -> Option<ItemId> { - use clangll::{CXCursor_ClassTemplate, - CXCursor_ClassTemplatePartialSpecialization, - CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; + use clangll::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!("builtin_or_resolved_ty: {:?}, {:?}, {:?}", ty, location, @@ -655,10 +647,7 @@ impl<'ctx> BindgenContext<'ctx> { let mut declaration = ty.declaration(); if !declaration.is_valid() { if let Some(location) = location { - if location.kind() == CXCursor_ClassTemplate || - location.kind() == - CXCursor_ClassTemplatePartialSpecialization || - location.kind() == CXCursor_TypeAliasTemplateDecl { + if location.is_template_like() { declaration = location; } } @@ -690,10 +679,7 @@ impl<'ctx> BindgenContext<'ctx> { // Note that we only do it if parent_id is some, and we have a // location for building the new arguments, the template // argument names don't matter in the global context. - if (declaration.kind() == CXCursor_ClassTemplate || - declaration.kind() == - CXCursor_ClassTemplatePartialSpecialization || - declaration.kind() == CXCursor_TypeAliasTemplateDecl) && + if declaration.is_template_like() && *ty != canonical_declaration.cur_type() && location.is_some() && parent_id.is_some() { diff --git a/libbindgen/src/ir/item.rs b/libbindgen/src/ir/item.rs index 79aca5af..a754801c 100644 --- a/libbindgen/src/ir/item.rs +++ b/libbindgen/src/ir/item.rs @@ -43,7 +43,8 @@ pub trait ItemCanonicalName { /// name is just `"BAR"`. pub trait ItemCanonicalPath { /// Get the namespace-aware canonical path for this item. This means that if - /// namespaces are disabled, you'll + /// namespaces are disabled, you'll get a single item, and otherwise you get + /// the whole path. fn namespace_aware_canonical_path(&self, ctx: &BindgenContext) -> Vec<String>; |