Skip to content

Commit

Permalink
typedef fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Apr 7, 2022
1 parent e29bdd1 commit 1dabc3a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/bindgen/cdecl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ impl CDecl {
// Write the identifier
if let Some(ident) = ident {
if config.language == Language::Zig && self.declarators.is_empty() {
write!(out, "{}: {}", ident, self.type_name);
if ident.is_empty() {
write!(out, "{}", self.type_name);
} else {
write!(out, "{}: {}", ident, self.type_name);
}
} else {
write!(out, "{}", ident);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl Style {

pub fn zig_def(self) -> &'static str {
if self.generate_tag() {
"pub const"
"pub const "
} else {
"pub extern"
}
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl Constant {
Language::Zig => {
out.write(config.style.zig_def());
self.ty.write(config, out);
write!(out, " {} = ", name);
write!(out, "{} = ", name);
value.write(config, out);
write!(out, ";");
}
Expand Down
14 changes: 12 additions & 2 deletions src/bindgen/ir/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ impl Field {
}
}

pub fn from_type(ty: Type) -> Field {
Field {
name: "".to_string(),
ty,
cfg: None,
annotations: AnnotationSet::new(),
documentation: Documentation::none(),
}
}

pub fn load(field: &syn::Field, self_path: &Path) -> Result<Option<Field>, String> {
Ok(if let Some(mut ty) = Type::load(&field.ty)? {
ty.replace_self_with(self_path);
Expand Down Expand Up @@ -61,13 +71,13 @@ impl Source for Field {
cdecl::write_field(out, &self.ty, &self.name, config);
// Cython extern declarations don't manage layouts, layouts are defined entierly by the
// corresponding C code. So we can omit bitfield sizes which are not supported by Cython.
if config.language != Language::Cython {
if config.language != Language::Cython || config.language != Language::Zig {
if let Some(bitfield) = self.annotations.atom("bitfield") {
write!(out, ": {}", bitfield.unwrap_or_default());
}
}

if config.language != Language::Cython {
if config.language != Language::Cython || config.language != Language::Zig {
condition.write_after(config, out);
// FIXME(#634): `write_vertical_source_list` should support
// configuring list elements natively. For now we print a newline
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Source for Typedef {
}
Language::Zig => {
write!(out, "{}{} = ", config.style.zig_def(), self.export_name());
self.aliased.write(config, out);
Field::from_type(self.aliased.clone()).write(config, out);
}
}

Expand Down

0 comments on commit 1dabc3a

Please sign in to comment.