diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2016-10-31 15:12:33 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2016-10-31 15:39:29 -0700 |
commit | 005fd4399be57f12952f08140a0178c09512a77f (patch) | |
tree | 99359cbac60853f3d2718a398683dc52f9bee781 /src/codegen/mod.rs | |
parent | 724aa063d3797a82995f313bc447bd55e8520a47 (diff) |
Move the `TypeCollector` trait to the `ir` module
This commit moves the `TypeCollector` trait out from the `codegen` module and
into its own submodule in `ir::type_collector`. Additionally, it puts the
various `TypeCollector` trait implementations next to the types that each
implementation is for.
Diffstat (limited to 'src/codegen/mod.rs')
-rwxr-xr-x | src/codegen/mod.rs | 129 |
1 files changed, 1 insertions, 128 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 65900739..a656c2c1 100755 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -14,11 +14,11 @@ use ir::item_kind::ItemKind; use ir::comp::{CompKind, CompInfo, Field, Method}; use ir::layout::Layout; use ir::annotations::FieldAccessorKind; +use ir::type_collector::{ItemSet, TypeCollector}; use std::ops; use std::borrow::Cow; use std::mem; -use std::collections::BTreeSet; use std::collections::HashSet; use std::collections::hash_map::{HashMap, Entry}; @@ -1584,133 +1584,6 @@ impl CodeGenerator for Function { } } -type ItemSet = BTreeSet<ItemId>; - -trait TypeCollector { - type Extra; - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - extra: &Self::Extra); -} - -impl TypeCollector for ItemId { - type Extra = (); - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - extra: &()) { - context.resolve_item(*self).collect_types(context, types, extra); - } -} - -impl TypeCollector for Item { - type Extra = (); - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - _extra: &()) { - if self.is_hidden(context) || types.contains(&self.id()) { - return; - } - - match *self.kind() { - ItemKind::Type(ref ty) => { - types.insert(self.id()); - if !self.is_opaque(context) { - ty.collect_types(context, types, self); - } - } - _ => {}, // FIXME. - } - } -} - -impl TypeCollector for Type { - type Extra = Item; - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - item: &Item) { - match *self.kind() { - TypeKind::Pointer(inner) | - TypeKind::Reference(inner) | - TypeKind::Array(inner, _) | - TypeKind::TemplateAlias(inner, _) | - TypeKind::Alias(_, inner) | - TypeKind::Named(_, Some(inner)) | - TypeKind::ResolvedTypeRef(inner) - => inner.collect_types(context, types, &()), - - TypeKind::TemplateRef(inner, ref template_args) => { - inner.collect_types(context, types, &()); - for item in template_args { - item.collect_types(context, types, &()); - } - } - TypeKind::Comp(ref ci) => ci.collect_types(context, types, item), - TypeKind::Function(ref sig) => { - sig.collect_types(context, types, item) - } - // FIXME: Pending types! - ref other @ _ => { - debug!("Ignoring: {:?}", other); - }, - } - } -} - -impl TypeCollector for FunctionSig { - type Extra = Item; - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - _item: &Item) { - self.return_type().collect_types(context, types, &()); - - for &(_, ty) in self.argument_types() { - ty.collect_types(context, types, &()); - } - } -} - -impl TypeCollector for CompInfo { - type Extra = Item; - - fn collect_types(&self, - context: &BindgenContext, - types: &mut ItemSet, - item: &Item) { - if let Some(template) = self.specialized_template() { - template.collect_types(context, types, &()); - } - - let applicable_template_args = item.applicable_template_args(context); - for arg in applicable_template_args { - arg.collect_types(context, types, &()); - } - - for base in self.base_members() { - base.collect_types(context, types, &()); - } - - for field in self.fields() { - field.ty().collect_types(context, types, &()); - } - - for ty in self.inner_types() { - ty.collect_types(context, types, &()); - } - - // FIXME(emilio): Methods, VTable? - } -} - pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> { context.gen(|context| { let mut result = CodegenResult::new(); |