|
| 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(Default)] |
| 10 | +pub struct S { |
| 11 | + pub base: Value<i32>, |
| 12 | +} |
| 13 | +impl Clone for S { |
| 14 | + fn clone(&self) -> Self { |
| 15 | + let __this: Value<S> = Rc::new(RefCell::new(Self { |
| 16 | + base: Rc::new(RefCell::new((*self.base.borrow()))), |
| 17 | + })); |
| 18 | + let this: Ptr<S> = __this.as_pointer(); |
| 19 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 20 | + } |
| 21 | +} |
| 22 | +impl ByteRepr for S { |
| 23 | + fn byte_size() -> usize { |
| 24 | + 4 |
| 25 | + } |
| 26 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 27 | + (*self.base.borrow()).to_bytes(&mut buf[0..4]); |
| 28 | + } |
| 29 | + fn from_bytes(buf: &[u8]) -> Self { |
| 30 | + Self { |
| 31 | + base: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | +#[derive(Default)] |
| 36 | +pub struct Box { |
| 37 | + pub v: Value<i32>, |
| 38 | +} |
| 39 | +impl Clone for Box { |
| 40 | + fn clone(&self) -> Self { |
| 41 | + let __this: Value<Box> = Rc::new(RefCell::new(Self { |
| 42 | + v: Rc::new(RefCell::new((*self.v.borrow()))), |
| 43 | + })); |
| 44 | + let this: Ptr<Box> = __this.as_pointer(); |
| 45 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 46 | + } |
| 47 | +} |
| 48 | +impl ByteRepr for Box { |
| 49 | + fn byte_size() -> usize { |
| 50 | + 4 |
| 51 | + } |
| 52 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 53 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 54 | + } |
| 55 | + fn from_bytes(buf: &[u8]) -> Self { |
| 56 | + Self { |
| 57 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +pub fn main() { |
| 62 | + std::process::exit(main_0()); |
| 63 | +} |
| 64 | +fn main_0() -> i32 { |
| 65 | + let s: Value<S> = Rc::new(RefCell::new(S { |
| 66 | + base: Rc::new(RefCell::new(100)), |
| 67 | + })); |
| 68 | + assert!((({ SImpl::width_i32__char_const(&s.as_pointer(), 3,) }) == 103)); |
| 69 | + assert!((({ SImpl::width_i32__int_const(&s.as_pointer(), 3,) }) == 112)); |
| 70 | + assert!((({ SImpl::scale_i32__2_const(&s.as_pointer(), 5,) }) == 110)); |
| 71 | + assert!((({ SImpl::scale_i32__3_const(&s.as_pointer(), 5,) }) == 115)); |
| 72 | + assert!((({ SImpl::count_i32_const(&s.as_pointer(), 1,) }) == 101)); |
| 73 | + assert!((({ SImpl::count_i32__int_long_const(&s.as_pointer(), 1,) }) == 103)); |
| 74 | + assert!((({ SImpl::plain_i32_const(&s.as_pointer(), 1,) }) == 101)); |
| 75 | + assert!((({ SImpl::plain_i64_const(&s.as_pointer(), 1_i64,) }) == 102)); |
| 76 | + let b: Value<Box> = Rc::new(RefCell::new(Box { |
| 77 | + v: Rc::new(RefCell::new(4)), |
| 78 | + })); |
| 79 | + assert!(((*(*b.borrow()).v.borrow()) == 4)); |
| 80 | + return 0; |
| 81 | +} |
| 82 | +pub trait SImpl { |
| 83 | + fn plain_i32_const(&self, x: i32) -> i32; |
| 84 | + fn plain_i64_const(&self, x: i64) -> i32; |
| 85 | + fn width_i32__char_const(&self, x: i32) -> i32; |
| 86 | + fn width_i32__int_const(&self, x: i32) -> i32; |
| 87 | + fn scale_i32__2_const(&self, x: i32) -> i32; |
| 88 | + fn scale_i32__3_const(&self, x: i32) -> i32; |
| 89 | + fn count_i32_const(&self, x: i32) -> i32; |
| 90 | + fn count_i32__int_long_const(&self, x: i32) -> i32; |
| 91 | +} |
| 92 | +impl SImpl for Ptr<S> { |
| 93 | + fn plain_i32_const(&self, x: i32) -> i32 { |
| 94 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 95 | + return ((*(*(*self).upgrade().deref()).base.borrow()) + (*x.borrow())); |
| 96 | + } |
| 97 | + fn plain_i64_const(&self, x: i64) -> i32 { |
| 98 | + let x: Value<i64> = Rc::new(RefCell::new(x)); |
| 99 | + return (((*(*(*self).upgrade().deref()).base.borrow()) + ((*x.borrow()) as i32)) + 1); |
| 100 | + } |
| 101 | + fn width_i32__char_const(&self, x: i32) -> i32 { |
| 102 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 103 | + return ((*(*(*self).upgrade().deref()).base.borrow()) |
| 104 | + + ((*x.borrow()) * (::std::mem::size_of::<u8>() as i32))); |
| 105 | + } |
| 106 | + fn width_i32__int_const(&self, x: i32) -> i32 { |
| 107 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 108 | + return ((*(*(*self).upgrade().deref()).base.borrow()) |
| 109 | + + ((*x.borrow()) * (::std::mem::size_of::<i32>() as i32))); |
| 110 | + } |
| 111 | + fn scale_i32__2_const(&self, x: i32) -> i32 { |
| 112 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 113 | + return ((*(*(*self).upgrade().deref()).base.borrow()) + ((*x.borrow()) * 2)); |
| 114 | + } |
| 115 | + fn scale_i32__3_const(&self, x: i32) -> i32 { |
| 116 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 117 | + return ((*(*(*self).upgrade().deref()).base.borrow()) + ((*x.borrow()) * 3)); |
| 118 | + } |
| 119 | + fn count_i32_const(&self, x: i32) -> i32 { |
| 120 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 121 | + return (((*(*(*self).upgrade().deref()).base.borrow()) + (*x.borrow())) + (0 as i32)); |
| 122 | + } |
| 123 | + fn count_i32__int_long_const(&self, x: i32) -> i32 { |
| 124 | + let x: Value<i32> = Rc::new(RefCell::new(x)); |
| 125 | + return (((*(*(*self).upgrade().deref()).base.borrow()) + (*x.borrow())) + (2 as i32)); |
| 126 | + } |
| 127 | +} |
0 commit comments