Skip to content

Commit 785b4cf

Browse files
committed
Return struct fields in struct
1 parent 58d8082 commit 785b4cf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

c2rust-transpile/src/translator/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,12 @@ struct ConvertedVariable {
11941194
pub init: TranslationResult<WithStmts<Box<Expr>>>,
11951195
}
11961196

1197+
pub struct ConvertedStructFields {
1198+
pub field_entries: Vec<Field>,
1199+
pub contains_va_list: bool,
1200+
pub can_derive_debug: bool,
1201+
}
1202+
11971203
impl<'c> Translation<'c> {
11981204
pub fn new(
11991205
mut ast_context: TypedAstContext,
@@ -1628,8 +1634,11 @@ impl<'c> Translation<'c> {
16281634
}
16291635

16301636
// Gather up all the field names and field types
1631-
let (field_entries, contains_va_list, can_derive_debug) =
1632-
self.convert_struct_fields(decl_id, fields, platform_byte_size)?;
1637+
let ConvertedStructFields {
1638+
field_entries,
1639+
contains_va_list,
1640+
can_derive_debug,
1641+
} = self.convert_struct_fields(decl_id, fields, platform_byte_size)?;
16331642

16341643
let mut derives = vec![];
16351644
if !contains_va_list {

c2rust-transpile/src/translator/structs.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashSet;
66
use std::ops::Index;
77

88
use super::named_references::NamedReference;
9-
use super::TranslationError;
9+
use super::{ConvertedStructFields, TranslationError};
1010
use crate::c_ast::{BinOp, CDeclId, CDeclKind, CExprId, CRecordId, CTypeId, CTypeKind};
1111
use crate::diagnostics::TranslationResult;
1212
use crate::translator::{ExprContext, Translation, PADDING_SUFFIX};
@@ -343,7 +343,7 @@ impl<'a> Translation<'a> {
343343
struct_id: CRecordId,
344344
field_ids: &[CDeclId],
345345
platform_byte_size: u64,
346-
) -> TranslationResult<(Vec<Field>, bool, bool)> {
346+
) -> TranslationResult<ConvertedStructFields> {
347347
let mut field_entries = Vec::with_capacity(field_ids.len());
348348
// We need to clobber bitfields in consecutive bytes together (leaving
349349
// regular fields alone) and add in padding as necessary
@@ -434,7 +434,11 @@ impl<'a> Translation<'a> {
434434
}
435435
}
436436
}
437-
Ok((field_entries, contains_va_list, can_derive_debug))
437+
Ok(ConvertedStructFields {
438+
field_entries,
439+
contains_va_list,
440+
can_derive_debug,
441+
})
438442
}
439443

440444
/// Here we output a block to generate a struct literal initializer in.

0 commit comments

Comments
 (0)