diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /vendor/windows-bindgen/src/classes.rs | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/windows-bindgen/src/classes.rs')
-rw-r--r-- | vendor/windows-bindgen/src/classes.rs | 215 |
1 files changed, 0 insertions, 215 deletions
diff --git a/vendor/windows-bindgen/src/classes.rs b/vendor/windows-bindgen/src/classes.rs deleted file mode 100644 index 3cdf50006..000000000 --- a/vendor/windows-bindgen/src/classes.rs +++ /dev/null @@ -1,215 +0,0 @@ -use super::*; - -pub fn gen(gen: &Gen, def: TypeDef) -> TokenStream { - if gen.sys { - if gen.reader.type_def_has_default_interface(def) { - let name = to_ident(gen.reader.type_def_name(def)); - quote! { - pub type #name = *mut ::core::ffi::c_void; - } - } else { - quote! {} - } - } else { - gen_class(gen, def) - } -} - -fn gen_class(gen: &Gen, def: TypeDef) -> TokenStream { - if gen.reader.type_def_extends(def) == TypeName::Attribute { - return TokenStream::new(); - } - - let name = to_ident(gen.reader.type_def_name(def)); - let interfaces = gen - .reader - .type_interfaces(&Type::TypeDef((def, Vec::new()))); - let mut methods = quote! {}; - let mut method_names = MethodNames::new(); - - let cfg = gen.reader.type_def_cfg(def, &[]); - let doc = gen.cfg_doc(&cfg); - let features = gen.cfg_features(&cfg); - - for interface in &interfaces { - if let Type::TypeDef((def, generics)) = &interface.ty { - let mut virtual_names = MethodNames::new(); - - for method in gen.reader.type_def_methods(*def) { - methods.combine(&winrt_methods::gen( - gen, - *def, - generics, - interface.kind, - method, - &mut method_names, - &mut virtual_names, - )); - } - } - } - - let factories = interfaces.iter().filter_map(|interface| match interface.kind { - InterfaceKind::Static => { - if let Type::TypeDef((def, generics)) = &interface.ty { - if gen.reader.type_def_methods(*def).next().is_some() { - let interface_type = gen.type_name(&interface.ty); - let features = gen.cfg_features(&gen.reader.type_def_cfg(*def, generics)); - - let hidden = if gen.doc { - quote! { #[doc(hidden)] } - } else { - quote! {} - }; - - return Some(quote! { - #hidden - #features - pub fn #interface_type<R, F: FnOnce(&#interface_type) -> ::windows::core::Result<R>>( - callback: F, - ) -> ::windows::core::Result<R> { - static SHARED: ::windows::imp::FactoryCache<#name, #interface_type> = - ::windows::imp::FactoryCache::new(); - SHARED.call(callback) - } - }); - } - } - None - } - _ => None, - }); - - if gen.reader.type_def_has_default_interface(def) { - let new = if gen.reader.type_def_has_default_constructor(def) { - quote! { - pub fn new() -> ::windows::core::Result<Self> { - Self::IActivationFactory(|f| f.ActivateInstance::<Self>()) - } - fn IActivationFactory<R, F: FnOnce(&::windows::imp::IGenericFactory) -> ::windows::core::Result<R>>( - callback: F, - ) -> ::windows::core::Result<R> { - static SHARED: ::windows::imp::FactoryCache<#name, ::windows::imp::IGenericFactory> = - ::windows::imp::FactoryCache::new(); - SHARED.call(callback) - } - } - } else { - quote! {} - }; - - let mut tokens = quote! { - #doc - #features - #[repr(transparent)] - pub struct #name(::windows::core::IUnknown); - #features - impl #name { - #new - #methods - #(#factories)* - } - }; - - tokens.combine(&gen.interface_core_traits( - def, - &[], - &name, - &TokenStream::new(), - &TokenStream::new(), - &features, - )); - tokens.combine(&gen.interface_winrt_trait( - def, - &[], - &name, - &TokenStream::new(), - &TokenStream::new(), - &features, - )); - tokens.combine(&gen.interface_trait(def, &[], &name, &TokenStream::new(), &features, true)); - tokens.combine(&gen.runtime_name_trait(def, &[], &name, &TokenStream::new(), &features)); - tokens.combine(&gen.async_get( - def, - &[], - &name, - &TokenStream::new(), - &TokenStream::new(), - &features, - )); - tokens.combine(&iterators::gen( - gen, - def, - &[], - &name, - &TokenStream::new(), - &TokenStream::new(), - &cfg, - )); - tokens.combine(&gen_conversions(gen, def, &name, &interfaces, &cfg)); - tokens.combine(&gen.agile(def, &name, &TokenStream::new(), &features)); - tokens - } else { - let mut tokens = quote! { - #doc - #features - pub struct #name; - #features - impl #name { - #methods - #(#factories)* - } - }; - - tokens.combine(&gen.runtime_name_trait(def, &[], &name, &TokenStream::new(), &features)); - tokens - } -} - -fn gen_conversions( - gen: &Gen, - def: TypeDef, - name: &TokenStream, - interfaces: &[Interface], - cfg: &Cfg, -) -> TokenStream { - let features = gen.cfg_features(cfg); - let mut tokens = quote! { - #features - ::windows::imp::interface_hierarchy!(#name, ::windows::core::IUnknown, ::windows::core::IInspectable); - }; - - for interface in interfaces { - if gen.reader.type_is_exclusive(&interface.ty) { - continue; - } - - if interface.kind != InterfaceKind::Default - && interface.kind != InterfaceKind::None - && interface.kind != InterfaceKind::Base - { - continue; - } - - let into = gen.type_name(&interface.ty); - // TODO: simplify - maybe provide + operator? - let features = gen.cfg_features(&cfg.union(&gen.reader.type_cfg(&interface.ty))); - - tokens.combine("e! { - #features - impl ::windows::core::CanTryInto<#into> for #name {} - }); - } - - for def in gen.reader.type_def_bases(def) { - let into = gen.type_def_name(def, &[]); - let features = gen.cfg_features(&cfg.union(&gen.reader.type_def_cfg(def, &[]))); - - tokens.combine("e! { - #features - impl ::windows::core::CanTryInto<#into> for #name {} - }); - } - - tokens -} |