Skip to content

Commit 0025da7

Browse files
committed
Pass the potential id to be used as the type wrapper id.
This should fix the MSVC problems. Signed-off-by: Emilio Cobos Álvarez <[email protected]>
1 parent 9b227c8 commit 0025da7

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/ir/context.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,22 +433,22 @@ impl<'ctx> BindgenContext<'ctx> {
433433
/// };
434434
/// ```
435435
fn build_template_wrapper(&mut self,
436+
with_id: ItemId,
436437
wrapping: ItemId,
437438
parent_id: ItemId,
438439
ty: &clang::Type,
439440
location: clang::Cursor) -> ItemId {
440441
use clangll::*;
441442
let mut args = vec![];
442443
let mut found_invalid_template_ref = false;
443-
let self_id = ItemId::next();
444444
location.visit(|c, _| {
445445
if c.kind() == CXCursor_TemplateRef &&
446446
c.cur_type().kind() == CXType_Invalid {
447447
found_invalid_template_ref = true;
448448
}
449449
if c.kind() == CXCursor_TypeRef {
450450
let new_ty =
451-
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(self_id), self);
451+
Item::from_ty_or_ref(c.cur_type(), Some(*c), Some(with_id), self);
452452
args.push(new_ty);
453453
}
454454
CXChildVisit_Continue
@@ -494,17 +494,18 @@ impl<'ctx> BindgenContext<'ctx> {
494494
let name = ty.spelling();
495495
let name = if name.is_empty() { None } else { Some(name) };
496496
let ty = Type::new(name, ty.fallible_layout().ok(), type_kind, ty.is_const());
497-
Item::new(self_id, None, None, parent_id, ItemKind::Type(ty))
497+
Item::new(with_id, None, None, parent_id, ItemKind::Type(ty))
498498
};
499499

500500
// Bypass all the validations in add_item explicitly.
501-
self.items.insert(self_id, item);
502-
self_id
501+
self.items.insert(with_id, item);
502+
with_id
503503
}
504504

505505
/// Looks up for an already resolved type, either because it's builtin, or
506506
/// because we already have it in the map.
507507
pub fn builtin_or_resolved_ty(&mut self,
508+
with_id: ItemId,
508509
parent_id: Option<ItemId>,
509510
ty: &clang::Type,
510511
location: Option<clang::Cursor>) -> Option<ItemId> {
@@ -533,6 +534,7 @@ impl<'ctx> BindgenContext<'ctx> {
533534
if let Some(id) = id {
534535
debug!("Already resolved ty {:?}, {:?}, {:?} {:?}",
535536
id, declaration, ty, location);
537+
536538
// If the declaration existed, we *might* be done, but it's not
537539
// the case for class templates, where the template arguments
538540
// may vary.
@@ -548,11 +550,12 @@ impl<'ctx> BindgenContext<'ctx> {
548550
*ty != canonical_declaration.cur_type() &&
549551
location.is_some() && parent_id.is_some() {
550552
return Some(
551-
self.build_template_wrapper(id, parent_id.unwrap(), ty,
553+
self.build_template_wrapper(with_id, id,
554+
parent_id.unwrap(), ty,
552555
location.unwrap()));
553556
}
554557

555-
return Some(self.build_ty_wrapper(id, parent_id, ty));
558+
return Some(self.build_ty_wrapper(with_id, id, parent_id, ty));
556559
}
557560
}
558561

@@ -568,19 +571,19 @@ impl<'ctx> BindgenContext<'ctx> {
568571
// We should probably make the constness tracking separate, so it doesn't
569572
// bloat that much, but hey, we already bloat the heck out of builtin types.
570573
fn build_ty_wrapper(&mut self,
574+
with_id: ItemId,
571575
wrapped_id: ItemId,
572576
parent_id: Option<ItemId>,
573577
ty: &clang::Type) -> ItemId {
574-
let id = ItemId::next();
575578
let spelling = ty.spelling();
576579
let is_const = ty.is_const();
577580
let layout = ty.fallible_layout().ok();
578581
let type_kind = TypeKind::ResolvedTypeRef(wrapped_id);
579582
let ty = Type::new(Some(spelling), layout, type_kind, is_const);
580-
let item = Item::new(id, None, None,
583+
let item = Item::new(with_id, None, None,
581584
parent_id.unwrap_or(self.current_module), ItemKind::Type(ty));
582585
self.add_builtin_item(item);
583-
id
586+
with_id
584587
}
585588

586589
fn build_builtin_ty(&mut self,

src/ir/item.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@ impl ClangItemParser for Item {
681681
.expect("Unable to resolve type");
682682
}
683683

684-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, &ty, location) {
684+
if let Some(ty) = context.builtin_or_resolved_ty(potential_id,
685+
parent_id, &ty,
686+
location) {
685687
debug!("{:?} already resolved: {:?}", ty, location);
686688
return ty;
687689
}
@@ -743,7 +745,8 @@ impl ClangItemParser for Item {
743745
context.replace(replaced, id);
744746
}
745747

746-
if let Some(ty) = context.builtin_or_resolved_ty(parent_id, ty, location) {
748+
if let Some(ty) = context.builtin_or_resolved_ty(id, parent_id,
749+
ty, location) {
747750
return Ok(ty);
748751
}
749752

src/ir/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ impl Type {
426426
parent_id: Option<ItemId>,
427427
ctx: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError> {
428428
use clangll::*;
429-
if let Some(ty) = ctx.builtin_or_resolved_ty(parent_id, ty, location) {
429+
if let Some(ty) = ctx.builtin_or_resolved_ty(potential_id, parent_id,
430+
ty, location) {
430431
debug!("{:?} already resolved: {:?}", ty, location);
431432
return Ok(ParseResult::AlreadyResolved(ty));
432433
}

0 commit comments

Comments
 (0)