summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-10-02 12:20:53 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-10-02 12:20:53 -0700
commit3495d03e98bfe623f83083d1788e08f73d876a59 (patch)
treefbb33c676266030f1d6563264592ddfe9a7c1420
parent3ef31e851e530d38f867c9063200576dee4494b0 (diff)
Make methods/constructors/destructors use FunctionId
And also allow ID comparison across ID types, as this makes implementing the above much easier.
-rw-r--r--src/codegen/mod.rs2
-rw-r--r--src/ir/analysis/template_params.rs2
-rw-r--r--src/ir/comp.rs28
-rw-r--r--src/ir/context.rs30
-rw-r--r--src/ir/item.rs6
5 files changed, 45 insertions, 23 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index f2b3a17b..ce5054c9 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -379,7 +379,7 @@ impl CodeGenerator for Module {
}
}
- if item.id() == ctx.root_module().into() {
+ if item.id() == ctx.root_module() {
if result.saw_bindgen_union {
utils::prepend_union_types(ctx, &mut *result);
}
diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs
index 24ab4f26..00504aa4 100644
--- a/src/ir/analysis/template_params.rs
+++ b/src/ir/analysis/template_params.rs
@@ -277,7 +277,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
let params = decl.self_template_params(self.ctx).unwrap_or(vec![]);
- debug_assert!(this_id != instantiation.template_definition().into());
+ debug_assert!(this_id != instantiation.template_definition());
let used_by_def = self.used
.get(&instantiation.template_definition().into())
.expect("Should have a used entry for instantiation's template definition")
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 3d09363c..fa137068 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -2,7 +2,7 @@
use super::analysis::HasVtable;
use super::annotations::Annotations;
-use super::context::{BindgenContext, ItemId, TypeId, VarId};
+use super::context::{BindgenContext, FunctionId, ItemId, TypeId, VarId};
use super::dot::DotAttributes;
use super::item::{IsOpaque, Item};
use super::layout::Layout;
@@ -53,13 +53,13 @@ pub struct Method {
/// item, but a `Function` one.
///
/// This is tricky and probably this field should be renamed.
- signature: ItemId,
+ signature: FunctionId,
is_const: bool,
}
impl Method {
/// Construct a new `Method`.
- pub fn new(kind: MethodKind, signature: ItemId, is_const: bool) -> Self {
+ pub fn new(kind: MethodKind, signature: FunctionId, is_const: bool) -> Self {
Method {
kind: kind,
signature: signature,
@@ -94,8 +94,8 @@ impl Method {
self.kind == MethodKind::Static
}
- /// Get the `ItemId` for the `Function` signature for this method.
- pub fn signature(&self) -> ItemId {
+ /// Get the id for the `Function` signature for this method.
+ pub fn signature(&self) -> FunctionId {
self.signature
}
@@ -831,11 +831,11 @@ pub struct CompInfo {
methods: Vec<Method>,
/// The different constructors this struct or class contains.
- constructors: Vec<ItemId>,
+ constructors: Vec<FunctionId>,
/// The destructor of this type. The bool represents whether this destructor
/// is virtual.
- destructor: Option<(bool, ItemId)>,
+ destructor: Option<(bool, FunctionId)>,
/// Vector of classes this one inherits from.
base_members: Vec<Base>,
@@ -984,12 +984,12 @@ impl CompInfo {
}
/// Get this type's set of constructors.
- pub fn constructors(&self) -> &[ItemId] {
+ pub fn constructors(&self) -> &[FunctionId] {
&self.constructors
}
/// Get this type's destructor.
- pub fn destructor(&self) -> Option<(bool, ItemId)> {
+ pub fn destructor(&self) -> Option<(bool, FunctionId)> {
self.destructor
}
@@ -1233,6 +1233,8 @@ impl CompInfo {
_ => return CXChildVisit_Continue,
};
+ let signature = signature.expect_function_id(ctx);
+
match cur.kind() {
CXCursor_Constructor => {
ci.constructors.push(signature);
@@ -1497,14 +1499,14 @@ impl Trace for CompInfo {
for method in self.methods() {
if method.is_destructor() {
- tracer.visit_kind(method.signature, EdgeKind::Destructor);
+ tracer.visit_kind(method.signature.into(), EdgeKind::Destructor);
} else {
- tracer.visit_kind(method.signature, EdgeKind::Method);
+ tracer.visit_kind(method.signature.into(), EdgeKind::Method);
}
}
- for &ctor in self.constructors() {
- tracer.visit_kind(ctor, EdgeKind::Constructor);
+ for ctor in self.constructors() {
+ tracer.visit_kind(ctor.into(), EdgeKind::Constructor);
}
// Base members and fields are not generated for opaque types (but all
diff --git a/src/ir/context.rs b/src/ir/context.rs
index f9efbf05..3dfef1de 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -31,7 +31,7 @@ use std::iter::IntoIterator;
use std::mem;
/// An identifier for some kind of IR item.
-#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)]
pub struct ItemId(usize);
macro_rules! item_id_newtype {
@@ -47,7 +47,7 @@ macro_rules! item_id_newtype {
unchecked = $unchecked:ident;
) => {
$( #[$attr] )*
- #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+ #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)]
pub struct $name(ItemId);
impl $name {
@@ -58,6 +58,16 @@ macro_rules! item_id_newtype {
}
}
+ impl<T> ::std::cmp::PartialEq<T> for $name
+ where
+ T: Copy + Into<ItemId>
+ {
+ fn eq(&self, rhs: &T) -> bool {
+ let rhs: ItemId = (*rhs).into();
+ self.0 == rhs
+ }
+ }
+
impl From<$name> for ItemId {
fn from(id: $name) -> ItemId {
id.0
@@ -186,6 +196,16 @@ impl ItemId {
}
}
+impl<T> ::std::cmp::PartialEq<T> for ItemId
+where
+ T: Copy + Into<ItemId>
+{
+ fn eq(&self, rhs: &T) -> bool {
+ let rhs: ItemId = (*rhs).into();
+ self.0 == rhs.0
+ }
+}
+
impl<T> CanDeriveDebug for T
where
T: Copy + Into<ItemId>
@@ -651,7 +671,7 @@ impl BindgenContext {
let is_template_instantiation = is_type &&
item.expect_type().is_template_instantiation();
- if item.id() != self.root_module.into() {
+ if item.id() != self.root_module {
self.add_item_to_module(&item);
}
@@ -715,7 +735,7 @@ impl BindgenContext {
/// codegen'd, even if its parent is not whitelisted. See issue #769 for
/// details.
fn add_item_to_module(&mut self, item: &Item) {
- assert!(item.id() != self.root_module.into());
+ assert!(item.id() != self.root_module);
assert!(!self.items.contains_key(&item.id()));
if let Some(parent) = self.items.get_mut(&item.parent_id()) {
@@ -1191,7 +1211,7 @@ impl BindgenContext {
assert!(self.current_module == self.root_module);
for (&id, _item) in self.items() {
- if id == self.root_module.into() {
+ if id == self.root_module {
continue;
}
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 2b137584..3a4c49d4 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -577,7 +577,7 @@ impl Item {
// FIXME: Workaround for some types falling behind when parsing weird
// stl classes, for example.
if ctx.options().enable_cxx_namespaces && self.kind().is_module() &&
- self.id() != ctx.root_module().into()
+ self.id() != ctx.root_module()
{
return false;
}
@@ -589,7 +589,7 @@ impl Item {
None => return false,
};
- if parent_item.id() == ctx.root_module().into() {
+ if parent_item.id() == ctx.root_module() {
return true;
} else if ctx.options().enable_cxx_namespaces ||
!parent_item.kind().is_module()
@@ -834,7 +834,7 @@ impl Item {
let mut names: Vec<_> = target
.parent_id()
.ancestors(ctx)
- .filter(|id| *id != ctx.root_module().into())
+ .filter(|id| *id != ctx.root_module())
.take_while(|id| {
// Stop iterating ancestors once we reach a non-inline namespace
// when opt.within_namespaces is set.