зеркало из https://github.com/microsoft/com-rs.git
Move all macros support functions to one library
This commit is contained in:
Родитель
d215a96821
Коммит
69fe618fbb
|
@ -1,11 +1,11 @@
|
|||
[package]
|
||||
name = "com"
|
||||
version = "0.0.1"
|
||||
authors = ["Microsoft Corp"]
|
||||
version = "0.1.0"
|
||||
authors = ["Microsoft Corp."]
|
||||
edition = "2018"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3", features = ["winuser", "winreg", "winerror", "winnt", "libloaderapi", "olectl", "objbase",] }
|
||||
|
||||
[dependencies]
|
||||
macros = { path="macros" }
|
||||
com_macros = { path = "macros" }
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "macros"
|
||||
name = "com_macros"
|
||||
version = "0.1.0"
|
||||
authors = ["adrianwithah <lim.weiheng.hadrian@gmail.com>"]
|
||||
authors = ["Microsoft Corp."]
|
||||
edition = "2018"
|
||||
autotests = false
|
||||
|
||||
|
@ -18,8 +18,5 @@ com = { path = ".." }
|
|||
|
||||
[dependencies]
|
||||
syn = { version = "1.0.5", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0.1"
|
||||
com_interface = { path = "com_interface" }
|
||||
co_class = { path = "co_class" }
|
||||
aggr_co_class = { path = "aggr_co_class" }
|
||||
com_macros_support = { path = "support" }
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "aggr_co_class"
|
||||
version = "0.1.0"
|
||||
authors = ["adrianwithah <lim.weiheng.hadrian@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "1.0.5", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0.1"
|
||||
macro_utils = { path = "../macro_utils" }
|
||||
co_class = { path = "../co_class" }
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "co_class"
|
||||
version = "0.1.0"
|
||||
authors = ["adrianwithah <lim.weiheng.hadrian@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "1.0.5", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0.1"
|
||||
macro_utils = { path = "../macro_utils" }
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "com_interface"
|
||||
version = "0.1.0"
|
||||
authors = ["adrianwithah <lim.weiheng.hadrian@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "1.0.5", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0.1"
|
||||
macro_utils = { path = "../macro_utils" }
|
|
@ -1,6 +1,6 @@
|
|||
use aggr_co_class::expand_aggr_co_class;
|
||||
use co_class::expand_co_class;
|
||||
use com_interface::{expand_com_interface, expand_derive};
|
||||
use com_macros_support::aggr_co_class::expand_aggr_co_class;
|
||||
use com_macros_support::co_class::expand_co_class;
|
||||
use com_macros_support::com_interface::{expand_com_interface, expand_derive};
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "macro_utils"
|
||||
name = "com_macros_support"
|
||||
version = "0.1.0"
|
||||
authors = ["adrianwithah <lim.weiheng.hadrian@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
@ -7,3 +7,4 @@ edition = "2018"
|
|||
[dependencies]
|
||||
syn = { version = "1.0.5", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0.1"
|
|
@ -5,21 +5,21 @@ use syn::ItemStruct;
|
|||
// We manually generate a ClassFactory without macros, otherwise
|
||||
// it leads to an infinite loop.
|
||||
pub fn generate(struct_item: &ItemStruct) -> HelperTokenStream {
|
||||
let base_interface_idents = co_class::class_factory::get_class_factory_base_interface_idents();
|
||||
let aggr_map = co_class::class_factory::get_class_factory_aggr_map();
|
||||
let base_interface_idents = crate::co_class::class_factory::get_class_factory_base_interface_idents();
|
||||
let aggr_map = crate::co_class::class_factory::get_class_factory_aggr_map();
|
||||
|
||||
let struct_ident = &struct_item.ident;
|
||||
let class_factory_ident = macro_utils::class_factory_ident(&struct_ident);
|
||||
let class_factory_ident = crate::utils::class_factory_ident(&struct_ident);
|
||||
|
||||
let struct_definition =
|
||||
co_class::class_factory::gen_class_factory_struct_definition(&class_factory_ident);
|
||||
let lock_server = co_class::class_factory::gen_lock_server();
|
||||
let iunknown_impl = co_class::class_factory::gen_iunknown_impl(
|
||||
crate::co_class::class_factory::gen_class_factory_struct_definition(&class_factory_ident);
|
||||
let lock_server = crate::co_class::class_factory::gen_lock_server();
|
||||
let iunknown_impl = crate::co_class::class_factory::gen_iunknown_impl(
|
||||
&base_interface_idents,
|
||||
&aggr_map,
|
||||
&class_factory_ident,
|
||||
);
|
||||
let class_factory_impl = co_class::class_factory::gen_class_factory_impl(
|
||||
let class_factory_impl = crate::co_class::class_factory::gen_class_factory_impl(
|
||||
&base_interface_idents,
|
||||
&class_factory_ident,
|
||||
);
|
|
@ -1,3 +1,4 @@
|
|||
use crate::co_class;
|
||||
use proc_macro2::TokenStream as HelperTokenStream;
|
||||
use quote::quote;
|
||||
use std::collections::HashMap;
|
||||
|
@ -20,8 +21,9 @@ pub fn generate(
|
|||
let aggregate_fields = co_class::com_struct::gen_aggregate_fields(aggr_map);
|
||||
|
||||
// COM Fields for an aggregable coclass.
|
||||
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
|
||||
let iunknown_to_use_field_ident = macro_utils::iunknown_to_use_field_ident();
|
||||
let non_delegating_iunknown_field_ident =
|
||||
crate::utils::non_delegating_iunknown_field_ident();
|
||||
let iunknown_to_use_field_ident = crate::utils::iunknown_to_use_field_ident();
|
||||
|
||||
quote!(
|
||||
#[repr(C)]
|
|
@ -18,8 +18,9 @@ pub fn generate(
|
|||
let allocate_fn = gen_allocate_fn(aggr_map, base_interface_idents, struct_item);
|
||||
let set_iunknown_fn = gen_set_iunknown_fn();
|
||||
let inner_iunknown_fns = gen_inner_iunknown_fns(base_interface_idents, aggr_map, struct_ident);
|
||||
let get_class_object_fn = co_class::com_struct_impl::gen_get_class_object_fn(struct_item);
|
||||
let set_aggregate_fns = co_class::com_struct_impl::gen_set_aggregate_fns(aggr_map);
|
||||
let get_class_object_fn =
|
||||
crate::co_class::com_struct_impl::gen_get_class_object_fn(struct_item);
|
||||
let set_aggregate_fns = crate::co_class::com_struct_impl::gen_set_aggregate_fns(aggr_map);
|
||||
|
||||
quote!(
|
||||
impl #struct_ident {
|
||||
|
@ -35,8 +36,8 @@ pub fn generate(
|
|||
/// Function that should only be used by Class Object, to set the
|
||||
/// object's iunknown_to_use, if the object is going to get aggregated.
|
||||
fn gen_set_iunknown_fn() -> HelperTokenStream {
|
||||
let iunknown_to_use_field_ident = macro_utils::iunknown_to_use_field_ident();
|
||||
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
|
||||
let iunknown_to_use_field_ident = crate::utils::iunknown_to_use_field_ident();
|
||||
let non_delegating_iunknown_field_ident = crate::utils::non_delegating_iunknown_field_ident();
|
||||
|
||||
quote!(
|
||||
pub(crate) fn set_iunknown(&mut self, aggr: *mut *const <dyn com::interfaces::iunknown::IUnknown as com::ComInterface>::VTable) {
|
||||
|
@ -68,7 +69,7 @@ fn gen_inner_iunknown_fns(
|
|||
}
|
||||
|
||||
pub fn gen_inner_add_ref() -> HelperTokenStream {
|
||||
let add_ref_implementation = co_class::iunknown_impl::gen_add_ref_implementation();
|
||||
let add_ref_implementation = crate::co_class::iunknown_impl::gen_add_ref_implementation();
|
||||
|
||||
quote! {
|
||||
pub(crate) fn inner_add_ref(&self) -> u32 {
|
||||
|
@ -82,18 +83,21 @@ pub fn gen_inner_release(
|
|||
aggr_map: &HashMap<Ident, Vec<Ident>>,
|
||||
struct_ident: &Ident,
|
||||
) -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
|
||||
let release_decrement = co_class::iunknown_impl::gen_release_decrement(&ref_count_ident);
|
||||
let release_decrement = crate::co_class::iunknown_impl::gen_release_decrement(&ref_count_ident);
|
||||
let release_assign_new_count_to_var =
|
||||
co_class::iunknown_impl::gen_release_assign_new_count_to_var(
|
||||
crate::co_class::iunknown_impl::gen_release_assign_new_count_to_var(
|
||||
&ref_count_ident,
|
||||
&ref_count_ident,
|
||||
);
|
||||
let release_new_count_var_zero_check =
|
||||
co_class::iunknown_impl::gen_new_count_var_zero_check(&ref_count_ident);
|
||||
let release_drops =
|
||||
co_class::iunknown_impl::gen_release_drops(base_interface_idents, aggr_map, struct_ident);
|
||||
crate::co_class::iunknown_impl::gen_new_count_var_zero_check(&ref_count_ident);
|
||||
let release_drops = crate::co_class::iunknown_impl::gen_release_drops(
|
||||
base_interface_idents,
|
||||
aggr_map,
|
||||
struct_ident,
|
||||
);
|
||||
let non_delegating_iunknown_drop = gen_non_delegating_iunknown_drop();
|
||||
|
||||
quote! {
|
||||
|
@ -111,7 +115,7 @@ pub fn gen_inner_release(
|
|||
}
|
||||
|
||||
fn gen_non_delegating_iunknown_drop() -> HelperTokenStream {
|
||||
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
|
||||
let non_delegating_iunknown_field_ident = crate::utils::non_delegating_iunknown_field_ident();
|
||||
quote!(
|
||||
Box::from_raw(self.#non_delegating_iunknown_field_ident as *mut <dyn com::interfaces::iunknown::IUnknown as com::ComInterface>::VTable);
|
||||
)
|
||||
|
@ -122,13 +126,14 @@ fn gen_inner_query_interface(
|
|||
base_interface_idents: &[Ident],
|
||||
aggr_map: &HashMap<Ident, Vec<Ident>>,
|
||||
) -> HelperTokenStream {
|
||||
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
|
||||
let non_delegating_iunknown_field_ident = crate::utils::non_delegating_iunknown_field_ident();
|
||||
|
||||
// Generate match arms for implemented interfaces
|
||||
let base_match_arms = co_class::iunknown_impl::gen_base_match_arms(base_interface_idents);
|
||||
let base_match_arms =
|
||||
crate::co_class::iunknown_impl::gen_base_match_arms(base_interface_idents);
|
||||
|
||||
// Generate match arms for aggregated interfaces
|
||||
let aggr_match_arms = co_class::iunknown_impl::gen_aggregate_match_arms(aggr_map);
|
||||
let aggr_match_arms = crate::co_class::iunknown_impl::gen_aggregate_match_arms(aggr_map);
|
||||
|
||||
quote!(
|
||||
pub(crate) fn inner_query_interface(&self, riid: *const winapi::shared::guiddef::IID, ppv: *mut *mut winapi::ctypes::c_void) -> HRESULT {
|
||||
|
@ -159,22 +164,26 @@ fn gen_allocate_fn(
|
|||
) -> HelperTokenStream {
|
||||
let struct_ident = &struct_item.ident;
|
||||
|
||||
let base_inits =
|
||||
co_class::com_struct_impl::gen_allocate_base_inits(struct_ident, base_interface_idents);
|
||||
let base_inits = crate::co_class::com_struct_impl::gen_allocate_base_inits(
|
||||
struct_ident,
|
||||
base_interface_idents,
|
||||
);
|
||||
|
||||
// Allocate function signature
|
||||
let allocate_parameters =
|
||||
co_class::com_struct_impl::gen_allocate_function_parameters_signature(struct_item);
|
||||
crate::co_class::com_struct_impl::gen_allocate_function_parameters_signature(struct_item);
|
||||
|
||||
// Syntax for instantiating the fields of the struct.
|
||||
let base_fields = co_class::com_struct_impl::gen_allocate_base_fields(base_interface_idents);
|
||||
let ref_count_field = co_class::com_struct_impl::gen_allocate_ref_count_field();
|
||||
let user_fields = co_class::com_struct_impl::gen_allocate_user_fields(struct_item);
|
||||
let aggregate_fields = co_class::com_struct_impl::gen_allocate_aggregate_fields(aggr_map);
|
||||
let base_fields =
|
||||
crate::co_class::com_struct_impl::gen_allocate_base_fields(base_interface_idents);
|
||||
let ref_count_field = crate::co_class::com_struct_impl::gen_allocate_ref_count_field();
|
||||
let user_fields = crate::co_class::com_struct_impl::gen_allocate_user_fields(struct_item);
|
||||
let aggregate_fields =
|
||||
crate::co_class::com_struct_impl::gen_allocate_aggregate_fields(aggr_map);
|
||||
|
||||
// Aggregable COM struct specific fields
|
||||
let iunknown_to_use_field_ident = macro_utils::iunknown_to_use_field_ident();
|
||||
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
|
||||
let iunknown_to_use_field_ident = crate::utils::iunknown_to_use_field_ident();
|
||||
let non_delegating_iunknown_field_ident = crate::utils::non_delegating_iunknown_field_ident();
|
||||
let non_delegating_iunknown_offset = base_interface_idents.len();
|
||||
|
||||
quote!(
|
|
@ -7,7 +7,7 @@ use syn::ItemStruct;
|
|||
/// delegate to the interface pointer at __iunknown_to_use.
|
||||
pub fn generate(struct_item: &ItemStruct) -> HelperTokenStream {
|
||||
let struct_ident = &struct_item.ident;
|
||||
let iunknown_to_use_field_ident = macro_utils::iunknown_to_use_field_ident();
|
||||
let iunknown_to_use_field_ident = crate::utils::iunknown_to_use_field_ident();
|
||||
let ptr_casting = quote! { as *mut winapi::ctypes::c_void };
|
||||
|
||||
quote!(
|
|
@ -10,15 +10,15 @@ mod com_struct_impl;
|
|||
mod iunknown_impl;
|
||||
|
||||
pub fn expand_aggr_co_class(input: &ItemStruct, attr_args: &AttributeArgs) -> TokenStream {
|
||||
let base_interface_idents = macro_utils::base_interface_idents(attr_args);
|
||||
let aggr_interface_idents = macro_utils::get_aggr_map(attr_args);
|
||||
let base_interface_idents = crate::utils::base_interface_idents(attr_args);
|
||||
let aggr_interface_idents = crate::utils::get_aggr_map(attr_args);
|
||||
|
||||
let mut out: Vec<TokenStream> = Vec::new();
|
||||
out.push(com_struct::generate(&aggr_interface_idents, &base_interface_idents, input).into());
|
||||
out.push(
|
||||
com_struct_impl::generate(&base_interface_idents, &aggr_interface_idents, input).into(),
|
||||
);
|
||||
out.push(co_class::co_class_impl::generate(input).into());
|
||||
out.push(crate::co_class::co_class_impl::generate(input).into());
|
||||
out.push(iunknown_impl::generate(input).into());
|
||||
out.push(class_factory::generate(input).into());
|
||||
|
|
@ -25,7 +25,7 @@ pub fn generate(struct_item: &ItemStruct) -> HelperTokenStream {
|
|||
let aggr_map = get_class_factory_aggr_map();
|
||||
|
||||
let struct_ident = &struct_item.ident;
|
||||
let class_factory_ident = macro_utils::class_factory_ident(&struct_ident);
|
||||
let class_factory_ident = crate::utils::class_factory_ident(&struct_ident);
|
||||
|
||||
let struct_definition = gen_class_factory_struct_definition(&class_factory_ident);
|
||||
let lock_server = gen_lock_server();
|
||||
|
@ -69,9 +69,9 @@ pub fn generate(struct_item: &ItemStruct) -> HelperTokenStream {
|
|||
|
||||
// Can't use gen_base_fields here, since user might not have imported IClassFactory.
|
||||
pub fn gen_class_factory_struct_definition(class_factory_ident: &Ident) -> HelperTokenStream {
|
||||
let ref_count_field = crate::com_struct::gen_ref_count_field();
|
||||
let ref_count_field = super::com_struct::gen_ref_count_field();
|
||||
let interface_ident = get_iclass_factory_interface_ident();
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(&interface_ident);
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(&interface_ident);
|
||||
quote! {
|
||||
#[repr(C)]
|
||||
pub struct #class_factory_ident {
|
||||
|
@ -96,7 +96,7 @@ pub fn gen_iunknown_impl(
|
|||
class_factory_ident: &Ident,
|
||||
) -> HelperTokenStream {
|
||||
let query_interface = gen_query_interface();
|
||||
let add_ref = crate::iunknown_impl::gen_add_ref();
|
||||
let add_ref = super::iunknown_impl::gen_add_ref();
|
||||
let release = gen_release(&base_interface_idents, &aggr_map, class_factory_ident);
|
||||
quote! {
|
||||
impl com::interfaces::iunknown::IUnknown for #class_factory_ident {
|
||||
|
@ -112,17 +112,17 @@ pub fn gen_release(
|
|||
aggr_map: &HashMap<Ident, Vec<Ident>>,
|
||||
struct_ident: &Ident,
|
||||
) -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
|
||||
let release_decrement = crate::iunknown_impl::gen_release_decrement(&ref_count_ident);
|
||||
let release_assign_new_count_to_var = crate::iunknown_impl::gen_release_assign_new_count_to_var(
|
||||
let release_decrement = super::iunknown_impl::gen_release_decrement(&ref_count_ident);
|
||||
let release_assign_new_count_to_var = super::iunknown_impl::gen_release_assign_new_count_to_var(
|
||||
&ref_count_ident,
|
||||
&ref_count_ident,
|
||||
);
|
||||
let release_new_count_var_zero_check =
|
||||
crate::iunknown_impl::gen_new_count_var_zero_check(&ref_count_ident);
|
||||
super::iunknown_impl::gen_new_count_var_zero_check(&ref_count_ident);
|
||||
let release_drops =
|
||||
crate::iunknown_impl::gen_release_drops(base_interface_idents, aggr_map, struct_ident);
|
||||
super::iunknown_impl::gen_release_drops(base_interface_idents, aggr_map, struct_ident);
|
||||
|
||||
quote! {
|
||||
unsafe fn release(&self) -> u32 {
|
||||
|
@ -140,7 +140,7 @@ pub fn gen_release(
|
|||
}
|
||||
|
||||
fn gen_query_interface() -> HelperTokenStream {
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(&get_iclass_factory_interface_ident());
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(&get_iclass_factory_interface_ident());
|
||||
|
||||
quote! {
|
||||
unsafe fn query_interface(&self, riid: *const winapi::shared::guiddef::IID, ppv: *mut *mut winapi::ctypes::c_void) -> winapi::shared::winerror::HRESULT {
|
||||
|
@ -164,10 +164,10 @@ pub fn gen_class_factory_impl(
|
|||
base_interface_idents: &[Ident],
|
||||
class_factory_ident: &Ident,
|
||||
) -> HelperTokenStream {
|
||||
let ref_count_field = crate::com_struct_impl::gen_allocate_ref_count_field();
|
||||
let base_fields = crate::com_struct_impl::gen_allocate_base_fields(base_interface_idents);
|
||||
let ref_count_field = super::com_struct_impl::gen_allocate_ref_count_field();
|
||||
let base_fields = super::com_struct_impl::gen_allocate_base_fields(base_interface_idents);
|
||||
let base_inits =
|
||||
crate::com_struct_impl::gen_allocate_base_inits(class_factory_ident, base_interface_idents);
|
||||
super::com_struct_impl::gen_allocate_base_inits(class_factory_ident, base_interface_idents);
|
||||
|
||||
quote! {
|
||||
impl #class_factory_ident {
|
|
@ -36,14 +36,14 @@ pub fn generate(
|
|||
|
||||
pub fn gen_base_fields(base_interface_idents: &[Ident]) -> HelperTokenStream {
|
||||
let bases_interface_idents = base_interface_idents.iter().map(|base| {
|
||||
let field_ident = macro_utils::vptr_field_ident(&base);
|
||||
let field_ident = crate::utils::vptr_field_ident(&base);
|
||||
quote!(#field_ident: *const <dyn #base as com::ComInterface>::VTable)
|
||||
});
|
||||
quote!(#(#bases_interface_idents,)*)
|
||||
}
|
||||
|
||||
pub fn gen_ref_count_field() -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
quote!(#ref_count_ident: std::cell::Cell<u32>,)
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ pub fn gen_allocate_user_fields(struct_item: &ItemStruct) -> HelperTokenStream {
|
|||
|
||||
// Reference count field initialisation.
|
||||
pub fn gen_allocate_ref_count_field() -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
quote!(
|
||||
#ref_count_ident: std::cell::Cell::new(0),
|
||||
)
|
||||
|
@ -102,7 +102,7 @@ pub fn gen_allocate_ref_count_field() -> HelperTokenStream {
|
|||
// Generate the vptr field idents needed in the instantiation syntax of the COM struct.
|
||||
pub fn gen_allocate_base_fields(base_interface_idents: &[Ident]) -> HelperTokenStream {
|
||||
let base_fields = base_interface_idents.iter().map(|base| {
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(base);
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(base);
|
||||
quote!(#vptr_field_ident)
|
||||
});
|
||||
|
||||
|
@ -117,7 +117,7 @@ pub fn gen_allocate_base_inits(
|
|||
let mut offset_count: usize = 0;
|
||||
let base_inits = base_interface_idents.iter().map(|base| {
|
||||
let vtable_var_ident = format_ident!("{}_vtable", base.to_string().to_lowercase());
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(&base);
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(&base);
|
||||
|
||||
let out = quote!(
|
||||
let #vtable_var_ident = com::vtable!(#struct_ident: #base, #offset_count);
|
||||
|
@ -135,7 +135,7 @@ pub fn gen_allocate_base_inits(
|
|||
/// class object.
|
||||
pub fn gen_get_class_object_fn(struct_item: &ItemStruct) -> HelperTokenStream {
|
||||
let struct_ident = &struct_item.ident;
|
||||
let class_factory_ident = macro_utils::class_factory_ident(&struct_ident);
|
||||
let class_factory_ident = crate::utils::class_factory_ident(&struct_ident);
|
||||
|
||||
quote!(
|
||||
pub fn get_class_object() -> Box<#class_factory_ident> {
|
||||
|
@ -148,7 +148,7 @@ pub fn gen_set_aggregate_fns(aggr_map: &HashMap<Ident, Vec<Ident>>) -> HelperTok
|
|||
let mut fns = Vec::new();
|
||||
for (aggr_field_ident, aggr_base_interface_idents) in aggr_map.iter() {
|
||||
for base in aggr_base_interface_idents {
|
||||
let set_aggregate_fn_ident = macro_utils::set_aggregate_fn_ident(&base);
|
||||
let set_aggregate_fn_ident = crate::utils::set_aggregate_fn_ident(&base);
|
||||
fns.push(quote!(
|
||||
fn #set_aggregate_fn_ident(&mut self, aggr: com::InterfacePtr<dyn com::interfaces::iunknown::IUnknown>) {
|
||||
// TODO: What happens if we are overwriting an existing aggregate?
|
|
@ -37,7 +37,7 @@ pub fn gen_add_ref() -> HelperTokenStream {
|
|||
}
|
||||
|
||||
pub fn gen_add_ref_implementation() -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
quote!(
|
||||
let value = self.#ref_count_ident.get().checked_add(1).expect("Overflow of reference count");
|
||||
self.#ref_count_ident.set(value);
|
||||
|
@ -50,7 +50,7 @@ pub fn gen_release(
|
|||
aggr_map: &HashMap<Ident, Vec<Ident>>,
|
||||
struct_ident: &Ident,
|
||||
) -> HelperTokenStream {
|
||||
let ref_count_ident = macro_utils::ref_count_ident();
|
||||
let ref_count_ident = crate::utils::ref_count_ident();
|
||||
|
||||
let release_decrement = gen_release_decrement(&ref_count_ident);
|
||||
let release_assign_new_count_to_var =
|
||||
|
@ -102,7 +102,7 @@ fn gen_aggregate_drops(aggr_map: &HashMap<Ident, Vec<Ident>>) -> HelperTokenStre
|
|||
|
||||
fn gen_vptr_drops(base_interface_idents: &[Ident]) -> HelperTokenStream {
|
||||
let vptr_drops = base_interface_idents.iter().map(|base| {
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(&base);
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(&base);
|
||||
quote!(
|
||||
Box::from_raw(self.#vptr_field_ident as *mut <dyn #base as com::ComInterface>::VTable);
|
||||
)
|
||||
|
@ -143,7 +143,7 @@ pub fn gen_query_interface(
|
|||
base_interface_idents: &[Ident],
|
||||
aggr_map: &HashMap<Ident, Vec<Ident>>,
|
||||
) -> HelperTokenStream {
|
||||
let first_vptr_field = macro_utils::vptr_field_ident(&base_interface_idents[0]);
|
||||
let first_vptr_field = crate::utils::vptr_field_ident(&base_interface_idents[0]);
|
||||
|
||||
// Generate match arms for implemented interfaces
|
||||
let base_match_arms = gen_base_match_arms(base_interface_idents);
|
||||
|
@ -177,7 +177,7 @@ pub fn gen_base_match_arms(base_interface_idents: &[Ident]) -> HelperTokenStream
|
|||
let base_match_arms = base_interface_idents.iter().map(|base| {
|
||||
let match_condition =
|
||||
quote!(<dyn #base as com::ComInterface>::is_iid_in_inheritance_chain(riid));
|
||||
let vptr_field_ident = macro_utils::vptr_field_ident(&base);
|
||||
let vptr_field_ident = crate::utils::vptr_field_ident(&base);
|
||||
|
||||
quote!(
|
||||
else if #match_condition {
|
|
@ -1,4 +1,3 @@
|
|||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{AttributeArgs, ItemStruct};
|
||||
|
||||
|
@ -11,8 +10,8 @@ pub mod com_struct_impl;
|
|||
pub mod iunknown_impl;
|
||||
|
||||
pub fn expand_co_class(input: &ItemStruct, attr_args: &AttributeArgs) -> TokenStream {
|
||||
let base_interface_idents = macro_utils::base_interface_idents(attr_args);
|
||||
let aggr_interface_idents = macro_utils::get_aggr_map(attr_args);
|
||||
let base_interface_idents = crate::utils::base_interface_idents(attr_args);
|
||||
let aggr_interface_idents = crate::utils::get_aggr_map(attr_args);
|
||||
|
||||
let mut out: Vec<TokenStream> = Vec::new();
|
||||
out.push(com_struct::generate(&aggr_interface_idents, &base_interface_idents, input).into());
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{iid, vtable, vtable_macro};
|
||||
use crate::com_interface::{iid, vtable, vtable_macro};
|
||||
|
||||
use proc_macro2::TokenStream as HelperTokenStream;
|
||||
use quote::quote;
|
|
@ -1,5 +1,3 @@
|
|||
use macro_utils;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::{Ident, Span, TokenStream as HelperTokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
|
@ -85,6 +83,6 @@ pub fn generate(macro_attr: &TokenStream, interface_ident: &Ident) -> HelperToke
|
|||
pub fn ident(interface_ident: &Ident) -> Ident {
|
||||
format_ident!(
|
||||
"IID_{}",
|
||||
macro_utils::camel_to_snake(&interface_ident.to_string()).to_uppercase()
|
||||
crate::utils::camel_to_snake(&interface_ident.to_string()).to_uppercase()
|
||||
)
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
use crate::vptr;
|
||||
use macro_utils;
|
||||
use super::vptr;
|
||||
|
||||
use proc_macro2::{Ident, TokenStream as HelperTokenStream};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
|
@ -34,7 +33,7 @@ fn gen_impl_method(interface_ident: &Ident, method: &TraitItemMethod) -> HelperT
|
|||
let vptr_ident = vptr::ident(&interface_ident.to_string());
|
||||
let method_ident = format_ident!(
|
||||
"{}",
|
||||
macro_utils::snake_to_camel(&method.sig.ident.to_string())
|
||||
crate::utils::snake_to_camel(&method.sig.ident.to_string())
|
||||
);
|
||||
let interface_ptr_ident = format_ident!("interface_ptr");
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::vtable;
|
||||
use super::vtable;
|
||||
use proc_macro2::{Ident, TokenStream as HelperTokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::vptr;
|
||||
use macro_utils;
|
||||
use super::vptr;
|
||||
use proc_macro2::{Ident, TokenStream as HelperTokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
use std::iter::FromIterator;
|
||||
|
@ -56,7 +55,7 @@ pub fn ident(interface_name: &str) -> Ident {
|
|||
}
|
||||
|
||||
fn base_field_ident(base_interface_name: &str) -> Ident {
|
||||
format_ident!("{}_base", macro_utils::camel_to_snake(base_interface_name))
|
||||
format_ident!("{}_base", crate::utils::camel_to_snake(base_interface_name))
|
||||
}
|
||||
|
||||
fn gen_vtable_methods(interface: &ItemTrait) -> HelperTokenStream {
|
||||
|
@ -76,7 +75,7 @@ fn gen_vtable_methods(interface: &ItemTrait) -> HelperTokenStream {
|
|||
fn gen_vtable_method(interface_ident: &Ident, method: &TraitItemMethod) -> HelperTokenStream {
|
||||
let method_ident = format_ident!(
|
||||
"{}",
|
||||
macro_utils::snake_to_camel(&method.sig.ident.to_string())
|
||||
crate::utils::snake_to_camel(&method.sig.ident.to_string())
|
||||
);
|
||||
let vtable_function_signature = gen_vtable_function_signature(interface_ident, method);
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
use macro_utils;
|
||||
|
||||
use proc_macro2::{Ident, TokenStream as HelperTokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{ItemStruct, Type, TypeBareFn};
|
||||
|
@ -24,7 +22,7 @@ pub fn generate(item: &ItemStruct) -> HelperTokenStream {
|
|||
pub fn ident(struct_ident: &Ident) -> Ident {
|
||||
format_ident!(
|
||||
"{}_gen_vtable",
|
||||
macro_utils::camel_to_snake(&struct_ident.to_string().replace("VTable", ""))
|
||||
crate::utils::camel_to_snake(&struct_ident.to_string().replace("VTable", ""))
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -35,7 +33,7 @@ fn gen_parent_vtable_binding(item: &ItemStruct) -> HelperTokenStream {
|
|||
if parent.ends_with("_base") {
|
||||
let parent = format_ident!(
|
||||
"I{}",
|
||||
macro_utils::snake_to_camel(
|
||||
crate::utils::snake_to_camel(
|
||||
parent.trim_end_matches("_base").trim_start_matches("i")
|
||||
)
|
||||
);
|
||||
|
@ -75,7 +73,7 @@ fn gen_vtable_function(
|
|||
) -> HelperTokenStream {
|
||||
assert!(fun.unsafety.is_some(), "Function must be marked unsafe");
|
||||
assert!(fun.abi.is_some(), "Function must have marked ABI");
|
||||
let method_name = format_ident!("{}", macro_utils::camel_to_snake(&method_name.to_string()));
|
||||
let method_name = format_ident!("{}", crate::utils::camel_to_snake(&method_name.to_string()));
|
||||
let interface_name = struct_ident.to_string().replace("VTable", "");
|
||||
let interface_ident = format_ident!("{}", interface_name);
|
||||
let function_ident = format_ident!("{}_{}", interface_name.to_lowercase(), method_name);
|
||||
|
@ -127,7 +125,7 @@ fn gen_vtable_method_initialization(item: &ItemStruct) -> HelperTokenStream {
|
|||
let function_ident = format_ident!(
|
||||
"{}_{}",
|
||||
item.ident.to_string().replace("VTable", "").to_lowercase(),
|
||||
macro_utils::camel_to_snake(&method_ident.to_string())
|
||||
crate::utils::camel_to_snake(&method_ident.to_string())
|
||||
);
|
||||
quote! {
|
||||
#function_ident::<$class, $offset>,
|
|
@ -0,0 +1,6 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
pub mod aggr_co_class;
|
||||
pub mod co_class;
|
||||
pub mod com_interface;
|
||||
mod utils;
|
|
@ -7,14 +7,6 @@ pub fn class_factory_ident(class_ident: &Ident) -> Ident {
|
|||
format_ident!("{}ClassFactory", class_ident)
|
||||
}
|
||||
|
||||
pub fn vtable_ident(interface_ident: &Ident) -> Ident {
|
||||
format_ident!("{}VTable", interface_ident)
|
||||
}
|
||||
|
||||
pub fn vptr_ident(interface_ident: &Ident) -> Ident {
|
||||
format_ident!("{}VPtr", interface_ident)
|
||||
}
|
||||
|
||||
pub fn non_delegating_iunknown_field_ident() -> Ident {
|
||||
format_ident!("__non_delegatingegating_iunknown")
|
||||
}
|
||||
|
@ -32,7 +24,7 @@ pub fn vptr_field_ident(interface_ident: &Ident) -> Ident {
|
|||
}
|
||||
|
||||
pub fn set_aggregate_fn_ident(base: &Ident) -> Ident {
|
||||
format_ident!("set_aggregate_{}", crate::camel_to_snake(&base.to_string()))
|
||||
format_ident!("set_aggregate_{}", super::camel_to_snake(&base.to_string()))
|
||||
}
|
||||
|
||||
pub fn base_interface_idents(attr_args: &AttributeArgs) -> Vec<Ident> {
|
||||
|
@ -89,7 +81,7 @@ pub fn get_aggr_map(attr_args: &AttributeArgs) -> HashMap<Ident, Vec<Ident>> {
|
|||
}
|
||||
let ident = aggr_interfaces_idents
|
||||
.iter()
|
||||
.map(|base| crate::camel_to_snake(&base.to_string()))
|
||||
.map(|base| super::camel_to_snake(&base.to_string()))
|
||||
.fold("aggr".to_owned(), |acc, base| format!("{}_{}", acc, base));
|
||||
aggr_map.insert(format_ident!("{}", ident), aggr_interfaces_idents);
|
||||
}
|
|
@ -66,7 +66,7 @@ macro_rules! vtable {
|
|||
pub extern crate winapi as _winapi;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use macros::{co_class, com_interface, VTable};
|
||||
pub use com_macros::{co_class, com_interface, VTable};
|
||||
|
||||
// this allows for the crate to refer to itself as `com` to keep macros consistent
|
||||
// whether they are used by some other crate or internally
|
||||
|
|
Загрузка…
Ссылка в новой задаче