luaur_compiler/methods/
compiler_is_condition_fast.rs1use crate::enums::type_constant_folding::Type;
2use crate::records::compiler::Compiler;
3use crate::records::constant::Constant;
4use luaur_ast::records::ast_expr::AstExpr;
5use luaur_ast::records::ast_expr_binary::AstExprBinary;
6use luaur_ast::records::ast_expr_binary::AstExprBinary_Op;
7use luaur_ast::records::ast_expr_group::AstExprGroup;
8use luaur_ast::records::ast_node::AstNode;
9use luaur_common::records::dense_hash_map::DenseHashMap;
10
11impl Compiler {
12 pub fn is_condition_fast(&mut self, node: *mut AstExpr) -> bool {
13 unsafe {
14 if node.is_null() {
15 return false;
16 }
17
18 let cv = self.constants.find(&node);
19
20 if let Some(constant) = cv {
21 if (*constant).r#type != Type::Type_Unknown {
22 return true;
23 }
24 }
25
26 let binary = luaur_ast::rtti::ast_node_as::<AstExprBinary>(node as *mut AstNode);
27 if !binary.is_null() {
28 match (*binary).op {
29 AstExprBinary_Op::And
30 | AstExprBinary_Op::Or
31 | AstExprBinary_Op::CompareNe
32 | AstExprBinary_Op::CompareEq
33 | AstExprBinary_Op::CompareLt
34 | AstExprBinary_Op::CompareLe
35 | AstExprBinary_Op::CompareGt
36 | AstExprBinary_Op::CompareGe => return true,
37 _ => return false,
38 }
39 }
40
41 let group = luaur_ast::rtti::ast_node_as::<AstExprGroup>(node as *mut AstNode);
42 if !group.is_null() {
43 return self.is_condition_fast((*group).expr);
44 }
45
46 false
47 }
48 }
49}