From 785b4cf00fc474d65e338d29fd76e3a8fd35a1af Mon Sep 17 00:00:00 2001 From: David Herzka Date: Tue, 7 Nov 2023 11:17:19 -0500 Subject: [PATCH] Return struct fields in struct --- c2rust-transpile/src/translator/mod.rs | 13 +++++++++++-- c2rust-transpile/src/translator/structs.rs | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/c2rust-transpile/src/translator/mod.rs b/c2rust-transpile/src/translator/mod.rs index 691abaadd5..eb88815792 100644 --- a/c2rust-transpile/src/translator/mod.rs +++ b/c2rust-transpile/src/translator/mod.rs @@ -1194,6 +1194,12 @@ struct ConvertedVariable { pub init: TranslationResult>>, } +pub struct ConvertedStructFields { + pub field_entries: Vec, + pub contains_va_list: bool, + pub can_derive_debug: bool, +} + impl<'c> Translation<'c> { pub fn new( mut ast_context: TypedAstContext, @@ -1628,8 +1634,11 @@ impl<'c> Translation<'c> { } // Gather up all the field names and field types - let (field_entries, contains_va_list, can_derive_debug) = - self.convert_struct_fields(decl_id, fields, platform_byte_size)?; + let ConvertedStructFields { + field_entries, + contains_va_list, + can_derive_debug, + } = self.convert_struct_fields(decl_id, fields, platform_byte_size)?; let mut derives = vec![]; if !contains_va_list { diff --git a/c2rust-transpile/src/translator/structs.rs b/c2rust-transpile/src/translator/structs.rs index e86ca822bc..b1832129d6 100644 --- a/c2rust-transpile/src/translator/structs.rs +++ b/c2rust-transpile/src/translator/structs.rs @@ -6,7 +6,7 @@ use std::collections::HashSet; use std::ops::Index; use super::named_references::NamedReference; -use super::TranslationError; +use super::{ConvertedStructFields, TranslationError}; use crate::c_ast::{BinOp, CDeclId, CDeclKind, CExprId, CRecordId, CTypeId, CTypeKind}; use crate::diagnostics::TranslationResult; use crate::translator::{ExprContext, Translation, PADDING_SUFFIX}; @@ -343,7 +343,7 @@ impl<'a> Translation<'a> { struct_id: CRecordId, field_ids: &[CDeclId], platform_byte_size: u64, - ) -> TranslationResult<(Vec, bool, bool)> { + ) -> TranslationResult { let mut field_entries = Vec::with_capacity(field_ids.len()); // We need to clobber bitfields in consecutive bytes together (leaving // regular fields alone) and add in padding as necessary @@ -434,7 +434,11 @@ impl<'a> Translation<'a> { } } } - Ok((field_entries, contains_va_list, can_derive_debug)) + Ok(ConvertedStructFields { + field_entries, + contains_va_list, + can_derive_debug, + }) } /// Here we output a block to generate a struct literal initializer in.