| 2297 | } |
| 2298 | |
| 2299 | GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_script, const GDScriptParser::ClassNode *p_class, const GDScriptParser::FunctionNode *p_func, bool p_for_ready, bool p_for_lambda) { |
| 2300 | r_error = OK; |
| 2301 | CodeGen codegen; |
| 2302 | codegen.generator = memnew(GDScriptByteCodeGenerator); |
| 2303 | |
| 2304 | codegen.class_node = p_class; |
| 2305 | codegen.script = p_script; |
| 2306 | codegen.function_node = p_func; |
| 2307 | |
| 2308 | StringName func_name; |
| 2309 | bool is_abstract = false; |
| 2310 | bool is_static = false; |
| 2311 | Variant rpc_config; |
| 2312 | GDScriptDataType return_type; |
| 2313 | return_type.has_type = true; |
| 2314 | return_type.kind = GDScriptDataType::BUILTIN; |
| 2315 | return_type.builtin_type = Variant::NIL; |
| 2316 | |
| 2317 | if (p_func) { |
| 2318 | if (p_func->identifier) { |
| 2319 | func_name = p_func->identifier->name; |
| 2320 | } else { |
| 2321 | func_name = "<anonymous lambda>"; |
| 2322 | } |
| 2323 | is_abstract = p_func->is_abstract; |
| 2324 | is_static = p_func->is_static; |
| 2325 | rpc_config = p_func->rpc_config; |
| 2326 | return_type = _gdtype_from_datatype(p_func->get_datatype(), p_script); |
| 2327 | } else { |
| 2328 | if (p_for_ready) { |
| 2329 | func_name = "@implicit_ready"; |
| 2330 | } else { |
| 2331 | func_name = "@implicit_new"; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | MethodInfo method_info; |
| 2336 | |
| 2337 | codegen.function_name = func_name; |
| 2338 | method_info.name = func_name; |
| 2339 | codegen.is_static = is_static; |
| 2340 | if (is_abstract) { |
| 2341 | method_info.flags |= METHOD_FLAG_VIRTUAL_REQUIRED; |
| 2342 | } |
| 2343 | if (is_static) { |
| 2344 | method_info.flags |= METHOD_FLAG_STATIC; |
| 2345 | } |
| 2346 | codegen.generator->write_start(p_script, func_name, is_static, rpc_config, return_type); |
| 2347 | |
| 2348 | int optional_parameters = 0; |
| 2349 | GDScriptCodeGenerator::Address vararg_addr; |
| 2350 | |
| 2351 | if (p_func) { |
| 2352 | for (int i = 0; i < p_func->parameters.size(); i++) { |
| 2353 | const GDScriptParser::ParameterNode *parameter = p_func->parameters[i]; |
| 2354 | GDScriptDataType par_type = _gdtype_from_datatype(parameter->get_datatype(), p_script); |
| 2355 | uint32_t par_addr = codegen.generator->add_parameter(parameter->identifier->name, parameter->initializer != nullptr, par_type); |
| 2356 | codegen.parameters[parameter->identifier->name] = GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::FUNCTION_PARAMETER, par_addr, par_type); |
nothing calls this directly
no test coverage detected