MCPcopy Create free account
hub / github.com/caverav/flutterdec / simplify_bin_expr

Function simplify_bin_expr

crates/flutterdec-decompiler/src/helpers/expr.rs:112–182  ·  view source on GitHub ↗
(lhs: String, op: &str, rhs: String)

Source from the content-addressed store, hash-verified

110 }
111 }
112 None
113}
114
115pub(super) fn simplify_bin_expr(lhs: String, op: &str, rhs: String) -> String {
116 let lt = lhs.trim();
117 let rt = rhs.trim();
118 let l_int = parse_expr_int(lt);
119 let r_int = parse_expr_int(rt);
120
121 match op {
122 "+" => {
123 if lt == "null" {
124 if let Some(v) = r_int {
125 return fmt_int(v);
126 }
127 }
128 if rt == "null" {
129 if let Some(v) = l_int {
130 return fmt_int(v);
131 }
132 }
133 if l_int == Some(0) {
134 return rt.to_string();
135 }
136 if r_int == Some(0) {
137 return lt.to_string();
138 }
139 // ARM64 arithmetic wraps, so folding wraps too. Plain `+` panics in
140 // debug on overflow, which `movk` made reachable by binding full
141 // 64-bit constants, and a checked fold that bailed would silently
142 // drop a constant that is genuinely known.
143 if let (Some(a), Some(b)) = (l_int, r_int) {
144 return fmt_int(a.wrapping_add(b));
145 }
146 if let (Some((stack_base, stack_off)), Some(delta)) =
147 (parse_stack_base_offset(lt), r_int)
148 {
149 return format!("{stack_base}[{}]", fmt_int(stack_off.wrapping_add(delta)));
150 }
151 if let (Some((base, off)), Some(delta)) = (parse_base_offset_expr(lt), r_int) {
152 let sum = off.wrapping_add(delta);
153 if sum == 0 {
154 return base;
155 }
156 if sum > 0 {
157 return format!("({base} + {})", fmt_int(sum));
158 }
159 return format!("({base} - {})", fmt_int(sum.wrapping_neg()));
160 }
161 }
162 "-" => {
163 if r_int == Some(0) {
164 return lt.to_string();
165 }
166 if let (Some(a), Some(b)) = (l_int, r_int) {
167 return fmt_int(a.wrapping_sub(b));
168 }
169 if let (Some((stack_base, stack_off)), Some(delta)) =

Callers 1

apply_other_liftMethod · 0.85

Calls 4

parse_expr_intFunction · 0.85
fmt_intFunction · 0.85
parse_stack_base_offsetFunction · 0.85
parse_base_offset_exprFunction · 0.85

Tested by

no test coverage detected