luaur_analysis/functions/
match_is_instance_guard.rs1use crate::records::data_flow_graph::DataFlowGraph;
2use crate::records::refinement_key::RefinementKey;
3use core::ffi::CStr;
4use luaur_ast::records::ast_expr_call::AstExprCall;
5use luaur_ast::records::ast_expr_global::AstExprGlobal;
6use luaur_ast::records::ast_expr_index_name::AstExprIndexName;
7use luaur_ast::rtti::ast_node_as;
8
9pub fn match_is_instance_guard(call: &AstExprCall, dfg: &DataFlowGraph) -> *const RefinementKey {
10 unsafe {
11 let index = ast_node_as::<AstExprIndexName>(call.func as *mut _);
12 if index.is_null() || (*index).op != '.' as i8 {
13 return core::ptr::null();
14 }
15
16 if (*index).index.value.is_null()
17 || CStr::from_ptr((*index).index.value).to_bytes() != b"isinstance"
18 {
19 return core::ptr::null();
20 }
21
22 if ast_node_as::<AstExprGlobal>((*index).expr as *mut _).is_null() {
23 return core::ptr::null();
24 }
25
26 if call.args.size < 1 {
27 return core::ptr::null();
28 }
29
30 dfg.get_refinement_key(*call.args.data)
31 }
32}