use convert_case::{Case, Casing};
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use crate::parser::command_spec::{Identifier, Type, Variant};
mod doc_identifier;
impl Identifier {
pub fn to_auxiliary_c(&self, generic_args: &[Type]) -> TokenStream2 {
let ident = self.to_rust_pascalized();
match &self.variant {
Variant::Structure { .. } => {
let ident = self.to_rust_pascalized();
quote! {
struct #ident
}
}
Variant::Enumeration { .. } => {
quote! {
enum #ident
}
}
Variant::Result { .. } | Variant::Option { .. } | Variant::Vec { .. } => {
let ident = Type::mangle_name(&self, generic_args);
quote! {
struct #ident
}
}
Variant::Primitive => match self.name.to_case(Case::Snake).as_str() {
"string" => {
quote! {
const char *
}
}
"u_8" => quote! { uint8_t },
"u_16" => quote! { uint16_t },
"u_32" => quote! { uint32_t },
"u_64" => quote! { uint64_t },
"i_8" => quote! { int8_t },
"i_16" => quote! { int16_t },
"i_32" => quote! { int32_t },
"i_64" => quote! { int64_t },
"f_32" => quote! { float },
"f_64" => quote! { double },
"void" => quote! { void },
other => {
todo!("'{}' is not yet supported", other)
}
},
Variant::Namespace
| Variant::RootNamespace
| Variant::Function
| Variant::NamedType
| Variant::DocNamedType
| Variant::Void => unreachable!("None of these variants should ever be used here"),
}
}
}