Skip to main content

luaur_compiler/methods/
compiler_get_expr_local.rs

1use crate::functions::unwrap_expr_of_type::unwrap_expr_of_type;
2use crate::records::compiler::Compiler;
3use luaur_ast::records::ast_expr::AstExpr;
4use luaur_ast::records::ast_expr_group::AstExprGroup;
5use luaur_ast::records::ast_expr_local::AstExprLocal;
6use luaur_ast::records::ast_expr_type_assertion::AstExprTypeAssertion;
7use luaur_ast::records::ast_node::AstNode;
8
9impl Compiler {
10    pub fn get_expr_local(&mut self, node: *mut AstExpr) -> *mut AstExprLocal {
11        unsafe {
12            if luaur_common::FFlag::LuauCompileInlineTableFunctions.get() {
13                return unwrap_expr_of_type::<AstExprLocal>(node);
14            }
15
16            let expr = luaur_ast::rtti::ast_node_as::<AstExprLocal>(node as *mut AstNode);
17            if !expr.is_null() {
18                return expr;
19            }
20
21            let group = luaur_ast::rtti::ast_node_as::<AstExprGroup>(node as *mut AstNode);
22            if !group.is_null() {
23                return self.get_expr_local((*group).expr);
24            }
25
26            let assertion =
27                luaur_ast::rtti::ast_node_as::<AstExprTypeAssertion>(node as *mut AstNode);
28            if !assertion.is_null() {
29                return self.get_expr_local((*assertion).expr);
30            }
31
32            core::ptr::null_mut()
33        }
34    }
35}