Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return struct fields in struct
Browse files Browse the repository at this point in the history
dgherzka committed Nov 7, 2023
1 parent 58d8082 commit 785b4cf
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
@@ -1194,6 +1194,12 @@ struct ConvertedVariable {
pub init: TranslationResult<WithStmts<Box<Expr>>>,
}

pub struct ConvertedStructFields {
pub field_entries: Vec<Field>,
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 {
10 changes: 7 additions & 3 deletions c2rust-transpile/src/translator/structs.rs
Original file line number Diff line number Diff line change
@@ -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<Field>, bool, bool)> {
) -> TranslationResult<ConvertedStructFields> {
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.

0 comments on commit 785b4cf

Please sign in to comment.