|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +thread_local!( |
| 10 | + pub static ctorCount_0: Value<i32> = Rc::new(RefCell::new(0)); |
| 11 | +); |
| 12 | +thread_local!( |
| 13 | + pub static copyCount_1: Value<i32> = Rc::new(RefCell::new(0)); |
| 14 | +); |
| 15 | +thread_local!( |
| 16 | + pub static dtorCount_2: Value<i32> = Rc::new(RefCell::new(0)); |
| 17 | +); |
| 18 | +thread_local!( |
| 19 | + pub static useCount_3: Value<i32> = Rc::new(RefCell::new(0)); |
| 20 | +); |
| 21 | +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] |
| 22 | +#[byte_size(4)] |
| 23 | +pub struct LifetimeTracked { |
| 24 | + #[offset(0)] |
| 25 | + pub uses: i32, |
| 26 | +} |
| 27 | +impl LifetimeTracked { |
| 28 | + pub fn new() -> Self { |
| 29 | + let __this: LifetimeTracked = Self { uses: 0 }; |
| 30 | + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); |
| 31 | + __this |
| 32 | + } |
| 33 | + pub fn copy_from(_a0: Ptr<LifetimeTracked>) -> Self { |
| 34 | + let __this: LifetimeTracked = Self { uses: 0 }; |
| 35 | + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); |
| 36 | + __this |
| 37 | + } |
| 38 | +} |
| 39 | +impl Clone for LifetimeTracked { |
| 40 | + fn clone(&self) -> Self { |
| 41 | + let __src: Value<LifetimeTracked> = Rc::new(RefCell::new(LifetimeTracked { |
| 42 | + uses: self.uses.clone(), |
| 43 | + })); |
| 44 | + LifetimeTracked::copy_from(__src.as_pointer()) |
| 45 | + } |
| 46 | +} |
| 47 | +impl Default for LifetimeTracked { |
| 48 | + fn default() -> Self { |
| 49 | + { LifetimeTracked::new() } |
| 50 | + } |
| 51 | +} |
| 52 | +thread_local!( |
| 53 | + pub static else_runs_4: Value<i32> = Rc::new(RefCell::new(0_i32)); |
| 54 | +); |
| 55 | +pub fn g_5(mut _a0: i32) { |
| 56 | + { |
| 57 | + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); |
| 58 | + } |
| 59 | +} |
| 60 | +pub fn g_6(mut _a0: i8) { |
| 61 | + { |
| 62 | + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); |
| 63 | + } |
| 64 | +} |
| 65 | +pub fn main() { |
| 66 | + __cpp2rust_init_globals(); |
| 67 | + std::process::exit(main_0()); |
| 68 | +} |
| 69 | +fn main_0() -> i32 { |
| 70 | + ({ g_5(1) }); |
| 71 | + ({ g_6(('c' as i8)) }); |
| 72 | + assert!((else_runs_4.with(|rc| *rc.borrow()) == 2)); |
| 73 | + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); |
| 74 | + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); |
| 75 | + return 0; |
| 76 | +} |
| 77 | +pub trait LifetimeTrackedImpl { |
| 78 | + fn destructor(&self); |
| 79 | + fn use_(&self); |
| 80 | + fn copy_assign(&self, _a0: Ptr<LifetimeTracked>) -> Ptr<LifetimeTracked>; |
| 81 | +} |
| 82 | +impl LifetimeTrackedImpl for Ptr<LifetimeTracked> { |
| 83 | + fn destructor(&self) { |
| 84 | + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); |
| 85 | + } |
| 86 | + fn use_(&self) { |
| 87 | + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); |
| 88 | + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); |
| 89 | + } |
| 90 | + fn copy_assign(&self, _a0: Ptr<LifetimeTracked>) -> Ptr<LifetimeTracked> { |
| 91 | + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); |
| 92 | + return (*self).clone(); |
| 93 | + } |
| 94 | +} |
| 95 | +pub fn __cpp2rust_init_globals() { |
| 96 | + let _ = ctorCount_0.with(|_| ()); |
| 97 | + let _ = copyCount_1.with(|_| ()); |
| 98 | + let _ = dtorCount_2.with(|_| ()); |
| 99 | + let _ = useCount_3.with(|_| ()); |
| 100 | + let _ = else_runs_4.with(|_| ()); |
| 101 | +} |
0 commit comments