File tree 2 files changed +51
-3
lines changed
2 files changed +51
-3
lines changed Original file line number Diff line number Diff line change @@ -1925,9 +1925,44 @@ impl BindgenContext {
1925
1925
wrapped_id : TypeId ,
1926
1926
parent_id : Option < ItemId > ,
1927
1927
ty : & clang:: Type ,
1928
+ ) -> TypeId {
1929
+ self . build_wrapper (
1930
+ with_id,
1931
+ wrapped_id,
1932
+ parent_id,
1933
+ ty,
1934
+ ty. is_const ( ) ,
1935
+ )
1936
+ }
1937
+
1938
+ /// A wrapper over a type that adds a const qualifier explicitly.
1939
+ ///
1940
+ /// Needed to handle const methods in C++, wrapping the type .
1941
+ pub fn build_const_wrapper (
1942
+ & mut self ,
1943
+ with_id : ItemId ,
1944
+ wrapped_id : TypeId ,
1945
+ parent_id : Option < ItemId > ,
1946
+ ty : & clang:: Type ,
1947
+ ) -> TypeId {
1948
+ self . build_wrapper (
1949
+ with_id,
1950
+ wrapped_id,
1951
+ parent_id,
1952
+ ty,
1953
+ /* is_const = */ true ,
1954
+ )
1955
+ }
1956
+
1957
+ fn build_wrapper (
1958
+ & mut self ,
1959
+ with_id : ItemId ,
1960
+ wrapped_id : TypeId ,
1961
+ parent_id : Option < ItemId > ,
1962
+ ty : & clang:: Type ,
1963
+ is_const : bool ,
1928
1964
) -> TypeId {
1929
1965
let spelling = ty. spelling ( ) ;
1930
- let is_const = ty. is_const ( ) ;
1931
1966
let layout = ty. fallible_layout ( ) . ok ( ) ;
1932
1967
let type_kind = TypeKind :: ResolvedTypeRef ( wrapped_id) ;
1933
1968
let ty = Type :: new ( Some ( spelling) , layout, type_kind, is_const) ;
Original file line number Diff line number Diff line change @@ -402,14 +402,27 @@ impl FunctionSig {
402
402
let is_virtual = is_method && cursor. method_is_virtual ( ) ;
403
403
let is_static = is_method && cursor. method_is_static ( ) ;
404
404
if !is_static && !is_virtual {
405
- let class = Item :: parse ( cursor. semantic_parent ( ) , None , ctx)
405
+ let parent = cursor. semantic_parent ( ) ;
406
+ let class = Item :: parse ( parent, None , ctx)
406
407
. expect ( "Expected to parse the class" ) ;
407
408
// The `class` most likely is not finished parsing yet, so use
408
409
// the unchecked variant.
409
410
let class = class. as_type_id_unchecked ( ) ;
410
411
412
+ let class = if is_const {
413
+ let const_class_id = ctx. next_item_id ( ) ;
414
+ ctx. build_const_wrapper (
415
+ const_class_id,
416
+ class,
417
+ None ,
418
+ & parent. cur_type ( ) ,
419
+ )
420
+ } else {
421
+ class
422
+ } ;
423
+
411
424
let ptr =
412
- Item :: builtin_type ( TypeKind :: Pointer ( class) , is_const , ctx) ;
425
+ Item :: builtin_type ( TypeKind :: Pointer ( class) , false , ctx) ;
413
426
args. insert ( 0 , ( Some ( "this" . into ( ) ) , ptr) ) ;
414
427
} else if is_virtual {
415
428
let void = Item :: builtin_type ( TypeKind :: Void , false , ctx) ;
You can’t perform that action at this time.
0 commit comments