Skip to main content

luaur_reduce_cli/methods/
reducer_run_reduce_alt_b.rs

1use crate::enums::test_result::TestResult;
2use crate::records::reducer::Reducer;
3use luaur_ast::records::parser::Parser;
4use luaur_ast::type_aliases::cst_node_map::CstNodeMap;
5use std::process;
6
7impl Reducer {
8    pub fn run_string_string_string_view_string_view(
9        &mut self,
10        script_name: String,
11        command: String,
12        source: &str,
13        search_text: &str,
14    ) {
15        self.script_name = script_name;
16
17        println!("Script: {}", self.script_name);
18
19        self.command = command;
20        self.search_text = search_text.to_string();
21
22        // `name_table` stored a `*mut Allocator` pointing at the local allocator in
23        // `Reducer::new`; returning the Reducer by value relocated `self.allocator`,
24        // leaving that pointer dangling. Re-point it at the current allocator before
25        // parsing (the same pattern the test Fixture uses) — otherwise interning
26        // identifiers dereferenced freed stack memory and segfaulted.
27        self.name_table.rebind_allocator(&mut self.allocator);
28
29        self.parse_result = Parser::parse(
30            source,
31            source.len(),
32            &mut self.name_table,
33            &mut self.allocator,
34            self.parse_options.clone(),
35        );
36        if !self.parse_result.errors.is_empty() {
37            println!("Parse errors");
38            process::exit(1);
39        }
40
41        self.root = self.parse_result.root;
42        self.cst_node_map = core::mem::replace(
43            &mut self.parse_result.cst_node_map,
44            CstNodeMap::new(core::ptr::null_mut()),
45        );
46
47        let initial_result = self.run();
48        if initial_result == TestResult::NoBug {
49            println!("Could not find failure string in the unmodified script!  Check your commandline arguments");
50            process::exit(2);
51        }
52
53        self.walk(self.root);
54
55        self.write_temp_script(true);
56
57        println!("Done!  Check {}", self.script_name);
58    }
59}