Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic types #1363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl ConversionType {
IntPtr => ConversionType::Direct,
UIntPtr => ConversionType::Direct,
Bool => ConversionType::Direct,
Typedef(_) => ConversionType::Direct,
Unsupported => ConversionType::Unknown,
},
Alias(alias) if alias.c_identifier == "GQuark" => ConversionType::Scalar,
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn ffi_type(env: &Env, tid: TypeId, c_type: &str) -> Result {
fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result {
let typ = env.library.type_(tid);
match *typ {
Type::Basic(fund) => {
Type::Basic(ref fund) => {
use crate::library::Basic::*;
let inner = match fund {
None => "libc::c_void",
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'env> RustTypeBuilder<'env> {
let mut skip_option = false;
let type_ = self.env.library.type_(self.type_id);
let mut rust_type = match *type_ {
Basic(fund) => {
Basic(ref fund) => {
match fund {
None => err("()"),
Boolean | Bool => ok("bool"),
Expand All @@ -268,7 +268,7 @@ impl<'env> RustTypeBuilder<'env> {
UInt => ok("u32"), //maybe dependent on target system

Short => ok_and_use("libc::c_short"), //depends of target system
UShort => ok_and_use("libc::c_ushort"), //depends o f target system
UShort => ok_and_use("libc::c_ushort"), //depends of target system
Long => ok_and_use("libc::c_long"), //depends of target system
ULong => ok_and_use("libc::c_ulong"), //depends of target system

Expand Down Expand Up @@ -303,6 +303,7 @@ impl<'env> RustTypeBuilder<'env> {
Type => ok_and_use(&use_glib_type(self.env, "types::Type")),
Char => ok_and_use(&use_glib_type(self.env, "Char")),
UChar => ok_and_use(&use_glib_type(self.env, "UChar")),
Typedef(name) => ok_and_use(name),
Unsupported => err("Unsupported"),
_ => err(&format!("Basic: {:?}", fund)),
}
Expand Down
3 changes: 2 additions & 1 deletion src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {

let typ = env.library.type_(tid);
let res = match *typ {
Type::Basic(fund) => {
Type::Basic(ref fund) => {
use crate::library::Basic::*;
let inner = match fund {
None => "c_void",
Expand Down Expand Up @@ -110,6 +110,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
UIntPtr => "uintptr_t",
Bool => "bool",
Unsupported => return Err(TypeError::Unimplemented(inner)),
Typedef(name) => return Ok(name.into()),
VarArgs => panic!("Should not reach here"),
};
Ok(inner.into())
Expand Down
25 changes: 7 additions & 18 deletions src/codegen/sys/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,8 @@ fn cross_validate_constants_with_c() {
let mut c_constants: Vec<(String, String)> = Vec::new();

for l in get_c_output("constant").unwrap().lines() {
let mut words = l.trim().split(';');
let name = words.next().expect("Failed to parse name").to_owned();
let value = words
.next()
.and_then(|s| s.parse().ok())
.expect("Failed to parse value");
c_constants.push((name, value));
let (name, value) = l.split_once(';').expect("Missing ';' separator");
c_constants.push((name.to_owned(), value.to_owned()));
}

let mut results = Results::default();
Expand Down Expand Up @@ -458,17 +453,11 @@ fn cross_validate_layout_with_c() {
let mut c_layouts = Vec::new();

for l in get_c_output("layout").unwrap().lines() {
let mut words = l.trim().split(';');
let name = words.next().expect("Failed to parse name").to_owned();
let size = words
.next()
.and_then(|s| s.parse().ok())
.expect("Failed to parse size");
let alignment = words
.next()
.and_then(|s| s.parse().ok())
.expect("Failed to parse alignment");
c_layouts.push((name, Layout { size, alignment }));
let (name, value) = l.split_once(';').expect("Missing first ';' separator");
let (size, alignment) = value.split_once(';').expect("Missing second ';' separator");
let size = size.parse().expect("Failed to parse size");
let alignment = alignment.parse().expect("Failed to parse alignment");
c_layouts.push((name.to_owned(), Layout { size, alignment }));
}

let mut results = Results::default();
Expand Down
19 changes: 19 additions & 0 deletions src/custom_vulkan_namespace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::library::*;

pub const VULKAN_NAMESPACE_NAME: &str = "Vulkan";

impl Library {
pub fn tweak_vulkan_namespace(&mut self) {
if let Some(ns_id) = self.find_namespace(VULKAN_NAMESPACE_NAME) {
let ns = self.namespace_mut(ns_id);
for typ in &mut ns.types {
if let Some(Type::Record(rec)) = typ {
*typ = Some(Type::Basic(Basic::Typedef(format!(
"ash::vk::{}",
rec.name
))));
}
}
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod codegen;
mod config;
mod consts;
mod custom_type_glib_priority;
mod custom_vulkan_namespace;
mod env;
mod file_saver;
pub mod fmt;
Expand Down
8 changes: 5 additions & 3 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Default for Concurrency {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Basic {
None,
Boolean,
Expand Down Expand Up @@ -240,6 +240,7 @@ pub enum Basic {
OsString,
Bool,
Unsupported,
Typedef(String),
}

impl Basic {
Expand Down Expand Up @@ -267,6 +268,7 @@ impl Basic {
| Self::Float
| Self::Double
| Self::Bool
| Self::Typedef(_)
)
}
}
Expand Down Expand Up @@ -1054,8 +1056,8 @@ impl Library {
INTERNAL_NAMESPACE,
library.add_namespace(INTERNAL_NAMESPACE_NAME)
);
for &(name, t) in BASIC {
library.add_type(INTERNAL_NAMESPACE, name, Type::Basic(t));
for (name, t) in BASIC {
library.add_type(INTERNAL_NAMESPACE, name, Type::Basic(t.clone()));
}
assert_eq!(MAIN_NAMESPACE, library.add_namespace(main_namespace_name));

Expand Down
1 change: 1 addition & 0 deletions src/library_preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ use crate::{config::WorkMode, library::*};
impl Library {
pub fn preprocessing(&mut self, work_mode: WorkMode) {
self.add_glib_priority(work_mode);
self.tweak_vulkan_namespace();
}
}