Skip to main content

luaur_reduce_cli/records/
reducer.rs

1use luaur_ast::records::allocator::Allocator;
2use luaur_ast::records::ast_name_table::AstNameTable;
3use luaur_ast::records::ast_stat_block::AstStatBlock;
4use luaur_ast::records::parse_options::ParseOptions;
5use luaur_ast::records::parse_result::ParseResult;
6use luaur_ast::type_aliases::cst_node_map::CstNodeMap;
7
8/// `Reducer` is a native-only utility for reducing Luau source code while preserving a bug.
9/// It is not portable to wasm32-unknown-unknown.
10#[repr(C)]
11#[derive(Debug)]
12pub struct Reducer {
13    pub(crate) allocator: Allocator,
14    pub(crate) name_table: AstNameTable,
15    pub(crate) parse_options: ParseOptions,
16    pub(crate) parse_result: ParseResult,
17    pub(crate) cst_node_map: CstNodeMap,
18    pub(crate) root: *mut AstStatBlock,
19    pub(crate) script_name: String,
20    pub(crate) command: String,
21    pub(crate) search_text: String,
22    pub(crate) step: i32,
23}
24
25impl Reducer {
26    pub fn new() -> Self {
27        let mut allocator = Allocator::allocator();
28        let name_table = AstNameTable::new(&mut allocator);
29        let mut parse_options = ParseOptions::default();
30        parse_options.capture_comments = true;
31        parse_options.store_cst_data = true;
32
33        Reducer {
34            allocator,
35            name_table,
36            parse_options,
37            parse_result: ParseResult {
38                root: core::ptr::null_mut(),
39                lines: 0,
40                hotcomments: Vec::new(),
41                errors: Vec::new(),
42                comment_locations: Vec::new(),
43                cst_node_map: CstNodeMap::new(core::ptr::null_mut()),
44            },
45            cst_node_map: CstNodeMap::new(core::ptr::null_mut()),
46            root: core::ptr::null_mut(),
47            script_name: String::new(),
48            command: String::new(),
49            search_text: String::new(),
50            step: 0,
51        }
52    }
53}
54
55impl Default for Reducer {
56    fn default() -> Self {
57        Self::new()
58    }
59}