/**************************************************************************/ /* gdscript_analyzer.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "gdscript_analyzer.h" #include "gdscript.h" #include "gdscript_utility_callable.h" #include "gdscript_utility_functions.h" #include "core/config/engine.h" #include "core/config/project_settings.h" #include "core/core_constants.h" #include "core/core_string_names.h" #include "core/io/file_access.h" #include "core/io/resource_loader.h" #include "core/object/class_db.h" #include "core/object/script_language.h" #include "core/templates/hash_map.h" #include "scene/resources/packed_scene.h" #if defined(TOOLS_ENABLED) && !defined(DISABLE_DEPRECATED) #define SUGGEST_GODOT4_RENAMES #include "editor/renames_map_3_to_4.h" #endif #define UNNAMED_ENUM "" #define ENUM_SEPARATOR "." static MethodInfo info_from_utility_func(const StringName &p_function) { ERR_FAIL_COND_V(!Variant::has_utility_function(p_function), MethodInfo()); MethodInfo info(p_function); if (Variant::has_utility_function_return_value(p_function)) { info.return_val.type = Variant::get_utility_function_return_type(p_function); if (info.return_val.type == Variant::NIL) { info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; } } if (Variant::is_utility_function_vararg(p_function)) { info.flags |= METHOD_FLAG_VARARG; } else { for (int i = 0; i < Variant::get_utility_function_argument_count(p_function); i++) { PropertyInfo pi; #ifdef DEBUG_METHODS_ENABLED pi.name = Variant::get_utility_function_argument_name(p_function, i); #else pi.name = "arg" + itos(i + 1); #endif pi.type = Variant::get_utility_function_argument_type(p_function, i); info.arguments.push_back(pi); } } return info; } static GDScriptParser::DataType make_callable_type(const MethodInfo &p_info) { GDScriptParser::DataType type; type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; type.kind = GDScriptParser::DataType::BUILTIN; type.builtin_type = Variant::CALLABLE; type.is_constant = true; type.method_info = p_info; return type; } static GDScriptParser::DataType make_signal_type(const MethodInfo &p_info) { GDScriptParser::DataType type; type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; type.kind = GDScriptParser::DataType::BUILTIN; type.builtin_type = Variant::SIGNAL; type.is_constant = true; type.method_info = p_info; return type; } static GDScriptParser::DataType make_native_meta_type(const StringName &p_class_name) { GDScriptParser::DataType type; type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; type.kind = GDScriptParser::DataType::NATIVE; type.builtin_type = Variant::OBJECT; type.native_type = p_class_name; type.is_constant = true; type.is_meta_type = true; return type; } static GDScriptParser::DataType make_script_meta_type(const Ref