|
| 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 a: Value<i32>, |
| 12 | + pub b: Value<i32>, |
| 13 | +} |
| 14 | +impl Clone for S { |
| 15 | + fn clone(&self) -> Self { |
| 16 | + let __this: Value<S> = Rc::new(RefCell::new(Self { |
| 17 | + a: Rc::new(RefCell::new((*self.a.borrow()))), |
| 18 | + b: Rc::new(RefCell::new((*self.b.borrow()))), |
| 19 | + })); |
| 20 | + let this: Ptr<S> = __this.as_pointer(); |
| 21 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 22 | + } |
| 23 | +} |
| 24 | +impl ByteRepr for S { |
| 25 | + fn byte_size() -> usize { |
| 26 | + 8 |
| 27 | + } |
| 28 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 29 | + (*self.a.borrow()).to_bytes(&mut buf[0..4]); |
| 30 | + (*self.b.borrow()).to_bytes(&mut buf[4..8]); |
| 31 | + } |
| 32 | + fn from_bytes(buf: &[u8]) -> Self { |
| 33 | + Self { |
| 34 | + a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 35 | + b: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))), |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | +pub fn main() { |
| 40 | + __cpp2rust_init_globals(); |
| 41 | + std::process::exit(main_0()); |
| 42 | +} |
| 43 | +fn main_0() -> i32 { |
| 44 | + let s1: Value<S> = Rc::new(RefCell::new(S { |
| 45 | + a: Rc::new(RefCell::new(1)), |
| 46 | + b: Rc::new(RefCell::new(2)), |
| 47 | + })); |
| 48 | + let s2: Value<S> = Rc::new(RefCell::new(S { |
| 49 | + a: Rc::new(RefCell::new(1)), |
| 50 | + b: Rc::new(RefCell::new(2)), |
| 51 | + })); |
| 52 | + let s3: Value<S> = Rc::new(RefCell::new(S { |
| 53 | + a: Rc::new(RefCell::new(1)), |
| 54 | + b: Rc::new(RefCell::new(3)), |
| 55 | + })); |
| 56 | + assert!( |
| 57 | + ({ |
| 58 | + let _x: Ptr<S> = s1.as_pointer(); |
| 59 | + operator_eq_0(_x, s2.as_pointer()) |
| 60 | + }) |
| 61 | + ); |
| 62 | + assert!( |
| 63 | + ({ |
| 64 | + let _x: Ptr<S> = s1.as_pointer(); |
| 65 | + operator_ne_1(_x, s3.as_pointer()) |
| 66 | + }) |
| 67 | + ); |
| 68 | + assert!( |
| 69 | + !({ |
| 70 | + let _x: Ptr<S> = s1.as_pointer(); |
| 71 | + operator_eq_0(_x, s3.as_pointer()) |
| 72 | + }) |
| 73 | + ); |
| 74 | + assert!( |
| 75 | + ({ |
| 76 | + let _x: Ptr<S> = s1.as_pointer(); |
| 77 | + operator_lt_2(_x, s3.as_pointer()) |
| 78 | + }) |
| 79 | + ); |
| 80 | + assert!( |
| 81 | + !({ |
| 82 | + let _x: Ptr<S> = s3.as_pointer(); |
| 83 | + operator_lt_2(_x, s1.as_pointer()) |
| 84 | + }) |
| 85 | + ); |
| 86 | + assert!((({ compare_3(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); |
| 87 | + assert!((({ compare_3(s3.as_pointer(), s1.as_pointer(),) }) == 1)); |
| 88 | + assert!((({ compare_3(s1.as_pointer(), s2.as_pointer(),) }) == 0)); |
| 89 | + return 0; |
| 90 | +} |
| 91 | +pub fn operator_eq_0(x: Ptr<S>, y: Ptr<S>) -> bool { |
| 92 | + return ({ |
| 93 | + let _lhs = (*(*x.upgrade().deref()).a.borrow()); |
| 94 | + _lhs == (*(*y.upgrade().deref()).a.borrow()) |
| 95 | + }) && ({ |
| 96 | + let _lhs = (*(*x.upgrade().deref()).b.borrow()); |
| 97 | + _lhs == (*(*y.upgrade().deref()).b.borrow()) |
| 98 | + }); |
| 99 | +} |
| 100 | +pub fn operator_ne_1(x: Ptr<S>, y: Ptr<S>) -> bool { |
| 101 | + return !({ |
| 102 | + let _x: Ptr<S> = (x).clone(); |
| 103 | + let _y: Ptr<S> = (y).clone(); |
| 104 | + operator_eq_0(_x, _y) |
| 105 | + }); |
| 106 | +} |
| 107 | +pub fn operator_lt_2(x: Ptr<S>, y: Ptr<S>) -> bool { |
| 108 | + return ({ |
| 109 | + let _lhs = (*(*x.upgrade().deref()).a.borrow()); |
| 110 | + _lhs < (*(*y.upgrade().deref()).a.borrow()) |
| 111 | + }) || (({ |
| 112 | + let _lhs = (*(*x.upgrade().deref()).a.borrow()); |
| 113 | + _lhs == (*(*y.upgrade().deref()).a.borrow()) |
| 114 | + }) && ({ |
| 115 | + let _lhs = (*(*x.upgrade().deref()).b.borrow()); |
| 116 | + _lhs < (*(*y.upgrade().deref()).b.borrow()) |
| 117 | + })); |
| 118 | +} |
| 119 | +pub fn compare_3(x: Ptr<S>, y: Ptr<S>) -> i32 { |
| 120 | + if ({ |
| 121 | + let _x: Ptr<S> = (x).clone(); |
| 122 | + let _y: Ptr<S> = (y).clone(); |
| 123 | + operator_lt_2(_x, _y) |
| 124 | + }) { |
| 125 | + return -1_i32; |
| 126 | + } |
| 127 | + if ({ |
| 128 | + let _x: Ptr<S> = (y).clone(); |
| 129 | + let _y: Ptr<S> = (x).clone(); |
| 130 | + operator_lt_2(_x, _y) |
| 131 | + }) { |
| 132 | + return 1; |
| 133 | + } |
| 134 | + return 0; |
| 135 | +} |
| 136 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments