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
12 changes: 8 additions & 4 deletions rules/any/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ fn f14<T1: 'static>(a0: &mut Option<Rc<dyn std::any::Any>>, init: cpp_type!("std
}

fn f19<T1: 'static>(a0: Ptr<Option<Rc<dyn std::any::Any>>>) -> Ptr<T1> {
a0.with(|__a: &Option<Rc<dyn std::any::Any>>| match __a.clone().map(|__r| __r.downcast::<RefCell<T1>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
})
if a0.is_null() {
Ptr::null()
} else {
a0.with(|__a: &Option<Rc<dyn std::any::Any>>| match __a.clone().map(|__r| __r.downcast::<RefCell<T1>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
})
}
}

fn f27<T1: 'static>(init: cpp_type!("std::decay_t<T1>", T1)) -> Option<Rc<dyn std::any::Any>> {
Expand Down
2 changes: 1 addition & 1 deletion rules/any/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ unsafe fn f14<T1: 'static>(a0: &mut Option<Box<dyn std::any::Any>>, init: cpp_ty
}

unsafe fn f19<T1: 'static>(a0: *mut Option<Box<dyn std::any::Any>>) -> *mut T1 {
match (*a0).as_mut().and_then(|__b| __b.downcast_mut::<T1>()) {
match a0.as_mut().and_then(|__a| __a.as_mut()).and_then(|__b| __b.downcast_mut::<T1>()) {
Some(__v) => __v as *mut T1,
None => std::ptr::null_mut(),
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ int main() {
b.reset();
assert(!b.has_value());
assert(std::any_cast<int>(&b) == nullptr);
std::any *n = nullptr;
assert(std::any_cast<int>(n) == nullptr);
return 0;
}
113 changes: 82 additions & 31 deletions tests/unit/out/refcount/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,38 @@ fn main_0() -> i32 {
RefCell::new(Point::new({ 3 }, { 4 })),
))));
assert!(({ (*a.borrow()).is_some() }));
let mut p: Ptr<Point> = (a.as_pointer()).with(|__a: &Option<Rc<dyn std::any::Any>>| match __a
.clone()
.map(|__r| __r.downcast::<RefCell<Point>>())
{
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
});
let mut p: Ptr<Point> = match ({ (a.as_pointer()) },) {
(mut __tmp_0,) => {
if __tmp_0.is_null() {
Ptr::null()
} else {
__tmp_0.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<Point>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
}
}
};
assert!(!((p).is_null()));
assert!((p.with(|__s| __s.x) == 3));
assert!((p.with(|__s| __s.y) == 4));
assert!(
((a.as_pointer()).with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
(match ({ (a.as_pointer()) },) {
(mut __tmp_1,) => {
if __tmp_1.is_null() {
Ptr::null()
} else {
__tmp_1.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
}
}
}))
})
.is_null()
);
let q: Ptr<Point> = {
Expand All @@ -55,38 +70,74 @@ fn main_0() -> i32 {
};
assert!((q.with(|__s| __s.x) == 5));
assert!(
((a.as_pointer())
.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<Point>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
(match ({ (a.as_pointer()) },) {
(mut __tmp_2,) => {
if __tmp_2.is_null() {
Ptr::null()
} else {
__tmp_2.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<Point>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
}
})
.with(|__s| __s.y)
}
}
.with(|__s| __s.y)
== 6)
);
let b: Value<Option<Rc<dyn std::any::Any>>> =
Rc::new(RefCell::new(Some(Rc::new(RefCell::new(7)))));
assert!(
(((b.as_pointer())
.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
((match ({ (b.as_pointer()) },) {
(mut __tmp_3,) => {
if __tmp_3.is_null() {
Ptr::null()
} else {
__tmp_3.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
}
})
.read())
}
}
.read())
== 7)
);
(*b.borrow_mut()) = None;
assert!(({ !((*b.borrow()).is_some()) }));
assert!(
((b.as_pointer()).with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
(match ({ (b.as_pointer()) },) {
(mut __tmp_4,) => {
if __tmp_4.is_null() {
Ptr::null()
} else {
__tmp_4.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
}
}
}))
})
.is_null()
);
let mut n: Ptr<Option<Rc<dyn std::any::Any>>> = Ptr::<Option<Rc<dyn std::any::Any>>>::null();
assert!(
(if n.is_null() {
Ptr::null()
} else {
n.with(|__a: &Option<Rc<dyn std::any::Any>>| {
match __a.clone().map(|__r| __r.downcast::<RefCell<i32>>()) {
Some(Ok(__v)) => __v.as_pointer(),
_ => Ptr::null(),
}
})
})
.is_null()
);
return 0;
Expand Down
27 changes: 22 additions & 5 deletions tests/unit/out/unsafe/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ pub fn main() {
unsafe fn main_0() -> i32 {
let mut a: Option<Box<dyn std::any::Any>> = Some(Box::new(Point::new({ 3 }, { 4 })));
assert!(a.is_some());
let mut p: *mut Point = match (*(&mut a as *mut Option<Box<dyn std::any::Any>>))
let mut p: *mut Point = match (&mut a as *mut Option<Box<dyn std::any::Any>>)
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<Point>())
{
Some(__v) => __v as *mut Point,
Expand All @@ -38,8 +39,9 @@ unsafe fn main_0() -> i32 {
assert!((((*p).x) == (3)));
assert!((((*p).y) == (4)));
assert!(
(match (*(&mut a as *mut Option<Box<dyn std::any::Any>>))
(match (&mut a as *mut Option<Box<dyn std::any::Any>>)
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<i32>())
{
Some(__v) => __v as *mut i32,
Expand All @@ -53,8 +55,9 @@ unsafe fn main_0() -> i32 {
};
assert!((((*q).x) == (5)));
assert!(
(((*match (*(&mut a as *mut Option<Box<dyn std::any::Any>>))
(((*match (&mut a as *mut Option<Box<dyn std::any::Any>>)
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<Point>())
{
Some(__v) => __v as *mut Point,
Expand All @@ -64,8 +67,9 @@ unsafe fn main_0() -> i32 {
);
let mut b: Option<Box<dyn std::any::Any>> = Some(Box::new(7));
assert!(
((*match (*(&mut b as *mut Option<Box<dyn std::any::Any>>))
((*match (&mut b as *mut Option<Box<dyn std::any::Any>>)
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<i32>())
{
Some(__v) => __v as *mut i32,
Expand All @@ -75,8 +79,21 @@ unsafe fn main_0() -> i32 {
b = None;
assert!(!(b.is_some()));
assert!(
(match (*(&mut b as *mut Option<Box<dyn std::any::Any>>))
(match (&mut b as *mut Option<Box<dyn std::any::Any>>)
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<i32>())
{
Some(__v) => __v as *mut i32,
None => std::ptr::null_mut(),
})
.is_null()
);
let mut n: *mut Option<Box<dyn std::any::Any>> = std::ptr::null_mut();
assert!(
(match n
.as_mut()
.and_then(|__a| __a.as_mut())
.and_then(|__b| __b.downcast_mut::<i32>())
{
Some(__v) => __v as *mut i32,
Expand Down
Loading