Skip to main content

luaur_analysis/functions/
has_break.rs

1use luaur_ast::records::ast_stat::AstStat;
2use luaur_ast::records::ast_stat_block::AstStatBlock;
3use luaur_ast::records::ast_stat_break::AstStatBreak;
4use luaur_ast::records::ast_stat_if::AstStatIf;
5use luaur_ast::rtti::ast_node_as;
6use luaur_ast::rtti::ast_node_is;
7
8pub fn has_break(node: *mut AstStat) -> bool {
9    if node.is_null() {
10        return false;
11    }
12
13    unsafe {
14        if !ast_node_as::<AstStatBlock>(node as *mut luaur_ast::records::ast_node::AstNode)
15            .is_null()
16        {
17            let stat =
18                ast_node_as::<AstStatBlock>(node as *mut luaur_ast::records::ast_node::AstNode);
19            if stat.is_null() {
20                return false;
21            }
22
23            for i in 0..(*stat).body.size {
24                if has_break(*(*stat).body.data.add(i)) {
25                    return true;
26                }
27            }
28            return false;
29        }
30
31        if ast_node_is::<AstStatBreak>(unsafe {
32            &*(node as *const luaur_ast::records::ast_node::AstNode)
33        }) {
34            return true;
35        }
36
37        if !ast_node_as::<AstStatIf>(node as *mut luaur_ast::records::ast_node::AstNode).is_null() {
38            let stat = ast_node_as::<AstStatIf>(node as *mut luaur_ast::records::ast_node::AstNode);
39            if stat.is_null() {
40                return false;
41            }
42
43            if has_break((*stat).thenbody as *mut AstStat) {
44                return true;
45            }
46
47            if !(*stat).elsebody.is_null() && has_break((*stat).elsebody as *mut AstStat) {
48                return true;
49            }
50
51            return false;
52        }
53
54        false
55    }
56}