rbatis_codegen/
ops_shr.rs1use crate::ops::AsProxy;
2use crate::ops::BitShr;
3use rbs::Value;
4
5fn op_shr_value(left: Value, rhs: Value) -> Value {
6 match left {
7 Value::I32(s) => Value::I32(s >> rhs.i32()),
8 Value::I64(s) => Value::I64(s >> rhs.i64()),
9 Value::U32(s) => Value::U32(s >> rhs.u32()),
10 Value::U64(s) => Value::U64(s >> rhs.u64()),
11 Value::Ext(_, e) => op_shr_value(*e, rhs),
12 _ => Value::Null,
13 }
14}
15
16impl BitShr<Value> for Value {
17 type Output = Value;
18 fn op_shr(self, rhs: Value) -> Self::Output {
19 op_shr_value(self, rhs)
20 }
21}
22
23impl BitShr<&Value> for Value {
24 type Output = Value;
25 fn op_shr(self, rhs: &Value) -> Self::Output {
26 op_shr_value(self, rhs.to_owned())
27 }
28}
29
30impl BitShr<&&Value> for Value {
31 type Output = Value;
32 fn op_shr(self, rhs: &&Value) -> Self::Output {
33 op_shr_value(self, (*rhs).to_owned())
34 }
35}
36
37impl BitShr<Value> for &Value {
38 type Output = Value;
39 fn op_shr(self, rhs: Value) -> Self::Output {
40 op_shr_value(self.to_owned(), rhs)
41 }
42}
43
44impl BitShr<&Value> for &Value {
45 type Output = Value;
46 fn op_shr(self, rhs: &Value) -> Self::Output {
47 op_shr_value(self.to_owned(), rhs.to_owned())
48 }
49}
50
51impl BitShr<&&Value> for &Value {
52 type Output = Value;
53 fn op_shr(self, rhs: &&Value) -> Self::Output {
54 op_shr_value(self.to_owned(), (*rhs).to_owned())
55 }
56}
57
58fn op_shr_u64(value: &Value, other: u64) -> u64 {
59 value.u64() >> other
60}
61
62fn op_shr_i64(value: &Value, other: i64) -> i64 {
63 value.i64() >> other
64}
65
66fn op_shr_u64_value(value: &Value, other: u64) -> u64 {
67 other >> value.u64()
68}
69
70fn op_shr_i64_value(value: &Value, other: i64) -> i64 {
71 other >> value.i64()
72}
73
74macro_rules! impl_numeric_shr {
75 ($($shr:ident,$shr_value:ident [$($ty:ty)*]-> $return_ty:ty)*) => {
76 $($(
77 impl BitShr<$ty> for Value {
78 type Output = $return_ty;
79 fn op_shr(self, other: $ty) -> Self::Output {
80 $shr(&self, other as _)
81 }
82 }
83
84 impl BitShr<&$ty> for Value {
85 type Output = $return_ty;
86 fn op_shr(self, other: &$ty) -> Self::Output {
87 $shr(&self, *other as _)
88 }
89 }
90
91 impl<'a> BitShr<$ty> for &'a Value {
92 type Output = $return_ty;
93 fn op_shr(self, other: $ty) -> Self::Output {
94 $shr(self, other as _)
95 }
96 }
97
98 impl<'a> BitShr<&$ty> for &'a Value {
99 type Output = $return_ty;
100 fn op_shr(self, other: &$ty) -> Self::Output {
101 $shr(self, *other as _)
102 }
103 }
104
105 impl BitShr<Value> for $ty {
106 type Output = $return_ty;
107 fn op_shr(self, other: Value) -> Self::Output {
108 $shr_value(&other, self as _)
109 }
110 }
111
112 impl BitShr<&Value> for $ty {
113 type Output = $return_ty;
114 fn op_shr(self, other: &Value) -> Self::Output {
115 $shr_value(other, self as _)
116 }
117 }
118
119 impl BitShr<Value> for &$ty {
120 type Output = $return_ty;
121 fn op_shr(self, other: Value) -> Self::Output {
122 $shr_value(&other, *self as _)
123 }
124 }
125
126 impl BitShr<&Value> for &$ty {
127 type Output = $return_ty;
128 fn op_shr(self, other: &Value) -> Self::Output {
129 $shr_value(other, *self as _)
130 }
131 }
132
133 impl BitShr<&&Value> for $ty {
134 type Output = $return_ty;
135 fn op_shr(self, other: &&Value) -> Self::Output {
136 $shr_value(*other, self as _)
137 }
138 }
139 )*)*
140 }
141}
142
143impl_numeric_shr! {
144 op_shr_u64,op_shr_u64_value[u8 u16 u32 u64] -> u64
145 op_shr_i64,op_shr_i64_value[i8 i16 i32 i64 isize usize] -> i64
146}
147
148macro_rules! self_shr {
149 ([$($ty:ty)*]) => {
150 $(
151impl BitShr<$ty> for $ty{
152 type Output = $ty;
153 fn op_shr(self, rhs: $ty) -> Self::Output {
154 self >> rhs
155 }
156}
157impl BitShr<&$ty> for $ty{
158 type Output = $ty;
159 fn op_shr(self, rhs: &$ty) -> Self::Output {
160 self >> *rhs
161 }
162}
163impl BitShr<$ty> for &$ty{
164 type Output = $ty;
165 fn op_shr(self, rhs: $ty) -> Self::Output {
166 *self >> rhs
167 }
168}
169impl BitShr<&$ty> for &$ty{
170 type Output = $ty;
171 fn op_shr(self, rhs: &$ty) -> Self::Output {
172 *self >> *rhs
173 }
174}
175 )*
176 };
177}
178
179self_shr!([u8 u16 u32 u64]);
180self_shr!([i8 i16 i32 i64 isize usize]);