Clear warnings and run cargo fmt

This commit is contained in:
adrianwithah 2019-09-10 20:46:42 +01:00
Родитель e98b2415c6
Коммит 6922995fc8
15 изменённых файлов: 75 добавлений и 61 удалений

Просмотреть файл

@ -2,7 +2,7 @@ use interface::ilocal_file_manager::ILocalFileManager;
use winapi::shared::winerror::{HRESULT, NOERROR};
use com::{aggr_co_class, com_implements,};
use com::aggr_co_class;
/// The implementation class
#[repr(C)]
#[aggr_co_class]

Просмотреть файл

@ -1,4 +1,4 @@
use com::{failed, ComPtr, IUnknown, IUnknownVPtr, IID_IUNKNOWN};
use com::{failed, IUnknownVPtr, IID_IUNKNOWN};
use interface::{
ifile_manager::IFileManager, ilocal_file_manager::ILocalFileManager,
CLSID_LOCAL_FILE_MANAGER_CLASS,
@ -15,9 +15,7 @@ use winapi::{
um::combaseapi::CoCreateInstance,
};
use std::mem::forget;
use com::{co_class, com_implements, aggr,};
use com::co_class;
/// The implementation class
#[co_class]
#[com_implements(IFileManager)]
@ -38,7 +36,7 @@ impl WindowsFileManager {
let mut wfm = WindowsFileManager::allocate(20);
// Instantiate object to aggregate
// TODO: Should change to use safe ComPtr methods instead.
// TODO: Create safe wrapper for instantiating as aggregate.
let mut unknown_file_manager = std::ptr::null_mut::<c_void>();
let hr = unsafe {
CoCreateInstance(

Просмотреть файл

@ -2,7 +2,7 @@ use interface::{ianimal::IAnimal, icat::ICat, idomesticanimal::IDomesticAnimal};
use winapi::shared::winerror::{HRESULT, NOERROR};
use com::{co_class, com_implements, aggr};
use com::co_class;
/// The implementation class
/// https://en.wikipedia.org/wiki/British_Shorthair

Просмотреть файл

@ -1,12 +1,16 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::quote;
use syn::{Ident, ItemStruct, Fields,};
use std::collections::HashMap;
use syn::{Fields, Ident, ItemStruct};
/// As an aggregable COM object, you need to have an inner non-delegating IUnknown vtable.
/// All IUnknown calls to this COM object will delegate to the IUnknown interface pointer
/// __iunknown_to_use.
pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
pub fn generate(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let vis = &struct_item.vis;
@ -21,10 +25,10 @@ pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[
let fields = match &struct_item.fields {
Fields::Named(f) => &f.named,
_ => panic!("Found non Named fields in struct.")
_ => panic!("Found non Named fields in struct."),
};
let aggregates = aggr_map.iter().map(|(aggr_field_ident, aggr_base_interface_idents)| {
let aggregates = aggr_map.iter().map(|(aggr_field_ident, _)| {
quote!(
#aggr_field_ident: *mut <dyn com::IUnknown as com::ComInterface>::VPtr
)

Просмотреть файл

@ -1,7 +1,7 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::quote;
use std::collections::HashMap;
use syn::{Ident, ItemStruct, Fields,};
use syn::{Fields, Ident, ItemStruct};
/// Generates the methods that the com struct needs to have. These include:
/// allocate: To initialise the vtables, including the non_delegatingegating_iunknown one.
@ -172,7 +172,11 @@ fn gen_inner_query_interface(
/// For an aggregable object, we have to do more work here. We need to
/// instantiate the non-delegating IUnknown vtable. The unsafe extern "stdcall"
/// methods belonging to the non-delegating IUnknown vtable are also defined here.
fn gen_allocate_fn(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
fn gen_allocate_fn(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let mut offset_count: usize = 0;
@ -199,14 +203,14 @@ fn gen_allocate_fn(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents:
let fields = match &struct_item.fields {
Fields::Named(f) => &f.named,
_ => panic!("Found non Named fields in struct.")
_ => panic!("Found non Named fields in struct."),
};
let field_idents = fields.iter().map(|field| {
let field_ident = field.ident.as_ref().unwrap().clone();
quote!(#field_ident)
});
let aggregate_inits = aggr_map.iter().map(|(aggr_field_ident, aggr_base_interface_idents)| {
let aggregate_inits = aggr_map.iter().map(|(aggr_field_ident, _)| {
quote!(
#aggr_field_ident: std::ptr::null_mut()
)

Просмотреть файл

@ -1,9 +1,13 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::quote;
use syn::{Ident, ItemStruct};
use std::collections::HashMap;
use syn::{Ident, ItemStruct};
pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
pub fn generate(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let non_delegating_iunknown_field_ident = macro_utils::non_delegating_iunknown_field_ident();
let box_from_raws = base_interface_idents.iter().map(|base| {

Просмотреть файл

@ -21,13 +21,12 @@ pub fn expand_aggr_co_class(_attr: TokenStream, item: TokenStream) -> TokenStrea
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(
com_struct_impl::generate(&base_interface_idents, &aggr_interface_idents, &input).into(),
);
out.push(iunknown_impl::generate(&input).into());
out.push(drop_impl::generate(&aggr_interface_idents, &base_interface_idents, &input).into());
out.push(class_factory::generate(&input).into());
// TokenStream::from_iter(out)
let result = TokenStream::from_iter(out);
println!("Result:\n{}", result.to_string());
result
TokenStream::from_iter(out)
}

Просмотреть файл

@ -1,7 +1,7 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::quote;
use syn::{Ident, ItemStruct, Fields};
use std::collections::HashMap;
use syn::{Fields, Ident, ItemStruct};
/// The actual COM object that wraps around the Init struct.
/// Structure of the object:
@ -10,7 +10,11 @@ use std::collections::HashMap;
/// ..ref count..
/// ..init struct..
/// }
pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
pub fn generate(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let vis = &struct_item.vis;
@ -23,10 +27,10 @@ pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[
let fields = match &struct_item.fields {
Fields::Named(f) => &f.named,
_ => panic!("Found non Named fields in struct.")
_ => panic!("Found non Named fields in struct."),
};
let aggregates = aggr_map.iter().map(|(aggr_field_ident, aggr_base_interface_idents)| {
let aggregates = aggr_map.iter().map(|(aggr_field_ident, _)| {
quote!(
#aggr_field_ident: *mut <dyn com::IUnknown as com::ComInterface>::VPtr
)

Просмотреть файл

@ -1,12 +1,16 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::{format_ident, quote};
use syn::{Ident, ItemStruct, Fields,};
use std::collections::HashMap;
use syn::{Fields, Ident, ItemStruct};
/// Generates the allocate and get_class_object function for the COM object.
/// allocate: instantiates the COM fields, such as vpointers for the COM object.
/// get_class_object: Instantiate an instance to the class object.
pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
pub fn generate(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
// Allocate stuff
@ -34,14 +38,14 @@ pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[
let fields = match &struct_item.fields {
Fields::Named(f) => &f.named,
_ => panic!("Found non Named fields in struct.")
_ => panic!("Found non Named fields in struct."),
};
let field_idents = fields.iter().map(|field| {
let field_ident = field.ident.as_ref().unwrap().clone();
quote!(#field_ident)
});
let aggregate_inits = aggr_map.iter().map(|(aggr_field_ident, aggr_base_interface_idents)| {
let aggregate_inits = aggr_map.iter().map(|(aggr_field_ident, _)| {
quote!(
#aggr_field_ident: std::ptr::null_mut()
)
@ -76,7 +80,10 @@ fn gen_set_aggregate_fns(aggr_map: &HashMap<Ident, Vec<Ident>>) -> HelperTokenSt
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 = format_ident!("set_aggregate_{}", macro_utils::camel_to_snake(&base.to_string()));
let set_aggregate_fn_ident = format_ident!(
"set_aggregate_{}",
macro_utils::camel_to_snake(&base.to_string())
);
fns.push(quote!(
fn #set_aggregate_fn_ident(&mut self, aggr: *mut <dyn com::IUnknown as com::ComInterface>::VPtr) {
// TODO: What happens if we are overwriting an existing aggregate?

Просмотреть файл

@ -1,9 +1,13 @@
use proc_macro2::TokenStream as HelperTokenStream;
use quote::quote;
use syn::{Ident, ItemStruct};
use std::collections::HashMap;
use syn::{Ident, ItemStruct};
pub fn generate(aggr_map: &HashMap<Ident, Vec<Ident>>, base_interface_idents: &[Ident], struct_item: &ItemStruct) -> HelperTokenStream {
pub fn generate(
aggr_map: &HashMap<Ident, Vec<Ident>>,
base_interface_idents: &[Ident],
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let box_from_raws = base_interface_idents.iter().map(|base| {
let vptr_field_ident = macro_utils::vptr_field_ident(&base);

Просмотреть файл

@ -13,12 +13,12 @@ pub fn generate(
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let ref_count_ident = macro_utils::ref_count_ident();
let query_interface = gen_query_interface(base_interface_idents, aggr_interface_idents, struct_item);
let query_interface = gen_query_interface(base_interface_idents, aggr_interface_idents);
quote!(
impl com::IUnknown for #struct_ident {
#query_interface
fn add_ref(&mut self) -> u32 {
@ -44,9 +44,7 @@ pub fn generate(
)
}
fn gen_base_match_arms(
base_interface_idents: &[Ident],
) -> HelperTokenStream {
fn gen_base_match_arms(base_interface_idents: &[Ident]) -> HelperTokenStream {
// Generate match arms for implemented interfaces
let base_match_arms = base_interface_idents.iter().map(|base| {
let match_condition =
@ -107,10 +105,7 @@ fn gen_aggregate_match_arms(
fn gen_query_interface(
base_interface_idents: &[Ident],
aggr_interface_idents: &HashMap<Ident, Vec<Ident>>,
struct_item: &ItemStruct,
) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let first_vptr_field = macro_utils::vptr_field_ident(&base_interface_idents[0]);
// Generate match arms for implemented interfaces
@ -142,4 +137,4 @@ fn gen_query_interface(
}
}
)
}
}

Просмотреть файл

@ -20,13 +20,14 @@ pub fn expand_co_class(_attr: TokenStream, item: TokenStream) -> TokenStream {
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(&aggr_interface_idents, &base_interface_idents, &input).into());
out.push(iunknown_impl::generate(&base_interface_idents, &aggr_interface_idents, &input).into());
out.push(
com_struct_impl::generate(&aggr_interface_idents, &base_interface_idents, &input).into(),
);
out.push(
iunknown_impl::generate(&base_interface_idents, &aggr_interface_idents, &input).into(),
);
out.push(drop_impl::generate(&aggr_interface_idents, &base_interface_idents, &input).into());
out.push(class_factory::generate(&input).into());
// TokenStream::from_iter(out)
let result = TokenStream::from_iter(out);
println!("Result:\n{}", result.to_string());
result
TokenStream::from_iter(out)
}

Просмотреть файл

@ -1,6 +1,6 @@
use quote::{format_ident,};
use syn::{
Ident, Meta, NestedMeta, Fields, ItemStruct
Ident, Meta, NestedMeta, ItemStruct,
};
use std::collections::HashMap;
@ -92,9 +92,5 @@ pub fn get_aggr_map(struct_item: &ItemStruct) -> HashMap<Ident, Vec<Ident>> {
}
}
for (ident, _) in aggr_map.iter() {
println!("Ident found: {}", ident);
}
aggr_map
}

Просмотреть файл

@ -28,11 +28,11 @@ pub fn aggr_co_class(attr: TokenStream, item: TokenStream) -> TokenStream {
}
#[proc_macro_attribute]
pub fn com_implements(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn com_implements(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
#[proc_macro_attribute]
pub fn aggr(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn aggr(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
}

Просмотреть файл

@ -29,9 +29,7 @@ impl ComPtr<dyn IClassFactory> {
pub fn get_instance<T: ComInterface + ?Sized>(&mut self) -> Option<ComPtr<T>> {
let mut ppv = std::ptr::null_mut::<c_void>();
let aggr = std::ptr::null_mut();
let hr = unsafe {
self.create_instance(aggr, &T::IID as *const IID, &mut ppv)
};
let hr = unsafe { self.create_instance(aggr, &T::IID as *const IID, &mut ppv) };
if failed(hr) {
// TODO: decide what failures are possible
return None;