|
| 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 | +pub type Overload = u32; |
| 10 | +pub const Overload_kMutableOverload: Overload = 1; |
| 11 | +pub const Overload_kConstOverload: Overload = 2; |
| 12 | +#[derive(Default)] |
| 13 | +pub struct S { |
| 14 | + pub v: Value<i32>, |
| 15 | +} |
| 16 | +impl Clone for S { |
| 17 | + fn clone(&self) -> Self { |
| 18 | + let __this: Value<S> = Rc::new(RefCell::new(Self { |
| 19 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 20 | + })); |
| 21 | + let this: Ptr<S> = __this.as_pointer(); |
| 22 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 23 | + } |
| 24 | +} |
| 25 | +impl ByteRepr for S { |
| 26 | + fn byte_size() -> usize { |
| 27 | + 4 |
| 28 | + } |
| 29 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 30 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 31 | + } |
| 32 | + fn from_bytes(buf: &[u8]) -> Self { |
| 33 | + Self { |
| 34 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | +pub fn g_0(_a0: Ptr<S>) -> Overload { |
| 39 | + return Overload_kMutableOverload; |
| 40 | +} |
| 41 | +pub fn g_1(_a0: Ptr<S>) -> Overload { |
| 42 | + return Overload_kConstOverload; |
| 43 | +} |
| 44 | +pub fn main() { |
| 45 | + __cpp2rust_init_globals(); |
| 46 | + std::process::exit(main_0()); |
| 47 | +} |
| 48 | +fn main_0() -> i32 { |
| 49 | + let s: Value<S> = Rc::new(RefCell::new(S { |
| 50 | + v: Rc::new(RefCell::new(7)), |
| 51 | + })); |
| 52 | + assert!(((({ SImpl::f(&s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); |
| 53 | + assert!(((({ SImpl::f_const(&s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); |
| 54 | + assert!(((({ g_0(s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); |
| 55 | + assert!(((({ g_1(s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); |
| 56 | + ({ SImpl::value_ref(&s.as_pointer()) }).write(9); |
| 57 | + assert!(((*(*s.borrow()).v.borrow()) == 9)); |
| 58 | + assert!(((({ SImpl::value_ref_const(&s.as_pointer(),) }).read()) == 9)); |
| 59 | + let cs: Ptr<S> = s.as_pointer(); |
| 60 | + assert!(((({ SImpl::f_const(&cs,) }) as i32) == (Overload_kConstOverload as i32))); |
| 61 | + assert!(((*(*cs.upgrade().deref()).v.borrow()) == 9)); |
| 62 | + return 0; |
| 63 | +} |
| 64 | +pub trait SImpl { |
| 65 | + fn f(&self) -> Overload; |
| 66 | + fn f_const(&self) -> Overload; |
| 67 | + fn value_ref(&self) -> Ptr<i32>; |
| 68 | + fn value_ref_const(&self) -> Ptr<i32>; |
| 69 | +} |
| 70 | +impl SImpl for Ptr<S> { |
| 71 | + fn f(&self) -> Overload { |
| 72 | + return Overload_kMutableOverload; |
| 73 | + } |
| 74 | + fn f_const(&self) -> Overload { |
| 75 | + return Overload_kConstOverload; |
| 76 | + } |
| 77 | + fn value_ref(&self) -> Ptr<i32> { |
| 78 | + return (*(*self).upgrade().deref()).v.as_pointer(); |
| 79 | + } |
| 80 | + fn value_ref_const(&self) -> Ptr<i32> { |
| 81 | + return (*(*self).upgrade().deref()).v.as_pointer(); |
| 82 | + } |
| 83 | +} |
| 84 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments