|
| 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 | +#[derive()] |
| 10 | +pub struct A { |
| 11 | + pub v: Value<i32>, |
| 12 | +} |
| 13 | +impl A { |
| 14 | + pub fn A1() -> Self { |
| 15 | + let __this: Value<A> = Rc::new(RefCell::new(Self { |
| 16 | + v: Rc::new(RefCell::new(1)), |
| 17 | + })); |
| 18 | + let this: Ptr<A> = __this.as_pointer(); |
| 19 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 20 | + } |
| 21 | + pub fn A2(v: i32) -> Self { |
| 22 | + let v: Value<i32> = Rc::new(RefCell::new(v)); |
| 23 | + let __this: Value<A> = Rc::new(RefCell::new(Self { |
| 24 | + v: Rc::new(RefCell::new((*v.borrow()))), |
| 25 | + })); |
| 26 | + let this: Ptr<A> = __this.as_pointer(); |
| 27 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 28 | + } |
| 29 | +} |
| 30 | +impl Clone for A { |
| 31 | + fn clone(&self) -> Self { |
| 32 | + let __this: Value<A> = Rc::new(RefCell::new(Self { |
| 33 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 34 | + })); |
| 35 | + let this: Ptr<A> = __this.as_pointer(); |
| 36 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 37 | + } |
| 38 | +} |
| 39 | +impl Default for A { |
| 40 | + fn default() -> Self { |
| 41 | + { A::A1() } |
| 42 | + } |
| 43 | +} |
| 44 | +impl ByteRepr for A { |
| 45 | + fn byte_size() -> usize { |
| 46 | + 4 |
| 47 | + } |
| 48 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 49 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 50 | + } |
| 51 | + fn from_bytes(buf: &[u8]) -> Self { |
| 52 | + Self { |
| 53 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +#[derive()] |
| 58 | +pub struct B { |
| 59 | + pub v: Value<i32>, |
| 60 | +} |
| 61 | +impl B { |
| 62 | + pub fn B() -> Self { |
| 63 | + let __this: Value<B> = Rc::new(RefCell::new(Self { |
| 64 | + v: Rc::new(RefCell::new(2)), |
| 65 | + })); |
| 66 | + let this: Ptr<B> = __this.as_pointer(); |
| 67 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 68 | + } |
| 69 | +} |
| 70 | +impl Clone for B { |
| 71 | + fn clone(&self) -> Self { |
| 72 | + let __this: Value<B> = Rc::new(RefCell::new(Self { |
| 73 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 74 | + })); |
| 75 | + let this: Ptr<B> = __this.as_pointer(); |
| 76 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 77 | + } |
| 78 | +} |
| 79 | +impl Default for B { |
| 80 | + fn default() -> Self { |
| 81 | + { B::B() } |
| 82 | + } |
| 83 | +} |
| 84 | +impl ByteRepr for B { |
| 85 | + fn byte_size() -> usize { |
| 86 | + 4 |
| 87 | + } |
| 88 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 89 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 90 | + } |
| 91 | + fn from_bytes(buf: &[u8]) -> Self { |
| 92 | + Self { |
| 93 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +#[derive(Default)] |
| 98 | +pub struct NoDefault { |
| 99 | + pub v: Value<i32>, |
| 100 | +} |
| 101 | +impl NoDefault { |
| 102 | + pub fn NoDefault(v: i32) -> Self { |
| 103 | + let v: Value<i32> = Rc::new(RefCell::new(v)); |
| 104 | + let __this: Value<NoDefault> = Rc::new(RefCell::new(Self { |
| 105 | + v: Rc::new(RefCell::new((*v.borrow()))), |
| 106 | + })); |
| 107 | + let this: Ptr<NoDefault> = __this.as_pointer(); |
| 108 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 109 | + } |
| 110 | +} |
| 111 | +impl Clone for NoDefault { |
| 112 | + fn clone(&self) -> Self { |
| 113 | + let __this: Value<NoDefault> = Rc::new(RefCell::new(Self { |
| 114 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 115 | + })); |
| 116 | + let this: Ptr<NoDefault> = __this.as_pointer(); |
| 117 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 118 | + } |
| 119 | +} |
| 120 | +impl ByteRepr for NoDefault { |
| 121 | + fn byte_size() -> usize { |
| 122 | + 4 |
| 123 | + } |
| 124 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 125 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 126 | + } |
| 127 | + fn from_bytes(buf: &[u8]) -> Self { |
| 128 | + Self { |
| 129 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +pub fn used_0(x: Option<A>) -> i32 { |
| 134 | + let x: Value<A> = Rc::new(RefCell::new(x.unwrap_or(A::A1()))); |
| 135 | + return (*(*x.borrow()).v.borrow()); |
| 136 | +} |
| 137 | +pub fn used_1(x: Option<B>) -> i32 { |
| 138 | + let x: Value<B> = Rc::new(RefCell::new(x.unwrap_or(B::B()))); |
| 139 | + return (*(*x.borrow()).v.borrow()); |
| 140 | +} |
| 141 | +pub fn scaled_2(x: A, n: Option<i32>) -> i32 { |
| 142 | + let x: Value<A> = Rc::new(RefCell::new(x)); |
| 143 | + let n: Value<i32> = Rc::new(RefCell::new(n.unwrap_or((4usize as i32)))); |
| 144 | + return ((*(*x.borrow()).v.borrow()) * (*n.borrow())); |
| 145 | +} |
| 146 | +pub fn always_given_3(x: Option<NoDefault>) -> i32 { |
| 147 | + let x: Value<NoDefault> = Rc::new(RefCell::new(x.unwrap_or())); |
| 148 | + return (*(*x.borrow()).v.borrow()); |
| 149 | +} |
| 150 | +#[derive(Default)] |
| 151 | +pub struct S_NoDefault_ { |
| 152 | + pub v: Value<i32>, |
| 153 | +} |
| 154 | +impl S_NoDefault_ { |
| 155 | + pub fn S_NoDefault_(v: i32) -> Self { |
| 156 | + let v: Value<i32> = Rc::new(RefCell::new(v)); |
| 157 | + let __this: Value<S_NoDefault_> = Rc::new(RefCell::new(Self { |
| 158 | + v: Rc::new(RefCell::new((*v.borrow()))), |
| 159 | + })); |
| 160 | + let this: Ptr<S_NoDefault_> = __this.as_pointer(); |
| 161 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 162 | + } |
| 163 | +} |
| 164 | +impl Clone for S_NoDefault_ { |
| 165 | + fn clone(&self) -> Self { |
| 166 | + let __this: Value<S_NoDefault_> = Rc::new(RefCell::new(Self { |
| 167 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 168 | + })); |
| 169 | + let this: Ptr<S_NoDefault_> = __this.as_pointer(); |
| 170 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 171 | + } |
| 172 | +} |
| 173 | +impl ByteRepr for S_NoDefault_ { |
| 174 | + fn byte_size() -> usize { |
| 175 | + 4 |
| 176 | + } |
| 177 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 178 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 179 | + } |
| 180 | + fn from_bytes(buf: &[u8]) -> Self { |
| 181 | + Self { |
| 182 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 183 | + } |
| 184 | + } |
| 185 | +} |
| 186 | +pub fn main() { |
| 187 | + __cpp2rust_init_globals(); |
| 188 | + std::process::exit(main_0()); |
| 189 | +} |
| 190 | +fn main_0() -> i32 { |
| 191 | + assert!((({ used_0(None,) }) == 1)); |
| 192 | + assert!((({ used_0(Some(A::A2({ 5 },)),) }) == 5)); |
| 193 | + assert!((({ used_1(None,) }) == 2)); |
| 194 | + assert!((({ scaled_2(A::A2({ 3 },), None,) }) == (3 * (4usize as i32)))); |
| 195 | + assert!((({ scaled_2(A::A2({ 3 },), Some(2),) }) == 6)); |
| 196 | + assert!((({ always_given_3(Some(NoDefault::NoDefault({ 3 },)),) }) == 3)); |
| 197 | + let s: Value<S_NoDefault_> = Rc::new(RefCell::new(S_NoDefault_::S_NoDefault_({ 1 }))); |
| 198 | + assert!( |
| 199 | + (({ S_NoDefault_Impl::get(&s.as_pointer(), Some(NoDefault::NoDefault({ 4 },)),) }) == 5) |
| 200 | + ); |
| 201 | + return 0; |
| 202 | +} |
| 203 | +pub trait S_NoDefault_Impl { |
| 204 | + fn get(&self, t: Option<NoDefault>) -> i32; |
| 205 | +} |
| 206 | +impl S_NoDefault_Impl for Ptr<S_NoDefault_> { |
| 207 | + fn get(&self, t: Option<NoDefault>) -> i32 { |
| 208 | + let t: Value<NoDefault> = Rc::new(RefCell::new(t.unwrap_or())); |
| 209 | + return ((*(*(*self).upgrade().deref()).v.borrow()) + (*(*t.borrow()).v.borrow())); |
| 210 | + } |
| 211 | +} |
| 212 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments