Add extension names to the funcion pointer structs

This commit is contained in:
Maik Klein 2019-02-12 15:04:38 +01:00
parent 6602522bb4
commit e86645d233

View file

@ -427,9 +427,6 @@ impl quote::ToTokens for ConstVal {
} }
} }
impl Constant { impl Constant {
// pub fn type(&self) -> Type {
// }
pub fn value(&self) -> Option<ConstVal> { pub fn value(&self) -> Option<ConstVal> {
match *self { match *self {
Constant::Number(n) => Some(ConstVal::U64(n as u64)), Constant::Number(n) => Some(ConstVal::U64(n as u64)),
@ -871,6 +868,7 @@ pub fn generate_extension_constants<'a>(
const_cache: &mut HashSet<&'a str>, const_cache: &mut HashSet<&'a str>,
const_values: &mut HashMap<Ident, Vec<Ident>>, const_values: &mut HashMap<Ident, Vec<Ident>>,
) -> quote::Tokens { ) -> quote::Tokens {
use vk_parse::EnumSpec;
let items = extension_items let items = extension_items
.iter() .iter()
.filter_map(|item| match item { .filter_map(|item| match item {
@ -880,7 +878,6 @@ pub fn generate_extension_constants<'a>(
.flat_map(|iter| iter); .flat_map(|iter| iter);
let enum_tokens = items.filter_map(|item| match item { let enum_tokens = items.filter_map(|item| match item {
vk_parse::InterfaceItem::Enum(_enum) => { vk_parse::InterfaceItem::Enum(_enum) => {
use vk_parse::EnumSpec;
if const_cache.contains(_enum.name.as_str()) { if const_cache.contains(_enum.name.as_str()) {
return None; return None;
} }
@ -952,7 +949,22 @@ pub fn generate_extension_commands<'a>(
.collect_vec(); .collect_vec();
let name = format!("{}Fn", extension_name.to_camel_case()); let name = format!("{}Fn", extension_name.to_camel_case());
let ident = Ident::from(&name[2..]); let ident = Ident::from(&name[2..]);
generate_function_pointers(ident, &commands, fn_cache) let fp = generate_function_pointers(ident, &commands, fn_cache);
let byte_name = format!("{}\0", extension_name);
let byte_name_ident =
syn::LitByteStr::new(byte_name.as_bytes(), proc_macro2::Span::call_site());
let extension_cstr = quote! {
impl #ident {
pub fn name() -> &'static ::std::ffi::CStr {
::std::ffi::CStr::from_bytes_with_nul(#byte_name_ident).expect("Wrong extension string")
}
}
};
quote! {
#extension_cstr
#fp
}
} }
pub fn generate_extension<'a>( pub fn generate_extension<'a>(
extension: &'a vk_parse::Extension, extension: &'a vk_parse::Extension,