Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions c2rust-ast-exporter/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.5...4.0)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(ASTExporter)

#################################################
Expand Down Expand Up @@ -89,7 +90,7 @@ add_library(clangAstExporter STATIC ${AST_EXPORTER_SRCS})
add_definitions(-DCLANG_LIBDIR_SUFFIX="${LLVM_LIBDIR_SUFFIX}")

set_target_properties(c2rust-ast-exporter PROPERTIES
CXX_STANDARD 14
CXX_STANDARD 17
CXX_EXTENSIONS OFF
)
# PRIVATE was added to make c2rust-ast-exporter build with LLVM 6.0. Keyword
Expand Down
3 changes: 2 additions & 1 deletion c2rust-ast-exporter/src/clang_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ pub fn process(items: Value) -> error::Result<AstContext> {
let entry_id: u64 = from_value(entry.pop_front().unwrap()).unwrap();
let tag = from_value(entry.pop_front().unwrap()).unwrap();

if tag < 400 {
// Tags before the first type tag indicate AST nodes, after indicate type nodes.
if tag < TypeTag::TagTypeUnknown as _ {
let children = from_value::<Vec<Value>>(entry.pop_front().unwrap())
.unwrap()
.iter()
Expand Down
5 changes: 1 addition & 4 deletions c2rust-ast-exporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ pub fn get_untyped_ast(

let items: Value = from_slice(&buffer[..]).unwrap();

match clang_ast::process(items) {
Ok(cxt) => Ok(cxt),
Err(e) => Err(Error::new(ErrorKind::InvalidData, format!("{:}", e))),
}
clang_ast::process(items).map_err(|e| Error::new(ErrorKind::InvalidData, format!("{}", e)))
}

fn get_ast_cbors(
Expand Down
14 changes: 7 additions & 7 deletions c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub enum ReplaceMode {
Extern,
}

/// Options that impact an expression and all of its subexpressions.
#[derive(Copy, Clone, Debug)]
pub struct ExprContext {
used: bool,
Expand Down Expand Up @@ -1711,8 +1712,8 @@ impl<'c> Translation<'c> {
.resolve_decl_suffix_name(decl_id, PADDING_SUFFIX)
.to_owned();
let padding_ty = mk().path_ty(vec!["usize"]);
let outer_size = self.compute_size_of_ty(outer_ty)?.to_expr();
let inner_size = self.compute_size_of_ty(inner_ty)?.to_expr();
let outer_size = self.mk_size_of_ty_expr(outer_ty)?.to_expr();
let inner_size = self.mk_size_of_ty_expr(inner_ty)?.to_expr();
let padding_value =
mk().binary_expr(BinOp::Sub(Default::default()), outer_size, inner_size);
let padding_const = mk()
Expand Down Expand Up @@ -2845,7 +2846,7 @@ impl<'c> Translation<'c> {
return true;
}

// None assignments don't prove enough type information unless there are follow-up assignments
// None assignments don't provide enough type information unless there are follow-up assignments
Copy link
Contributor

@kkysen kkysen Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// None assignments don't provide enough type information unless there are follow-up assignments
// `None` assignments don't provide enough type information unless there are follow-up assignments

nit: A bit clearer since None could read as an English word, too.

if let Some(CExprKind::ImplicitCast(_, _, CastKind::NullToPointer, _, _)) =
initializer_kind
{
Expand Down Expand Up @@ -3143,10 +3144,10 @@ impl<'c> Translation<'c> {
});
}
let ty = self.convert_type(type_id)?;
self.compute_size_of_ty(ty)
self.mk_size_of_ty_expr(ty)
}

fn compute_size_of_ty(&self, ty: Box<Type>) -> TranslationResult<WithStmts<Box<Expr>>> {
fn mk_size_of_ty_expr(&self, ty: Box<Type>) -> TranslationResult<WithStmts<Box<Expr>>> {
let name = "size_of";
let params = mk().angle_bracketed_args(vec![ty]);
let path = vec![
Expand Down Expand Up @@ -3181,8 +3182,7 @@ impl<'c> Translation<'c> {
Ok(WithStmts::new_val(call))
}

// Fixing this would require major refactors for marginal benefit.
#[allow(clippy::vec_box)]
#[allow(clippy::vec_box/*, reason = "not worth a substantial refactor"*/)]
fn convert_exprs(
&self,
ctx: ExprContext,
Expand Down
Loading