diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-07 16:04:11 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 16:04:11 -0600 |
commit | 3c4a8403bdaa8e18facbe13995e4fa84dddce997 (patch) | |
tree | 26e60f04bbd79310c9537ab0ebdca2a06f3977d4 | |
parent | c314a2f1b3b70a1322a23f785995124941ed632a (diff) | |
parent | cc82b839b164f38513dcdcc93a63d654c82ca80c (diff) |
Auto merge of #223 - fitzgen:useful-helpers, r=emilio
Useful little helpers for Item and Type
Just a couple things I have found helpful when debugging, and should probably exist either way.
r? @emilio
-rw-r--r-- | src/ir/item.rs | 11 | ||||
-rw-r--r-- | src/ir/ty.rs | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/ir/item.rs b/src/ir/item.rs index a07ee1f3..c6d80a08 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -331,6 +331,12 @@ impl Item { self.kind().expect_type() } + /// Get a reference to this item's underlying `Type`, or `None` if this is + /// some other kind of item. + pub fn as_type(&self) -> Option<&Type> { + self.kind().as_type() + } + /// Get a reference to this item's underlying `Function`. Panic if this is /// some other kind of item. pub fn expect_function(&self) -> &Function { @@ -531,6 +537,11 @@ impl Item { ctx.opaque_by_name(&self.real_canonical_name(ctx, false, true)) } + /// Is this a reference to another type? + pub fn is_type_ref(&self) -> bool { + self.as_type().map_or(false, |ty| ty.is_type_ref()) + } + /// Get the canonical name without taking into account the replaces /// annotation. /// diff --git a/src/ir/ty.rs b/src/ir/ty.rs index be749268..2c1e5f8e 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -136,6 +136,15 @@ impl Type { self.is_const } + /// Is this a reference to another type? + pub fn is_type_ref(&self) -> bool { + match self.kind { + TypeKind::ResolvedTypeRef(_) | + TypeKind::UnresolvedTypeRef(_, _, _) => true, + _ => false, + } + } + /// What is the layout of this type? pub fn layout(&self, ctx: &BindgenContext) -> Option<Layout> { use std::mem; |