Skip to main content

luaur_reduce_cli/methods/
reducer_try_promoting_child_statements_reduce.rs

1use crate::enums::test_result::TestResult;
2use crate::records::reducer::Reducer;
3use alloc::vec::Vec;
4use luaur_ast::records::ast_array::AstArray;
5use luaur_ast::records::ast_stat::AstStat;
6use luaur_ast::records::ast_stat_block::AstStatBlock;
7
8impl Reducer {
9    pub fn try_promoting_child_statements_ast_stat_block_usize(
10        &mut self,
11        b: *mut AstStatBlock,
12        index: usize,
13    ) -> bool {
14        unsafe {
15            let body_slice = core::slice::from_raw_parts((*b).body.data, (*b).body.size);
16            let mut temp_stats = Vec::from(body_slice);
17
18            let removed = temp_stats[index];
19            temp_stats.remove(index);
20
21            let nested_stats = self.get_nested_stats(removed);
22            temp_stats.splice(index..index, nested_stats);
23
24            let mut temp_array = AstArray {
25                data: temp_stats.as_mut_ptr(),
26                size: temp_stats.len(),
27            };
28
29            core::mem::swap(&mut (*b).body, &mut temp_array);
30
31            let result = self.run();
32
33            if result == TestResult::BugFound {
34                (*b).body.data = self.reallocate_statements(&temp_stats);
35                (*b).body.size = temp_stats.len();
36                true
37            } else {
38                core::mem::swap(&mut (*b).body, &mut temp_array);
39                false
40            }
41        }
42    }
43}