Skip to content

Commit 470ce10

Browse files
committed
Add more builtin types
1 parent 360a2a5 commit 470ce10

5 files changed

Lines changed: 46 additions & 4 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
138138
StrCat("f32");
139139
break;
140140
case clang::BuiltinType::Double:
141+
case clang::BuiltinType::LongDouble:
141142
StrCat("f64");
142143
break;
143144
case clang::BuiltinType::Char_S:
@@ -158,6 +159,11 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
158159
case clang::BuiltinType::Int:
159160
case clang::BuiltinType::Long:
160161
case clang::BuiltinType::LongLong:
162+
case clang::BuiltinType::WChar_S:
163+
case clang::BuiltinType::WChar_U:
164+
case clang::BuiltinType::Char8:
165+
case clang::BuiltinType::Char16:
166+
case clang::BuiltinType::Char32:
161167
StrCat(std::format("{}{}", type->isSignedInteger() ? 'i' : 'u',
162168
ctx_.getTypeSize(type)));
163169
break;
@@ -170,9 +176,13 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
170176
case clang::BuiltinType::Int128:
171177
StrCat("i128");
172178
break;
179+
case clang::BuiltinType::NullPtr:
180+
Convert(ctx_.VoidPtrTy);
181+
break;
173182
default:
174-
// FIXME: improve error handling
175-
log() << "unsupported builtin type\n";
183+
llvm::errs() << "unsupported builtin type: "
184+
<< type->getName(ctx_.getPrintingPolicy()) << '\n';
185+
assert(0 && "unsupported builtin type\n");
176186
break;
177187
}
178188
return false;

‎libcc2rs/src/reinterpret.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ impl_byte_repr!(u32);
6262
impl_byte_repr!(i32);
6363
impl_byte_repr!(u64);
6464
impl_byte_repr!(i64);
65+
impl_byte_repr!(u128);
66+
impl_byte_repr!(i128);
6567
impl_byte_repr!(usize);
6668
impl_byte_repr!(isize);
6769
impl_byte_repr!(f32);

‎tests/unit/out/refcount/types.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ fn main_0() -> i32 {
2121
let xi3: Value<i32> = Rc::new(RefCell::new(32));
2222
let xi4: Value<i64> = Rc::new(RefCell::new(64_i64));
2323
let b: Value<bool> = Rc::new(RefCell::new(((*xu64.borrow()) == 64_u64)));
24+
let xld: Value<f64> = Rc::new(RefCell::new(1.5E+0));
25+
let xwc: Value<i32> = Rc::new(RefCell::new(65_i32));
26+
let xc8: Value<u8> = Rc::new(RefCell::new(66_u8));
27+
let xc16: Value<u16> = Rc::new(RefCell::new(67_u16));
28+
let xc32: Value<u32> = Rc::new(RefCell::new(68_u32));
29+
let xnp: Value<Value<AnyPtr>> = Rc::new(RefCell::new(Default::default()));
2430
assert!(
2531
(((((((((((((*xu8.borrow()) as i32) + ((*xu16.borrow()) as i32)) as u32)
2632
.wrapping_add((*xu32.borrow()))) as u64)
@@ -33,5 +39,12 @@ fn main_0() -> i32 {
3339
.wrapping_add(((*xi4.borrow()) as u64))
3440
== 352_u64)
3541
);
42+
assert!((((*xld.borrow()) * 2_f64) == 3_f64));
43+
assert!(
44+
(((((*xwc.borrow()) + ((*xc8.borrow()) as i32)) + ((*xc16.borrow()) as i32)) as u32)
45+
.wrapping_add((*xc32.borrow()))
46+
== 266_u32)
47+
);
48+
assert!((<AnyPtr>::default()).is_null());
3649
return 0;
3750
}

‎tests/unit/out/unsafe/types.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ unsafe fn main_0() -> i32 {
2323
let mut xi3: i32 = 32;
2424
let mut xi4: i64 = 64_i64;
2525
let mut b: bool = ((xu64) == (64_u64));
26+
let mut xld: f64 = 1.5E+0;
27+
let mut xwc: i32 = 65_i32;
28+
let mut xc8: u8 = 66_u8;
29+
let mut xc16: u16 = 67_u16;
30+
let mut xc32: u32 = 68_u32;
31+
let mut xnp: *mut ::libc::c_void = Default::default();
2632
assert!(
2733
(((((((((((((xu8 as i32) + (xu16 as i32)) as u32).wrapping_add(xu32)) as u64)
2834
.wrapping_add(xu64))
@@ -34,5 +40,8 @@ unsafe fn main_0() -> i32 {
3440
.wrapping_add((xi4 as u64)))
3541
== (352_u64))
3642
);
43+
assert!((((xld) * (2_f64)) == (3_f64)));
44+
assert!(((((((xwc) + (xc8 as i32)) + (xc16 as i32)) as u32).wrapping_add(xc32)) == (266_u32)));
45+
assert!((<*mut ::libc::c_void>::default()).is_null());
3746
return 0;
3847
}

‎tests/unit/types.cpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Copyright (c) 2022-present INESC-ID.
2-
// Distributed under the MIT license that can be found in the LICENSE file.
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
32

43
#include <cassert>
54
#include <cstddef>
@@ -18,6 +17,15 @@ int main() {
1817
int32_t xi3 = 32;
1918
int64_t xi4 = 64;
2019
bool b = (xu64 == 64ULL);
20+
long double xld = 1.5;
21+
wchar_t xwc = 65;
22+
char8_t xc8 = 66;
23+
char16_t xc16 = 67;
24+
char32_t xc32 = 68;
25+
std::nullptr_t xnp = nullptr;
2126
assert(xu8 + xu16 + xu32 + xu64 + xsz1 + xsz2 + xi1 + xi2 + xi3 + xi4 == 352);
27+
assert(xld * 2 == 3);
28+
assert(xwc + xc8 + xc16 + xc32 == 266);
29+
assert(xnp == nullptr);
2230
return 0;
2331
}

0 commit comments

Comments
 (0)