Skip to main content

luaur_compiler/methods/
compiler_function_visitor_visit_compiler.rs

1use crate::records::function_visitor::FunctionVisitor;
2use luaur_ast::records::ast_expr_function::AstExprFunction;
3use luaur_ast::records::ast_local::AstLocal;
4use luaur_common::macros::luau_assert::LUAU_ASSERT;
5
6pub fn visit_ast_expr_function(this: &mut FunctionVisitor<'_>, node: *mut AstExprFunction) -> bool {
7    unsafe {
8        if node.is_null() {
9            return false;
10        }
11
12        let node_ref = &*node;
13
14        // node->body->visit(this);
15        if !node_ref.body.is_null() {
16            luaur_ast::visit::ast_stat_block_visit(&*node_ref.body, this);
17        }
18
19        // for (AstLocal* arg : node->args)
20        //     hasTypes |= arg->annotation != nullptr;
21        for i in 0..node_ref.args.size {
22            let arg_ptr = *node_ref.args.data.add(i);
23            if !arg_ptr.is_null() {
24                let arg = &*arg_ptr;
25                if !arg.annotation.is_null() {
26                    this.has_types = true;
27                }
28            }
29        }
30
31        // LUAU_ASSERT(functions.end() == std::find(functions.begin(), functions.end(), node));
32        let functions = &*this.functions;
33        let mut found = false;
34        for &f in functions.iter() {
35            if f == node {
36                found = true;
37                break;
38            }
39        }
40        LUAU_ASSERT!(!found);
41
42        // functions.push_back(node);
43        this.functions.push(node);
44
45        // if (!hasNativeFunction && node->hasNativeAttribute())
46        //     hasNativeFunction = true;
47        if !this.has_native_function && node_ref.has_native_attribute() {
48            this.has_native_function = true;
49        }
50    }
51
52    false
53}
54
55impl<'a> FunctionVisitor<'a> {
56    pub fn visit_ast_expr_function(&mut self, node: *mut AstExprFunction) -> bool {
57        visit_ast_expr_function(self, node)
58    }
59}