-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspecification.rs
97 lines (86 loc) · 2.75 KB
/
specification.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
use fnv::{FnvHashMap};
use serde::Deserialize;
pub type Specification = FnvHashMap<String, Definition>;
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct Definition {
pub classinfo: Option<ClassInfo>,
#[serde(rename = "static")]
pub static_traits: Option<TraitList>,
#[serde(rename = "instance")]
pub instance_traits: Option<TraitList>,
#[serde(rename = "prototype")]
pub prototype: Option<TraitList>,
pub constructor: Option<ConstructorInfo>,
}
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct TraitList {
#[serde(rename = "const")]
pub constants: FnvHashMap<String, VariableInfo>,
#[serde(rename = "var")]
pub variables: FnvHashMap<String, VariableInfo>,
pub function: FnvHashMap<String, FunctionInfo>,
pub getter: FnvHashMap<String, VariableInfo>,
pub setter: FnvHashMap<String, VariableInfo>,
}
impl TraitList {
pub fn names(&self) -> FnvHashMap<&str, (bool, &'static str)> {
let mut result: FnvHashMap<&str, (bool, &'static str)> = FnvHashMap::default();
for (key, value) in self.constants.iter() {
result.insert(key, (value.stubbed, ""));
}
for (key, value) in self.variables.iter() {
result.insert(key, (value.stubbed, ""));
}
for (key, value) in self.function.iter() {
result.insert(key, (value.stubbed, "()"));
}
for (key, value) in self.getter.iter() {
result.insert(key, (value.stubbed, ""));
}
for (key, value) in self.setter.iter() {
result.insert(key, (value.stubbed, ""));
}
result
}
}
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct ParamInfo {
#[serde(rename = "type")]
pub type_info: String,
#[serde(rename = "default")]
pub value: Option<String>,
pub variadic: bool,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FunctionInfo {
pub args: Vec<ParamInfo>,
pub returns: String,
#[serde(default)]
pub stubbed: bool,
}
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct ClassInfo {
pub dynamic: bool,
pub extends: Option<String>,
pub implements: Option<String>,
#[serde(rename = "final")]
pub is_final: bool,
}
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct VariableInfo {
#[serde(rename = "type")]
pub type_info: Option<String>,
pub value: Option<String>,
pub stubbed: bool,
}
#[derive(Deserialize, Default)]
#[serde(default, deny_unknown_fields)]
pub struct ConstructorInfo {
pub args: Vec<ParamInfo>,
}