Merge remote-tracking branch 'origin/generator' into generator

This commit is contained in:
Tim 2018-07-31 14:20:15 +02:00
commit 338ed956d2
3 changed files with 672 additions and 580 deletions

View file

@ -85,9 +85,9 @@ impl<V: FunctionPointers> Instance<V> {
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub trait InstanceV1_1: InstanceV1_0 { pub trait InstanceV1_1: InstanceV1_0 {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1; fn fp_v1_1(&self) -> &vk::InstanceFnV1_1;
unsafe fn enumerate_instance_version(&self, api_version: &vk::uint32_t) -> vk::Result { unsafe fn enumerate_instance_version(&self, api_version: &mut vk::uint32_t) -> vk::Result {
self.fp_v1_1() self.fp_v1_1()
.enumerate_instance_version(api_version as *const _) .enumerate_instance_version(api_version as *mut _)
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -556,14 +556,26 @@ pub trait FieldExt {
} }
pub trait ToTokens { pub trait ToTokens {
fn to_tokens(&self) -> Tokens; fn to_tokens(&self, is_const: bool) -> Tokens;
} }
impl ToTokens for vkxml::ReferenceType { impl ToTokens for vkxml::ReferenceType {
fn to_tokens(&self) -> Tokens { fn to_tokens(&self, is_const: bool) -> Tokens {
let ptr_name = match self { let ptr_name = match self {
vkxml::ReferenceType::Pointer => "*const", vkxml::ReferenceType::Pointer => {
if is_const {
"*const"
} else {
"*mut"
}
}
vkxml::ReferenceType::PointerToPointer => "*mut *mut", vkxml::ReferenceType::PointerToPointer => "*mut *mut",
vkxml::ReferenceType::PointerToConstPointer => "*const", vkxml::ReferenceType::PointerToConstPointer => {
if is_const {
"*const *const"
} else {
"*mut *const"
}
}
}; };
let ident = Term::intern(ptr_name); let ident = Term::intern(ptr_name);
quote!{ quote!{
@ -591,7 +603,7 @@ fn name_to_tokens(type_name: &str) -> Ident {
} }
fn to_type_tokens(type_name: &str, reference: Option<&vkxml::ReferenceType>) -> Tokens { fn to_type_tokens(type_name: &str, reference: Option<&vkxml::ReferenceType>) -> Tokens {
let new_name = name_to_tokens(type_name); let new_name = name_to_tokens(type_name);
let ptr_name = reference.map(|r| r.to_tokens()).unwrap_or(quote!{}); let ptr_name = reference.map(|r| r.to_tokens(false)).unwrap_or(quote!{});
quote!{#ptr_name #new_name} quote!{#ptr_name #new_name}
} }
@ -609,11 +621,12 @@ impl FieldExt for vkxml::Field {
} }
fn type_tokens(&self) -> Tokens { fn type_tokens(&self) -> Tokens {
println!("{:#?}", self);
let ty = name_to_tokens(&self.basetype); let ty = name_to_tokens(&self.basetype);
let pointer = self let pointer = self
.reference .reference
.as_ref() .as_ref()
.map(|r| r.to_tokens()) .map(|r| r.to_tokens(self.is_const))
.unwrap_or(quote!{}); .unwrap_or(quote!{});
let pointer_ty = quote!{ let pointer_ty = quote!{
#pointer #ty #pointer #ty
@ -903,7 +916,14 @@ pub enum EnumType {
pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident { pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident {
let _name = enum_name.split("FlagBits").nth(0).expect("split"); let _name = enum_name.split("FlagBits").nth(0).expect("split");
let struct_name = _name.to_shouty_snake_case(); // TODO: Should be read from vk.xml
// TODO: Also needs to be more robust, vendor names can be substrings from itself,
// like NVX and NV
let vendors = ["_NVX", "_KHR", "_EXT", "_NV", "_AMD", "_ANDROID", "_GOOGLE"];
let mut struct_name = _name.to_shouty_snake_case();
for vendor in &vendors {
struct_name = struct_name.replace(vendor, "");
}
let new_variant_name = variant_name.replace(&struct_name, "").replace("VK", ""); let new_variant_name = variant_name.replace(&struct_name, "").replace("VK", "");
let new_variant_name = new_variant_name let new_variant_name = new_variant_name
.trim_matches('_') .trim_matches('_')