Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/internal-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
export C2RUST_DIR=$PWD
# Needs to be run from `tests/integration/` (or further inside)
# to correctly load the `pyproject.toml`.
(cd tests/integration && ./test.py curl json-c lua nginx zstd libxml2 python2 libmcs)
(cd tests/integration && ./test.py nginx)

- uses: actions/upload-artifact@v4
with:
Expand Down
20 changes: 20 additions & 0 deletions c2rust-ast-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,26 @@ impl Builder {
}))
}

pub fn const_impl_item<I>(self, name: I, ty: Box<Type>, init: Box<Expr>) -> ImplItem
where
I: Make<Ident>,
{
let name = name.make(&self);
ImplItem::Const(ImplItemConst {
attrs: self.attrs,
vis: self.vis,
defaultness: None,
const_token: Token![const](self.span),
ident: name,
generics: self.generics,
colon_token: Token![:](self.span),
ty: *ty,
eq_token: Token![=](self.span),
expr: *init,
semi_token: Token![;](self.span),
})
}

pub fn fn_item<S>(self, sig: S, mut block: Block) -> Box<Item>
where
S: Make<Signature>,
Expand Down
7 changes: 6 additions & 1 deletion c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,11 +2625,16 @@ class TranslateASTVisitor final

void TypeEncoder::VisitEnumType(const EnumType *T) {
auto ed = T->getDecl()->getDefinition();

if (!ed) {
ed = T->getDecl()->getCanonicalDecl();
}

encodeType(T, TagEnumType, [T, ed](CborEncoder *local) {
cbor_encode_uint(local, uintptr_t(ed));
});

if (ed != nullptr) astEncoder->TraverseDecl(ed);
astEncoder->TraverseDecl(ed);
}

void TypeEncoder::VisitRecordType(const RecordType *T) {
Expand Down
12 changes: 10 additions & 2 deletions c2rust-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ impl VisitorImpls {
let folder_ident = Ident::new(&folder_name, Span::call_site());

if !walk.stmts.is_empty() {
let noop_fn_name = format!("noop_{}", method_name);
let noop_fn_name = if method_name == "flat_map_trait_item" {
String::from("noop_flat_map_assoc_item")
} else {
format!("noop_{}", method_name)
};
let noop_fn = Ident::new(&noop_fn_name, Span::call_site());
self.tokens.extend(quote! {
impl WalkAst for #ty {
Expand Down Expand Up @@ -84,7 +88,11 @@ impl VisitorImpls {
let folder_ident = Ident::new(&folder_name, Span::call_site());

if !walk.stmts.is_empty() {
let noop_fn_name = format!("noop_{}", method_name);
let noop_fn_name = if method_name == "flat_map_trait_item" {
String::from("noop_flat_map_assoc_item")
} else {
format!("noop_{}", method_name)
};
let noop_fn = Ident::new(&noop_fn_name, Span::call_site());
self.tokens.extend(quote! {
impl WalkAst for #ty {
Expand Down
8 changes: 8 additions & 0 deletions c2rust-refactor/src/ast_manip/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ pub trait MutVisitor: Sized {
noop_flat_map_item(i, self)
}

fn flat_map_trait_item(
&mut self,
i: P<AssocItem>,
ctxt: AssocCtxt,
) -> SmallVec<[P<AssocItem>; 1]> {
noop_flat_map_assoc_item(i, self)
}

fn visit_fn_header(&mut self, header: &mut FnHeader) {
noop_visit_fn_header(header, self);
}
Expand Down
9 changes: 9 additions & 0 deletions c2rust-refactor/src/transform/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ impl Transform for RenameUnnamed {
renamer
.new_idents
.insert(cx.hir_map().node_to_hir_id(i.id), new_name);

if let ItemKind::Struct(variant_data, _) | ItemKind::Union(variant_data, _) = &i.kind {
if let Some(ctor_id) = variant_data.ctor_id() {
renamer
.new_idents
.insert(cx.hir_map().node_to_hir_id(ctor_id), new_name);
}
}

renamer.new_to_old.insert(new_name, i.ident);
counter += 1;
smallvec![i.map(|i| Item {
Expand Down
Loading
Loading