|
| 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(Clone, Copy, PartialEq, Debug, Default)] |
| 10 | +enum widget_enum { |
| 11 | + #[default] |
| 12 | + MODE_IDLE = 0, |
| 13 | + MODE_ACTIVE = 1, |
| 14 | + MODE_DONE = 2, |
| 15 | +} |
| 16 | +impl From<i32> for widget_enum { |
| 17 | + fn from(n: i32) -> widget_enum { |
| 18 | + match n { |
| 19 | + 0 => widget_enum::MODE_IDLE, |
| 20 | + 1 => widget_enum::MODE_ACTIVE, |
| 21 | + 2 => widget_enum::MODE_DONE, |
| 22 | + _ => panic!("invalid widget_enum value: {}", n), |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | +libcc2rs::impl_enum_inc_dec!(widget_enum); |
| 27 | +#[derive(Default)] |
| 28 | +pub struct widget { |
| 29 | + pub id: Value<i32>, |
| 30 | + pub mode: Value<widget_enum>, |
| 31 | +} |
| 32 | +impl ByteRepr for widget {} |
| 33 | +#[derive(Default)] |
| 34 | +pub struct point_struct { |
| 35 | + pub x: Value<i32>, |
| 36 | + pub y: Value<i32>, |
| 37 | +} |
| 38 | +impl ByteRepr for point_struct { |
| 39 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 40 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 41 | + (*self.y.borrow()).to_bytes(&mut buf[4..8]); |
| 42 | + } |
| 43 | + fn from_bytes(buf: &[u8]) -> Self { |
| 44 | + Self { |
| 45 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 46 | + y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))), |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +#[derive(Clone)] |
| 51 | +pub struct point { |
| 52 | + __store: libcc2rs::UnionStorage, |
| 53 | +} |
| 54 | +impl point { |
| 55 | + pub fn whole(&self) -> Ptr<i32> { |
| 56 | + self.__store.reinterpret(0) |
| 57 | + } |
| 58 | + pub fn half(&self) -> Ptr<i16> { |
| 59 | + self.__store.reinterpret(0) |
| 60 | + } |
| 61 | +} |
| 62 | +impl Default for point { |
| 63 | + fn default() -> Self { |
| 64 | + point { |
| 65 | + __store: libcc2rs::UnionStorage::new(4), |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +impl ByteRepr for point {} |
| 70 | +#[derive(Clone)] |
| 71 | +pub struct slot_union { |
| 72 | + __store: libcc2rs::UnionStorage, |
| 73 | +} |
| 74 | +impl slot_union { |
| 75 | + pub fn i(&self) -> Ptr<i32> { |
| 76 | + self.__store.reinterpret(0) |
| 77 | + } |
| 78 | + pub fn u(&self) -> Ptr<u32> { |
| 79 | + self.__store.reinterpret(0) |
| 80 | + } |
| 81 | +} |
| 82 | +impl Default for slot_union { |
| 83 | + fn default() -> Self { |
| 84 | + slot_union { |
| 85 | + __store: libcc2rs::UnionStorage::new(4), |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | +impl ByteRepr for slot_union {} |
| 90 | +#[derive(Clone, Copy, PartialEq, Debug, Default)] |
| 91 | +enum slot { |
| 92 | + #[default] |
| 93 | + SLOT_A = 0, |
| 94 | + SLOT_B = 1, |
| 95 | +} |
| 96 | +impl From<i32> for slot { |
| 97 | + fn from(n: i32) -> slot { |
| 98 | + match n { |
| 99 | + 0 => slot::SLOT_A, |
| 100 | + 1 => slot::SLOT_B, |
| 101 | + _ => panic!("invalid slot value: {}", n), |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | +libcc2rs::impl_enum_inc_dec!(slot); |
| 106 | +#[derive(Default)] |
| 107 | +pub struct Inner { |
| 108 | + pub tag_field: Value<i32>, |
| 109 | +} |
| 110 | +impl ByteRepr for Inner { |
| 111 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 112 | + (*self.tag_field.borrow()).to_bytes(&mut buf[0..4]); |
| 113 | + } |
| 114 | + fn from_bytes(buf: &[u8]) -> Self { |
| 115 | + Self { |
| 116 | + tag_field: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 117 | + } |
| 118 | + } |
| 119 | +} |
| 120 | +#[derive(Default)] |
| 121 | +pub struct Outer { |
| 122 | + pub field: Value<Inner>, |
| 123 | +} |
| 124 | +impl ByteRepr for Outer {} |
| 125 | +#[derive(Default)] |
| 126 | +pub struct Inner_struct { |
| 127 | + pub typedef_field: Value<i32>, |
| 128 | +} |
| 129 | +impl ByteRepr for Inner_struct { |
| 130 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 131 | + (*self.typedef_field.borrow()).to_bytes(&mut buf[0..4]); |
| 132 | + } |
| 133 | + fn from_bytes(buf: &[u8]) -> Self { |
| 134 | + Self { |
| 135 | + typedef_field: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 136 | + } |
| 137 | + } |
| 138 | +} |
| 139 | +pub fn is_active_0(w: Ptr<widget>) -> i32 { |
| 140 | + let w: Value<Ptr<widget>> = Rc::new(RefCell::new(w)); |
| 141 | + return (({ |
| 142 | + let _lhs = ((*(*(*w.borrow()).upgrade().deref()).mode.borrow()) as u32).clone(); |
| 143 | + _lhs == ((widget_enum::MODE_ACTIVE as i32) as u32) |
| 144 | + }) as i32); |
| 145 | +} |
| 146 | +pub fn main() { |
| 147 | + std::process::exit(main_0()); |
| 148 | +} |
| 149 | +fn main_0() -> i32 { |
| 150 | + let w: Value<widget> = <Value<widget>>::default(); |
| 151 | + (*(*w.borrow()).id.borrow_mut()) = 7; |
| 152 | + (*(*w.borrow()).mode.borrow_mut()) = widget_enum::MODE_ACTIVE; |
| 153 | + assert!( |
| 154 | + (({ |
| 155 | + let _w: Ptr<widget> = (w.as_pointer()); |
| 156 | + is_active_0(_w) |
| 157 | + }) != 0) |
| 158 | + ); |
| 159 | + (*(*w.borrow()).mode.borrow_mut()) = widget_enum::MODE_DONE; |
| 160 | + assert!( |
| 161 | + (((((*(*w.borrow()).mode.borrow()) as u32) == ((widget_enum::MODE_DONE as i32) as u32)) |
| 162 | + as i32) |
| 163 | + != 0) |
| 164 | + ); |
| 165 | + let p: Value<point_struct> = <Value<point_struct>>::default(); |
| 166 | + (*(*p.borrow()).x.borrow_mut()) = 3; |
| 167 | + (*(*p.borrow()).y.borrow_mut()) = 4; |
| 168 | + assert!((((((*(*p.borrow()).x.borrow()) + (*(*p.borrow()).y.borrow())) == 7) as i32) != 0)); |
| 169 | + let up: Value<point> = <Value<point>>::default(); |
| 170 | + (*up.borrow_mut()).whole().write(5); |
| 171 | + assert!((((((*up.borrow()).whole().read()) == 5) as i32) != 0)); |
| 172 | + let b: Value<slot_union> = <Value<slot_union>>::default(); |
| 173 | + (*b.borrow_mut()).i().write(9); |
| 174 | + assert!((((((*b.borrow()).i().read()) == 9) as i32) != 0)); |
| 175 | + let e: Value<slot> = Rc::new(RefCell::new(slot::SLOT_B)); |
| 176 | + assert!((((((*e.borrow()) as u32) == ((slot::SLOT_B as i32) as u32)) as i32) != 0)); |
| 177 | + let inner_tag: Value<Inner> = <Value<Inner>>::default(); |
| 178 | + (*(*inner_tag.borrow()).tag_field.borrow_mut()) = 11; |
| 179 | + assert!(((((*(*inner_tag.borrow()).tag_field.borrow()) == 11) as i32) != 0)); |
| 180 | + let inner_typedef: Value<Inner_struct> = <Value<Inner_struct>>::default(); |
| 181 | + (*(*inner_typedef.borrow()).typedef_field.borrow_mut()) = 22; |
| 182 | + assert!(((((*(*inner_typedef.borrow()).typedef_field.borrow()) == 22) as i32) != 0)); |
| 183 | + let o: Value<Outer> = <Value<Outer>>::default(); |
| 184 | + (*(*(*o.borrow()).field.borrow()).tag_field.borrow_mut()) = 33; |
| 185 | + assert!(((((*(*(*o.borrow()).field.borrow()).tag_field.borrow()) == 33) as i32) != 0)); |
| 186 | + return (*(*w.borrow()).id.borrow()); |
| 187 | +} |
0 commit comments