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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use super::*;
pub fn gen_interface(def: &TypeDef, gen: &Gen, include: TypeInclude) -> TokenStream {
let name = gen_type_name(def, gen);
let struct_phantoms = gen_phantoms(def);
let constraints = gen_constraints(def);
let type_signature = gen_guid_signature(def, &format!("{{{:#?}}}", def.guid()));
let guid = gen_type_guid(def, gen);
if include == TypeInclude::Full {
let abi_name = gen_abi_name(def, gen);
let abi_phantoms = gen_phantoms(def);
let abi_signatures = def.methods().map(|method| {
let signature = method.signature(&def.generics);
let features = method_features(&signature, gen);
let not_features = not_method_features(&signature, gen);
let signature = gen_winrt_abi(&signature, gen);
if features.is_empty() {
quote! {
pub unsafe extern "system" fn #signature,
}
} else {
quote! {
#features
pub unsafe extern "system" fn #signature,
#not_features
usize,
}
}
});
let is_exclusive = def.is_exclusive();
let hidden = if is_exclusive {
quote! { #[doc(hidden)] }
} else {
quote! {}
};
let public_type = if is_exclusive {
TokenStream::new()
} else {
let interfaces = interfaces(def);
let methods = InterfaceInfo::gen_methods(&interfaces, gen);
let (async_get, future) = gen_async(def, &interfaces, gen);
let object = gen_object(&name, &constraints, &TokenStream::new());
let iterator = gen_iterator(def, &interfaces, gen);
let send_sync = if async_kind(def) == AsyncKind::None {
quote! {}
} else {
quote! {
unsafe impl<#constraints> ::std::marker::Send for #name {}
unsafe impl<#constraints> ::std::marker::Sync for #name {}
}
};
let conversions = interfaces.iter().filter(|interface| interface.kind != InterfaceKind::Default).map(|interface| interface.gen_conversion(&name, &constraints, &BTreeSet::new(), gen));
quote! {
impl<#constraints> #name {
#methods
#async_get
}
unsafe impl<#constraints> ::windows::runtime::RuntimeType for #name {
const SIGNATURE: ::windows::runtime::ConstBuffer = #type_signature;
}
#future
#object
#(#conversions)*
#send_sync
#iterator
}
};
quote! {
#[repr(transparent)]
#[derive(::std::cmp::PartialEq, ::std::cmp::Eq, ::std::clone::Clone, ::std::fmt::Debug)]
#hidden
pub struct #name(::windows::runtime::IInspectable, #(#struct_phantoms,)*) where #constraints;
unsafe impl<#constraints> ::windows::runtime::Interface for #name {
type Vtable = #abi_name;
const IID: ::windows::runtime::GUID = #guid;
}
#public_type
#[repr(C)]
#[doc(hidden)]
pub struct #abi_name(
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr, iid: &::windows::runtime::GUID, interface: *mut ::windows::runtime::RawPtr) -> ::windows::runtime::HRESULT,
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr) -> u32,
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr) -> u32,
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr, count: *mut u32, values: *mut *mut ::windows::runtime::GUID) -> ::windows::runtime::HRESULT,
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr, value: *mut ::windows::runtime::RawPtr) -> ::windows::runtime::HRESULT,
pub unsafe extern "system" fn(this: ::windows::runtime::RawPtr, value: *mut i32) -> ::windows::runtime::HRESULT,
#(#abi_signatures)*
#(pub #abi_phantoms,)*
) where #constraints;
}
} else {
quote! {
#[repr(transparent)]
#[derive(::std::cmp::PartialEq, ::std::cmp::Eq, ::std::clone::Clone, ::std::fmt::Debug)]
#[doc(hidden)]
pub struct #name(::windows::runtime::IInspectable, #(#struct_phantoms,)*) where #constraints;
unsafe impl<#constraints> ::windows::runtime::Interface for #name {
type Vtable = <::windows::runtime::IUnknown as ::windows::runtime::Interface>::Vtable;
const IID: ::windows::runtime::GUID = #guid;
}
unsafe impl<#constraints> ::windows::runtime::RuntimeType for #name {
const SIGNATURE: ::windows::runtime::ConstBuffer = #type_signature;
}
}
}
}
fn interfaces(def: &TypeDef) -> Vec<InterfaceInfo> {
fn add_interfaces(result: &mut Vec<InterfaceInfo>, parent: &TypeDef, is_base: bool) {
for child in parent.interface_impls() {
if let ElementType::TypeDef(def) = child.generic_interface(&parent.generics) {
if !result.iter().any(|info| info.def == def) {
add_interfaces(result, &def, is_base);
let version = def.version();
result.push(InterfaceInfo { def, kind: InterfaceKind::NonDefault, is_base: false, version });
}
}
}
}
let mut result = vec![InterfaceInfo { def: def.clone(), kind: InterfaceKind::Default, is_base: false, version: def.version() }];
add_interfaces(&mut result, def, false);
InterfaceInfo::sort(&mut result);
result
}