diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/analysis/derive_debug.rs | 22 | ||||
-rw-r--r-- | src/ir/analysis/has_vtable.rs | 22 | ||||
-rw-r--r-- | src/ir/analysis/mod.rs | 27 |
3 files changed, 31 insertions, 40 deletions
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs index ac2a92de..0dc1a0c5 100644 --- a/src/ir/analysis/derive_debug.rs +++ b/src/ir/analysis/derive_debug.rs @@ -1,6 +1,6 @@ //! Determining which types for which we can emit `#[derive(Debug)]`. -use super::{ConstrainResult, MonotoneFramework}; +use super::{ConstrainResult, MonotoneFramework, generate_dependencies}; use std::collections::HashSet; use std::collections::HashMap; use ir::context::{BindgenContext, ItemId}; @@ -9,7 +9,6 @@ use ir::traversal::EdgeKind; use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use ir::ty::TypeKind; use ir::comp::Field; -use ir::traversal::Trace; use ir::comp::FieldMethods; use ir::derive::CanTriviallyDeriveDebug; use ir::comp::CompKind; @@ -99,24 +98,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> { fn new(ctx: &'ctx BindgenContext<'gen>) -> CannotDeriveDebug<'ctx, 'gen> { let cannot_derive_debug = HashSet::new(); - let mut dependencies = HashMap::new(); - - for &item in ctx.whitelisted_items() { - dependencies.entry(item).or_insert(vec![]); - - { - // We reverse our natural IR graph edges to find dependencies - // between nodes. - item.trace(ctx, &mut |sub_item: ItemId, edge_kind| { - if ctx.whitelisted_items().contains(&sub_item) && - Self::consider_edge(edge_kind) { - dependencies.entry(sub_item) - .or_insert(vec![]) - .push(item); - } - }, &()); - } - } + let dependencies = generate_dependencies(ctx, Self::consider_edge); CannotDeriveDebug { ctx, diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs index d6287742..47c9ee15 100644 --- a/src/ir/analysis/has_vtable.rs +++ b/src/ir/analysis/has_vtable.rs @@ -1,11 +1,10 @@ //! Determining which types has vtable -use super::{ConstrainResult, MonotoneFramework}; +use super::{ConstrainResult, MonotoneFramework, generate_dependencies}; use std::collections::HashSet; use std::collections::HashMap; use ir::context::{BindgenContext, ItemId}; use ir::traversal::EdgeKind; use ir::ty::TypeKind; -use ir::traversal::Trace; /// An analysis that finds for each IR item whether it has vtable or not /// @@ -68,24 +67,7 @@ impl<'ctx, 'gen> MonotoneFramework for HasVtableAnalysis<'ctx, 'gen> { fn new(ctx: &'ctx BindgenContext<'gen>) -> HasVtableAnalysis<'ctx, 'gen> { let have_vtable = HashSet::new(); - let mut dependencies = HashMap::new(); - - for &item in ctx.whitelisted_items() { - dependencies.entry(item).or_insert(vec![]); - - { - // We reverse our natural IR graph edges to find dependencies - // between nodes. - item.trace(ctx, &mut |sub_item: ItemId, edge_kind| { - if ctx.whitelisted_items().contains(&sub_item) && - Self::consider_edge(edge_kind) { - dependencies.entry(sub_item) - .or_insert(vec![]) - .push(item); - } - }, &()); - } - } + let dependencies = generate_dependencies(ctx, Self::consider_edge); HasVtableAnalysis { ctx, diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs index 11467438..8a00ecce 100644 --- a/src/ir/analysis/mod.rs +++ b/src/ir/analysis/mod.rs @@ -46,6 +46,9 @@ mod has_vtable; pub use self::has_vtable::HasVtableAnalysis; pub use self::has_vtable::HasVtable; +use ir::context::{BindgenContext, ItemId}; +use ir::traversal::{EdgeKind, Trace}; +use std::collections::HashMap; use std::fmt; /// An analysis in the monotone framework. @@ -134,6 +137,30 @@ pub fn analyze<Analysis>(extra: Analysis::Extra) -> Analysis::Output analysis.into() } +/// Generate the dependency map for analysis +pub fn generate_dependencies<F>(ctx: &BindgenContext, consider_edge: F) -> HashMap<ItemId, Vec<ItemId>> + where F: Fn(EdgeKind) -> bool { + let mut dependencies = HashMap::new(); + + for &item in ctx.whitelisted_items() { + dependencies.entry(item).or_insert(vec![]); + + { + // We reverse our natural IR graph edges to find dependencies + // between nodes. + item.trace(ctx, &mut |sub_item: ItemId, edge_kind| { + if ctx.whitelisted_items().contains(&sub_item) && + consider_edge(edge_kind) { + dependencies.entry(sub_item) + .or_insert(vec![]) + .push(item); + } + }, &()); + } + } + dependencies +} + #[cfg(test)] mod tests { use super::*; |