-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathdeps.rs
99 lines (94 loc) · 3.37 KB
/
deps.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use crate::{
conversion::api::{Api, TypeKind},
types::QualifiedName,
};
use super::{
fun::{FnPhase, FnPrePhase1, PodAndDepAnalysis},
pod::PodAnalysis,
tdef::TypedefAnalysis,
};
pub(crate) trait HasDependencies {
fn deps(&self) -> Box<dyn Iterator<Item = &QualifiedName> + '_>;
}
impl HasDependencies for Api<FnPrePhase1> {
fn deps(&self) -> Box<dyn Iterator<Item = &QualifiedName> + '_> {
match self {
Api::Typedef {
old_tyname,
analysis: TypedefAnalysis { deps, .. },
..
} => Box::new(old_tyname.iter().chain(deps.iter())),
Api::Struct {
analysis: PodAnalysis {
bases, field_deps, ..
},
..
} => Box::new(field_deps.iter().chain(bases.iter())),
Api::Function { analysis, .. } => Box::new(analysis.deps.iter()),
Api::Subclass {
name: _,
superclass,
..
} => Box::new(std::iter::once(superclass)),
Api::RustSubclassFn { details, .. } => Box::new(details.dependencies.iter()),
Api::RustFn { deps, .. } => Box::new(deps.iter()),
_ => Box::new(std::iter::empty()),
}
}
}
impl HasDependencies for Api<FnPhase> {
/// Any dependencies on other APIs which this API has.
fn deps(&self) -> Box<dyn Iterator<Item = &QualifiedName> + '_> {
match self {
Api::Typedef {
old_tyname,
analysis: TypedefAnalysis { deps, .. },
..
} => Box::new(old_tyname.iter().chain(deps.iter())),
Api::Struct {
analysis:
PodAndDepAnalysis {
pod:
PodAnalysis {
kind: TypeKind::Pod,
bases,
field_deps,
..
},
constructor_and_allocator_deps,
..
},
..
} => Box::new(
field_deps
.iter()
.chain(bases.iter())
.chain(constructor_and_allocator_deps.iter()),
),
Api::Struct {
analysis:
PodAndDepAnalysis {
constructor_and_allocator_deps,
..
},
..
} => Box::new(constructor_and_allocator_deps.iter()),
Api::Function { analysis, .. } => Box::new(analysis.deps.iter()),
Api::Subclass {
name: _,
superclass,
..
} => Box::new(std::iter::once(superclass)),
Api::RustSubclassFn { details, .. } => Box::new(details.dependencies.iter()),
Api::RustFn { deps, .. } => Box::new(deps.iter()),
_ => Box::new(std::iter::empty()),
}
}
}