ppc login works in mme main
This commit is contained in:
@@ -227,19 +227,45 @@ fn generate_arg_passing(args: &[(Ident, Type)]) -> Vec<proc_macro2::TokenStream>
|
||||
}).collect()
|
||||
}
|
||||
|
||||
/// Last path segment of a Type, for signature strings (e.g. `clap::Command` -> `Command`).
|
||||
fn type_to_sig_name(ty: &Type) -> String {
|
||||
match ty {
|
||||
Type::Path(p) => p
|
||||
.path
|
||||
.segments
|
||||
.last()
|
||||
.map(|s| s.ident.to_string())
|
||||
.unwrap_or_else(|| quote!(#ty).to_string()),
|
||||
_ => quote!(#ty).to_string().replace(' ', ""),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a signature string like `"String, Command"` from FuncSpec args.
|
||||
fn synthesize_signature(args: &[(Ident, Type)]) -> String {
|
||||
args.iter()
|
||||
.map(|(_, ty)| type_to_sig_name(ty))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
fn expand_simple_include_native(simple: IncludeNativeSimple) -> TokenStream {
|
||||
let name = simple.name;
|
||||
let type_path = simple.type_path;
|
||||
let methods = simple.methods;
|
||||
|
||||
|
||||
let type_name_str = quote!(#type_path).to_string().replace(' ', "");
|
||||
let method_names: Vec<String> = methods.iter().map(|m| m.name.to_string()).collect();
|
||||
let method_sigs: Vec<String> = methods.iter().map(|m| synthesize_signature(&m.args)).collect();
|
||||
|
||||
let method_calls = methods.iter().map(|method| {
|
||||
let method_name = method.name.to_string();
|
||||
let method_ident = &method.name;
|
||||
let signature = synthesize_signature(&method.args);
|
||||
let arg_extractions = generate_arg_extraction(&method.args);
|
||||
let arg_passings = generate_arg_passing(&method.args);
|
||||
|
||||
|
||||
quote! {
|
||||
.method(#method_name, |args| {
|
||||
.method(#method_name, #signature, |args| {
|
||||
#(#arg_extractions)*
|
||||
let this = mize::prelude::get_global_mize()?
|
||||
.get_config(#name)?
|
||||
@@ -249,12 +275,26 @@ fn expand_simple_include_native(simple: IncludeNativeSimple) -> TokenStream {
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let expanded = quote! {
|
||||
mize::config::opt(#name)
|
||||
#(#method_calls)*
|
||||
{
|
||||
if let Ok(mize) = mize::prelude::get_global_mize() {
|
||||
if mize.is_generate_mode().unwrap_or(false) {
|
||||
let _ = mize.record_native(
|
||||
#name,
|
||||
#type_name_str,
|
||||
Vec::new(),
|
||||
vec![#(#method_names.to_string()),*],
|
||||
Vec::new(),
|
||||
vec![#(#method_sigs.to_string()),*],
|
||||
);
|
||||
}
|
||||
}
|
||||
mize::config::opt(#name)
|
||||
#(#method_calls)*
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
@@ -263,15 +303,22 @@ fn expand_block_include_native(block: IncludeNativeBlock) -> TokenStream {
|
||||
let type_path = block.type_path;
|
||||
let associated = block.associated;
|
||||
let methods = block.methods;
|
||||
|
||||
|
||||
let type_name_str = quote!(#type_path).to_string().replace(' ', "");
|
||||
let associated_names: Vec<String> = associated.iter().map(|m| m.name.to_string()).collect();
|
||||
let method_names: Vec<String> = methods.iter().map(|m| m.name.to_string()).collect();
|
||||
let associated_sigs: Vec<String> = associated.iter().map(|m| synthesize_signature(&m.args)).collect();
|
||||
let method_sigs: Vec<String> = methods.iter().map(|m| synthesize_signature(&m.args)).collect();
|
||||
|
||||
let method_calls = methods.iter().map(|method| {
|
||||
let method_name = method.name.to_string();
|
||||
let method_ident = &method.name;
|
||||
let signature = synthesize_signature(&method.args);
|
||||
let arg_extractions = generate_arg_extraction(&method.args);
|
||||
let arg_passings = generate_arg_passing(&method.args);
|
||||
|
||||
|
||||
quote! {
|
||||
.method(#method_name, |args| {
|
||||
.method(#method_name, #signature, |args| {
|
||||
#(#arg_extractions)*
|
||||
let this = mize::prelude::get_global_mize()?
|
||||
.get_config(#name)?
|
||||
@@ -281,28 +328,43 @@ fn expand_block_include_native(block: IncludeNativeBlock) -> TokenStream {
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let associated_calls = associated.iter().map(|func| {
|
||||
let func_name = func.name.to_string();
|
||||
let func_ident = &func.name;
|
||||
let signature = synthesize_signature(&func.args);
|
||||
let arg_extractions = generate_arg_extraction(&func.args);
|
||||
let arg_passings = generate_arg_passing(&func.args);
|
||||
|
||||
|
||||
quote! {
|
||||
.method(#func_name, |args| {
|
||||
.method(#func_name, #signature, |args| {
|
||||
#(#arg_extractions)*
|
||||
let result = <#type_path>::#func_ident(#(#arg_passings),*);
|
||||
Ok(mize::item::ItemData::from_native(result)?)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let expanded = quote! {
|
||||
mize::config::opt(#name)
|
||||
#(#associated_calls)*
|
||||
#(#method_calls)*
|
||||
{
|
||||
if let Ok(mize) = mize::prelude::get_global_mize() {
|
||||
if mize.is_generate_mode().unwrap_or(false) {
|
||||
let _ = mize.record_native(
|
||||
#name,
|
||||
#type_name_str,
|
||||
vec![#(#associated_names.to_string()),*],
|
||||
vec![#(#method_names.to_string()),*],
|
||||
vec![#(#associated_sigs.to_string()),*],
|
||||
vec![#(#method_sigs.to_string()),*],
|
||||
);
|
||||
}
|
||||
}
|
||||
mize::config::opt(#name)
|
||||
#(#associated_calls)*
|
||||
#(#method_calls)*
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user