diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index f932fa23..2ce0f85e 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -207,10 +207,6 @@ bool TypeImplementsByteRepr(clang::QualType qt) { return TypeImplementsByteRepr(arr->getElementType()); } if (const auto *rd = qt->getAsRecordDecl()) { - if (rd->getASTContext().getSourceManager().isInSystemHeader( - rd->getLocation())) { - return false; - } if (rd->isUnion()) { return true; } diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 3d31d3a9..bfd0462f 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -20,7 +20,21 @@ impl Clone for NonCopy { this } } -impl ByteRepr for NonCopy {} +impl ByteRepr for NonCopy { + fn byte_size() -> usize { + 32 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.data.borrow()).to_bytes(&mut buf[0..24]); + (*self.tag.borrow()).to_bytes(&mut buf[24..28]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + data: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + tag: Rc::new(RefCell::new(::from_bytes(&buf[24..28]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index 3cbce86e..183fbd41 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -42,7 +42,19 @@ impl Clone for MyContainer_int_ { this } } -impl ByteRepr for MyContainer_int_ {} +impl ByteRepr for MyContainer_int_ { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.vec_.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + vec_: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} #[derive(Default)] pub struct MyContainer_char_ { vec_: Value>, @@ -79,7 +91,19 @@ impl Clone for MyContainer_char_ { this } } -impl ByteRepr for MyContainer_char_ {} +impl ByteRepr for MyContainer_char_ { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.vec_.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + vec_: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} #[derive(Default)] pub struct MyContainer_float_ { vec_: Value>, @@ -116,7 +140,19 @@ impl Clone for MyContainer_float_ { this } } -impl ByteRepr for MyContainer_float_ {} +impl ByteRepr for MyContainer_float_ { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.vec_.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + vec_: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 66c9e892..57c56051 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -20,7 +20,21 @@ impl Clone for S { this } } -impl ByteRepr for S {} +impl ByteRepr for S { + fn byte_size() -> usize { + 32 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.v.borrow()).to_bytes(&mut buf[0..24]); + (*self.a.borrow()).to_bytes(&mut buf[24..28]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + v: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + a: Rc::new(RefCell::new(::from_bytes(&buf[24..28]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index f023a545..e2f608af 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -218,7 +218,31 @@ impl MinHeap { } } } -impl ByteRepr for MinHeap {} +impl ByteRepr for MinHeap { + fn byte_size() -> usize { + 32 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.size.borrow()).to_bytes(&mut buf[0..4]); + (*self.capacity.borrow()).to_bytes(&mut buf[4..8]); + (*self.arr.borrow()).to_bytes(&mut buf[8..16]); + (*self.next.borrow()).to_bytes(&mut buf[16..20]); + (*self.alloc.borrow()).to_bytes(&mut buf[24..32]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + size: Rc::new(RefCell::new(::from_bytes(&buf[0..4]))), + capacity: Rc::new(RefCell::new(::from_bytes(&buf[4..8]))), + arr: Rc::new(RefCell::new( + ]>>>>::from_bytes(&buf[8..16]), + )), + next: Rc::new(RefCell::new(::from_bytes(&buf[16..20]))), + alloc: Rc::new(RefCell::new( + >>>::from_bytes(&buf[24..32]), + )), + } + } +} pub fn AllocMinHeap_1(capacity: i32) -> Option> { let capacity: Value = Rc::new(RefCell::new(capacity)); let minHeap: Value>> = diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index a406be11..0b29d399 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -18,7 +18,19 @@ impl Clone for Holder { this } } -impl ByteRepr for Holder {} +impl ByteRepr for Holder { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.v.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + v: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} pub fn write_through_0(p: Ptr) { let p: Value> = Rc::new(RefCell::new(p)); (*p.borrow()).write(42); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index d5277b51..b07c301e 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -280,14 +280,52 @@ impl DisjointSet { } } } -impl ByteRepr for DisjointSet {} +impl ByteRepr for DisjointSet { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.rank.borrow()).to_bytes(&mut buf[0..8]); + (*self.parent.borrow()).to_bytes(&mut buf[8..16]); + (*self.n.borrow()).to_bytes(&mut buf[16..20]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + rank: Rc::new(RefCell::new(>>>::from_bytes( + &buf[0..8], + ))), + parent: Rc::new(RefCell::new(>>>::from_bytes( + &buf[8..16], + ))), + n: Rc::new(RefCell::new(::from_bytes(&buf[16..20]))), + } + } +} #[derive(Default)] pub struct Graph { pub edges: Value>>>, pub V: Value, pub E: Value, } -impl ByteRepr for Graph {} +impl ByteRepr for Graph { + fn byte_size() -> usize { + 16 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.edges.borrow()).to_bytes(&mut buf[0..8]); + (*self.V.borrow()).to_bytes(&mut buf[8..12]); + (*self.E.borrow()).to_bytes(&mut buf[12..16]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + edges: Rc::new(RefCell::new(>>>::from_bytes( + &buf[0..8], + ))), + V: Rc::new(RefCell::new(::from_bytes(&buf[8..12]))), + E: Rc::new(RefCell::new(::from_bytes(&buf[12..16]))), + } + } +} pub fn MSTKruskal_2(graph: Ptr) -> f64 { ({ let _arr: Ptr>>> = (*graph.upgrade().deref()).edges.as_pointer(); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index 9e540565..15c703f6 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -30,7 +30,21 @@ impl Default for UserDefined { } } } -impl ByteRepr for UserDefined {} +impl ByteRepr for UserDefined { + fn byte_size() -> usize { + 32 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.a.borrow()).to_bytes(&mut buf[0..4]); + (*self.v.borrow()).to_bytes(&mut buf[8..32]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + a: Rc::new(RefCell::new(>::from_bytes(&buf[0..4]))), + v: Rc::new(RefCell::new(>::from_bytes(&buf[8..32]))), + } + } +} #[derive()] pub struct FieldIsLibcType { pub addr: Value, @@ -50,7 +64,19 @@ impl Default for FieldIsLibcType { } } } -impl ByteRepr for FieldIsLibcType {} +impl ByteRepr for FieldIsLibcType { + fn byte_size() -> usize { + 16 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.addr.borrow()).to_bytes(&mut buf[0..16]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + addr: Rc::new(RefCell::new(::from_bytes(&buf[0..16]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 07e74001..953a075c 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -84,7 +84,23 @@ impl Clone for JPEGData { this } } -impl ByteRepr for JPEGData {} +impl ByteRepr for JPEGData { + fn byte_size() -> usize { + 48 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.com_data.borrow()).to_bytes(&mut buf[0..24]); + (*self.app_data.borrow()).to_bytes(&mut buf[24..48]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + com_data: Rc::new(RefCell::new(>>>::from_bytes(&buf[0..24]))), + app_data: Rc::new(RefCell::new(>>>::from_bytes( + &buf[24..48], + ))), + } + } +} pub fn push_param_0(dest: Ptr>>>) { let dest: Value>>>> = Rc::new(RefCell::new(dest)); ((*dest.borrow()).to_strong().as_pointer() as Ptr>>>).with_mut( diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 39e1bd87..62f7e73a 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -42,7 +42,23 @@ impl Default for WOFF2Params { { WOFF2Params::WOFF2Params() } } } -impl ByteRepr for WOFF2Params {} +impl ByteRepr for WOFF2Params { + fn byte_size() -> usize { + 40 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.extended_metadata.borrow()).to_bytes(&mut buf[0..32]); + (*self.brotli_quality.borrow()).to_bytes(&mut buf[32..36]); + (*self.allow_transforms.borrow()).to_bytes(&mut buf[36..37]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + extended_metadata: Rc::new(RefCell::new(>::from_bytes(&buf[0..32]))), + brotli_quality: Rc::new(RefCell::new(::from_bytes(&buf[32..36]))), + allow_transforms: Rc::new(RefCell::new(::from_bytes(&buf[36..37]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index ebc6ad42..42c27e37 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -47,7 +47,19 @@ impl Clone for Outer { this } } -impl ByteRepr for Outer {} +impl ByteRepr for Outer { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.runs.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + runs: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 8f570b48..9d4eb0eb 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -15,7 +15,19 @@ impl SafePointer { (*(*self.ptr.borrow_mut()).as_ref().unwrap().borrow_mut()).prefix_inc(); } } -impl ByteRepr for SafePointer {} +impl ByteRepr for SafePointer { + fn byte_size() -> usize { + 8 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.ptr.borrow()).to_bytes(&mut buf[0..8]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + ptr: Rc::new(RefCell::new(>>::from_bytes(&buf[0..8]))), + } + } +} #[derive(Default)] pub struct Pair { pub x: Value, diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index ee468020..8763aa17 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -10,7 +10,19 @@ use std::rc::{Rc, Weak}; pub struct Holder { pub val: Value>>, } -impl ByteRepr for Holder {} +impl ByteRepr for Holder { + fn byte_size() -> usize { + 8 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.val.borrow()).to_bytes(&mut buf[0..8]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + val: Rc::new(RefCell::new(>>::from_bytes(&buf[0..8]))), + } + } +} pub fn read_val_0(h: Ptr) -> i32 { let h: Value> = Rc::new(RefCell::new(h)); return (*(*(*(*h.borrow()).upgrade().deref()).val.borrow()) diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index e1ad9181..73a07682 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -39,7 +39,19 @@ impl ByteRepr for Inner { pub struct Outer { pub inner: Value>>, } -impl ByteRepr for Outer {} +impl ByteRepr for Outer { + fn byte_size() -> usize { + 8 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.inner.borrow()).to_bytes(&mut buf[0..8]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + inner: Rc::new(RefCell::new(>>::from_bytes(&buf[0..8]))), + } + } +} pub fn main() { std::process::exit(main_0()); } diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 0933260f..f8b0af11 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -22,7 +22,19 @@ impl Clone for NonTrivial { this } } -impl ByteRepr for NonTrivial {} +impl ByteRepr for NonTrivial { + fn byte_size() -> usize { + 24 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.data.borrow()).to_bytes(&mut buf[0..24]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + data: Rc::new(RefCell::new(>::from_bytes(&buf[0..24]))), + } + } +} pub fn unused_ref_param_1(x: Ptr) { (*x.upgrade().deref()).clone(); }