@@ -124,6 +124,7 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
124124 } ;
125125
126126 let mut ci = CompInfo :: new ( spelling, ctx. current_module_id , filename, comment, kind, vec ! [ ] , layout) ;
127+ ci. parser_cursor = Some ( cursor) ;
127128
128129 // If it's an instantiation of another template,
129130 // find the canonical declaration to find the module
@@ -367,18 +368,18 @@ fn conv_decl_ty_resolving_typedefs(ctx: &mut ClangParserCtx,
367368 // it's important not to override
368369 if !args. is_empty ( ) {
369370 ci. borrow_mut ( ) . args = args;
371+
370372 // XXX: This is a super-dumb way to get the spesialisation,
371373 // but it seems to be the only one that'd work here...
372374 cursor. visit ( |c, _: & Cursor | {
373375 if c. kind ( ) == CXCursor_TemplateRef {
374- let decl = decl_name ( ctx, & c. referenced ( ) ) ;
376+ let decl = decl_name ( ctx, & c. referenced ( ) ) ;
375377 ci. borrow_mut ( ) . ref_template = Some ( decl. to_type ( ) ) ;
376378 }
377379 CXChildVisit_Continue
378380 } ) ;
379381 }
380382
381-
382383 TComp ( ci)
383384 }
384385 CXCursor_EnumDecl => {
@@ -458,7 +459,9 @@ fn conv_ty_resolving_typedefs(ctx: &mut ClangParserCtx,
458459 CXType_Pointer => conv_ptr_ty_resolving_typedefs ( ctx, & ty. pointee_type ( ) , cursor, false , layout, resolve_typedefs) ,
459460 CXType_LValueReference => conv_ptr_ty_resolving_typedefs ( ctx, & ty. pointee_type ( ) , cursor, true , layout, resolve_typedefs) ,
460461 // XXX DependentSizedArray is wrong
461- CXType_VariableArray | CXType_DependentSizedArray | CXType_IncompleteArray => {
462+ CXType_VariableArray |
463+ CXType_DependentSizedArray |
464+ CXType_IncompleteArray => {
462465 conv_ptr_ty_resolving_typedefs ( ctx, & ty. elem_type ( ) , cursor, false , layout, resolve_typedefs)
463466 }
464467 CXType_FunctionProto => TFuncProto ( mk_fn_sig ( ctx, ty, cursor) ) ,
@@ -537,6 +540,7 @@ impl Annotations {
537540fn visit_composite ( cursor : & Cursor , parent : & Cursor ,
538541 ctx : & mut ClangParserCtx ,
539542 ci : & mut CompInfo ) -> Enum_CXVisitorResult {
543+ assert ! ( ci. parser_cursor. is_some( ) ) ;
540544 fn is_bitfield_continuation ( field : & il:: FieldInfo , _ty : & il:: Type , width : u32 ) -> bool {
541545 match ( & field. bitfields , field. ty . layout ( ) ) {
542546 ( & Some ( ref bitfields) , Some ( layout) ) => {
@@ -560,8 +564,41 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
560564 let is_class_typedef = cursor. cur_type ( ) . sanitized_spelling_in ( & ci. typedefs ) ;
561565 let mutable = cursor. is_mutable_field ( ) ;
562566
567+ let cursor_ty = cursor. cur_type ( ) ;
568+
563569 // NB: Overwritten in the case of non-integer bitfield
564- let mut ty = conv_ty_resolving_typedefs ( ctx, & cursor. cur_type ( ) , cursor, is_class_typedef) ;
570+ let mut ty = conv_ty_resolving_typedefs ( ctx,
571+ & cursor. cur_type ( ) ,
572+ cursor,
573+ is_class_typedef) ;
574+
575+ use std:: cell:: BorrowState ;
576+ if let Some ( child_ci) = ty. get_outermost_composite ( ) {
577+ if let BorrowState :: Unused = child_ci. borrow_state ( ) {
578+ let mut child_ci = child_ci. borrow_mut ( ) ;
579+ let child_cursor = child_ci. parser_cursor . unwrap ( ) ;
580+
581+ // TODO: This is lame, ideally we should use cursors.
582+ // The problem this is trying to solve is
583+ // tests/headers/inner_template_self.hpp.
584+ //
585+ // The problem with this is that clang treats the *prev*
586+ // field as a Class Declaration instead of a Class Template,
587+ // so we have to check now for the name and the module id.
588+ //
589+ // Ideally, some method like `semantic_parent` or
590+ // `lexical_parent` should return the reference to the
591+ // class, but I've tried everything I could think about and
592+ // failed miserably.
593+ if child_cursor. kind ( ) == CXCursor_ClassDecl &&
594+ child_ci. args . is_empty ( ) &&
595+ child_ci. name == ci. name &&
596+ child_ci. module_id == ci. module_id {
597+ child_ci. args = ci. args . clone ( ) ;
598+ }
599+ }
600+ }
601+
565602 let comment = cursor. raw_comment ( ) ;
566603
567604 let ( name, bitfields) = match ( cursor. bit_width ( ) , ci. members . last_mut ( ) ) {
0 commit comments