Skip to main content

luaur_analysis/methods/
lint_table_operations_visit_linter_alt_b.rs

1//! C++ `LintTableOperations::visit(AstExprCall*)` (`Analysis/src/Linter.cpp:2618`).
2
3use crate::records::lint_table_operations::LintTableOperations;
4use luaur_ast::records::ast_expr::AstExpr;
5use luaur_ast::records::ast_expr_call::AstExprCall;
6use luaur_ast::records::ast_expr_global::AstExprGlobal;
7use luaur_ast::records::ast_expr_index_name::AstExprIndexName;
8use luaur_ast::records::ast_node::AstNode;
9
10impl LintTableOperations {
11    pub fn visit_ast_expr_call(&mut self, node: *mut AstExprCall) -> bool {
12        unsafe {
13            let func_expr = (*node).func;
14            let func_global =
15                luaur_ast::rtti::ast_node_as::<AstExprGlobal>(func_expr as *mut AstNode);
16
17            if !func_global.is_null() {
18                if (*func_global).name.operator_eq_c_char(c"ipairs".as_ptr())
19                    && (*node).args.size == 1
20                {
21                    let arg0 = *(*node).args.data.add(0);
22                    self.check_indexer(node as *mut AstExpr, arg0, "ipairs");
23                }
24            } else {
25                let func_index =
26                    luaur_ast::rtti::ast_node_as::<AstExprIndexName>(func_expr as *mut AstNode);
27                if !func_index.is_null() {
28                    let tablib = luaur_ast::rtti::ast_node_as::<AstExprGlobal>(
29                        (*func_index).expr as *mut AstNode,
30                    );
31                    if !tablib.is_null() && (*tablib).name.operator_eq_c_char(c"table".as_ptr()) {
32                        self.check_table_call(node, func_index);
33                    }
34                }
35            }
36        }
37
38        true
39    }
40}