diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-05-20 01:10:13 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-05-20 03:32:38 +0200 |
commit | 44f68587e4635df5661e64f03dd2dd4d9a3ebd30 (patch) | |
tree | 63e3fa2d52fedcdeb7bc4c99859af2b9866c52fa /src | |
parent | 25150ca64f8009ac53829a2daa031c8723684523 (diff) |
codegen: Reuse the next_child_local_id hack for template instantiations.
This should be good enough, following the pattern of anonymous items, and should
prevent most of the current noise in stylo updates.
Closes #620
Fixes #619
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/mod.rs | 4 | ||||
-rw-r--r-- | src/ir/item.rs | 25 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 06e3a4f6..2f8ad805 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -760,8 +760,8 @@ impl CodeGenerator for TemplateInstantiation { let name = item.canonical_name(ctx); let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}", - name, - item.id().as_usize()); + name, item.exposed_id(ctx)); + let fn_name = ctx.rust_ident_raw(&fn_name); let prefix = ctx.trait_prefix(); diff --git a/src/ir/item.rs b/src/ir/item.rs index fdf2507d..6c118f54 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -370,7 +370,7 @@ pub struct Item { /// This item's id. id: ItemId, - /// The item's local id, unique only amongst its siblings. Only used for + /// The item's local id, unique only amongst its siblings. Only used for /// anonymous items. /// /// Lazily initialized in local_id(). @@ -379,7 +379,7 @@ pub struct Item { /// case this is an implementation detail. local_id: Cell<Option<usize>>, - /// The next local id to use for a child.. + /// The next local id to use for a child or template instantiation. next_child_local_id: Cell<usize>, /// A cached copy of the canonical name, as returned by `canonical_name`. @@ -490,13 +490,23 @@ impl Item { pub fn local_id(&self, ctx: &BindgenContext) -> usize { if self.local_id.get().is_none() { let parent = ctx.resolve_item(self.parent_id); - let local_id = parent.next_child_local_id.get(); - parent.next_child_local_id.set(local_id + 1); - self.local_id.set(Some(local_id)); + self.local_id.set(Some(parent.next_child_local_id())); } self.local_id.get().unwrap() } + /// Get an identifier that differentiates a child of this item of other + /// related items. + /// + /// This is currently used for anonymous items, and template instantiation + /// tests, in both cases in order to reduce noise when system headers are at + /// place. + pub fn next_child_local_id(&self) -> usize { + let local_id = self.next_child_local_id.get(); + self.next_child_local_id.set(local_id + 1); + local_id + } + /// Returns whether this item is a top-level item, from the point of view of /// bindgen. /// @@ -777,13 +787,16 @@ impl Item { ctx.rust_mangle(&name).into_owned() } - fn exposed_id(&self, ctx: &BindgenContext) -> String { + /// The exposed id that represents an unique id among the siblings of a + /// given item. + pub fn exposed_id(&self, ctx: &BindgenContext) -> String { // Only use local ids for enums, classes, structs and union types. All // other items use their global id. let ty_kind = self.kind().as_type().map(|t| t.kind()); if let Some(ty_kind) = ty_kind { match *ty_kind { TypeKind::Comp(..) | + TypeKind::TemplateInstantiation(..) | TypeKind::Enum(..) => return self.local_id(ctx).to_string(), _ => {} } |