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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use prelude::*;
use super::common::*;
use idents;
use utils;
use model;
use tyhandlers::{ModelTypeSystem};
pub fn expand_com_class(
attr_tokens: TokenStreamNightly,
item_tokens: TokenStreamNightly,
) -> Result<TokenStreamNightly, model::ParseError>
{
let mut output = vec![];
let cls = model::ComStruct::parse(
&lib_name(), attr_tokens.into(), &item_tokens.to_string() )?;
let struct_ident = cls.name();
let mut query_interface_match_arms = vec![
quote!(
::intercom::IID_IUnknown =>
( &vtables._ISupportErrorInfo )
as *const &::intercom::ISupportErrorInfoVtbl
as *mut &::intercom::ISupportErrorInfoVtbl
as ::intercom::RawComPtr
),
quote!(
::intercom::IID_ISupportErrorInfo =>
( &vtables._ISupportErrorInfo )
as *const &::intercom::ISupportErrorInfoVtbl
as *mut &::intercom::ISupportErrorInfoVtbl
as ::intercom::RawComPtr
) ];
let mut support_error_info_match_arms = vec![] ;
let isupporterrorinfo_ident = Ident::new( "ISupportErrorInfo", Span::call_site() );
let isupporterrorinfo_vtable_instance_ident =
idents::vtable_instance( &struct_ident, &isupporterrorinfo_ident );
let mut vtable_list_field_decls = vec![
quote!( _ISupportErrorInfo : &'static ::intercom::ISupportErrorInfoVtbl ) ];
let mut vtable_list_field_values = vec![
quote!( _ISupportErrorInfo : &#isupporterrorinfo_vtable_instance_ident ) ];
for itf in cls.interfaces() {
for &ts in &[ ModelTypeSystem::Automation, ModelTypeSystem::Raw ] {
let itf_variant = Ident::new( &format!( "{}_{:?}", itf, ts ), Span::call_site() );
let offset_ident = idents::vtable_offset( struct_ident, &itf_variant );
let iid_ident = idents::iid( &itf_variant );
let vtable_struct_ident = idents::vtable_struct( &itf_variant );
let vtable_instance_ident = idents::vtable_instance( struct_ident, &itf_variant );
output.push( quote!(
#[inline(always)]
#[allow(non_snake_case)]
fn #offset_ident() -> usize {
unsafe {
&::intercom::ComBox::< #struct_ident >::null_vtable().#itf_variant
as *const _ as usize
}
}
) );
vtable_list_field_decls.push(
quote!( #itf_variant : &'static #vtable_struct_ident ) );
vtable_list_field_values.push(
quote!( #itf_variant : &#vtable_instance_ident ) );
query_interface_match_arms.push( quote!(
self::#iid_ident => &vtables.#itf_variant
as *const &#vtable_struct_ident
as *mut &#vtable_struct_ident
as ::intercom::RawComPtr
) );
support_error_info_match_arms.push( quote!(
self::#iid_ident => true
) );
} }
output.push( quote!(
#[allow(non_upper_case_globals)]
const #isupporterrorinfo_vtable_instance_ident
: ::intercom::ISupportErrorInfoVtbl
= ::intercom::ISupportErrorInfoVtbl {
__base : ::intercom::IUnknownVtbl {
query_interface_Automation
: ::intercom::ComBox::< #struct_ident >
::query_interface_ptr,
add_ref_Automation
: ::intercom::ComBox::< #struct_ident >
::add_ref_ptr,
release_Automation
: ::intercom::ComBox::< #struct_ident >
::release_ptr,
},
interface_supports_error_info_Automation
: ::intercom::ComBox::< #struct_ident >
::interface_supports_error_info_ptr,
};
) );
output.push( quote!(
impl ::intercom::HasInterface< ::intercom::IUnknown > for #struct_ident {}
) );
let vtable_list_ident = idents::vtable_list( &struct_ident );
let visibility = cls.visibility();
output.push( quote!(
#[allow(non_snake_case)]
#[doc(hidden)]
#visibility struct #vtable_list_ident {
#( #vtable_list_field_decls ),*
}
) );
output.push( quote!(
impl ::intercom::CoClass for #struct_ident {
type VTableList = #vtable_list_ident;
fn create_vtable_list() -> Self::VTableList {
#vtable_list_ident {
#( #vtable_list_field_values ),*
}
}
fn query_interface(
vtables : &Self::VTableList,
riid : ::intercom::REFIID,
) -> ::intercom::RawComResult< ::intercom::RawComPtr > {
if riid.is_null() { return Err( ::intercom::raw::E_NOINTERFACE ) }
Ok( match *unsafe { &*riid } {
#( #query_interface_match_arms ),*,
_ => return Err( ::intercom::raw::E_NOINTERFACE )
} )
}
fn interface_supports_error_info(
riid : ::intercom::REFIID
) -> bool
{
match *unsafe { &*riid } {
#( #support_error_info_match_arms ),*,
_ => false
}
}
}
) );
let clsid_ident = idents::clsid( struct_ident );
if let Some( ref guid ) = *cls.clsid() {
let clsid_guid_tokens = utils::get_guid_tokens( guid );
let clsid_doc = format!( "`{}` class ID.", struct_ident );
let clsid_const = quote!(
#[allow(non_upper_case_globals)]
#[doc = #clsid_doc ]
pub const #clsid_ident : ::intercom::CLSID = #clsid_guid_tokens;
);
output.push( clsid_const );
}
Ok( tokens_to_tokenstream( item_tokens, output ) )
}