summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/context.rs37
-rw-r--r--src/ir/function.rs17
2 files changed, 51 insertions, 3 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index bbcc5698..ccb7b75a 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1926,8 +1926,43 @@ impl BindgenContext {
parent_id: Option<ItemId>,
ty: &clang::Type,
) -> TypeId {
+ self.build_wrapper(
+ with_id,
+ wrapped_id,
+ parent_id,
+ ty,
+ ty.is_const(),
+ )
+ }
+
+ /// A wrapper over a type that adds a const qualifier explicitly.
+ ///
+ /// Needed to handle const methods in C++, wrapping the type .
+ pub fn build_const_wrapper(
+ &mut self,
+ with_id: ItemId,
+ wrapped_id: TypeId,
+ parent_id: Option<ItemId>,
+ ty: &clang::Type,
+ ) -> TypeId {
+ self.build_wrapper(
+ with_id,
+ wrapped_id,
+ parent_id,
+ ty,
+ /* is_const = */ true,
+ )
+ }
+
+ fn build_wrapper(
+ &mut self,
+ with_id: ItemId,
+ wrapped_id: TypeId,
+ parent_id: Option<ItemId>,
+ ty: &clang::Type,
+ is_const: bool,
+ ) -> TypeId {
let spelling = ty.spelling();
- let is_const = ty.is_const();
let layout = ty.fallible_layout().ok();
let type_kind = TypeKind::ResolvedTypeRef(wrapped_id);
let ty = Type::new(Some(spelling), layout, type_kind, is_const);
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 602de80c..5e8d2fc8 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -402,14 +402,27 @@ impl FunctionSig {
let is_virtual = is_method && cursor.method_is_virtual();
let is_static = is_method && cursor.method_is_static();
if !is_static && !is_virtual {
- let class = Item::parse(cursor.semantic_parent(), None, ctx)
+ let parent = cursor.semantic_parent();
+ let class = Item::parse(parent, None, ctx)
.expect("Expected to parse the class");
// The `class` most likely is not finished parsing yet, so use
// the unchecked variant.
let class = class.as_type_id_unchecked();
+ let class = if is_const {
+ let const_class_id = ctx.next_item_id();
+ ctx.build_const_wrapper(
+ const_class_id,
+ class,
+ None,
+ &parent.cur_type(),
+ )
+ } else {
+ class
+ };
+
let ptr =
- Item::builtin_type(TypeKind::Pointer(class), is_const, ctx);
+ Item::builtin_type(TypeKind::Pointer(class), false, ctx);
args.insert(0, (Some("this".into()), ptr));
} else if is_virtual {
let void = Item::builtin_type(TypeKind::Void, false, ctx);