Merge pull request #110 from MatusT/generator

Default trait: set pointers to std::ptr::null()/null_mut()
This commit is contained in:
Maik Klein 2018-08-23 07:18:21 +02:00 committed by GitHub
commit 898e9791b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 421 additions and 392 deletions

File diff suppressed because it is too large Load diff

View file

@ -1157,8 +1157,37 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
#param_ident: unsafe { ::std::mem::zeroed() }
}
}
} else if field.reference.is_some()
|| is_static_array(field)
} else if let Some(ref reference) = field.reference {
match reference {
vkxml::ReferenceType::Pointer => {
if field.is_const {
quote!{
#param_ident: ::std::ptr::null()
}
} else {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
}
vkxml::ReferenceType::PointerToPointer => {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
vkxml::ReferenceType::PointerToConstPointer => {
if field.is_const {
quote!{
#param_ident: ::std::ptr::null()
}
} else {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
}
}
} else if is_static_array(field)
|| is_pfn(field)
|| handles.contains(&field.basetype.as_str())
{
@ -1611,7 +1640,7 @@ pub fn write_source_code(path: &Path) {
};
acc
});
let constants_code: Vec<_> = constants
.iter()
.map(|constant| generate_constant(constant, &mut const_cache))