/**************************************************************************/1/* method_info.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "method_info.h"3132#include "core/variant/array.h"33#include "core/variant/dictionary.h"34#include "core/variant/typed_array.h" // IWYU pragma: keep. `convert_property_list` return type.3536MethodInfo::operator Dictionary() const {37Dictionary d;38d["name"] = name;39d["args"] = convert_property_list(arguments);40Array da;41for (int i = 0; i < default_arguments.size(); i++) {42da.push_back(default_arguments[i]);43}44d["default_args"] = da;45d["flags"] = flags;46d["id"] = id;47Dictionary r = return_val;48d["return"] = r;49return d;50}5152MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {53MethodInfo mi;5455if (p_dict.has("name")) {56mi.name = p_dict["name"];57}58Array args;59if (p_dict.has("args")) {60args = p_dict["args"];61}6263for (const Variant &arg : args) {64Dictionary d = arg;65mi.arguments.push_back(PropertyInfo::from_dict(d));66}67Array defargs;68if (p_dict.has("default_args")) {69defargs = p_dict["default_args"];70}71for (const Variant &defarg : defargs) {72mi.default_arguments.push_back(defarg);73}7475if (p_dict.has("return")) {76mi.return_val = PropertyInfo::from_dict(p_dict["return"]);77}7879if (p_dict.has("flags")) {80mi.flags = p_dict["flags"];81}8283return mi;84}8586uint32_t MethodInfo::get_compatibility_hash() const {87bool has_return = (return_val.type != Variant::NIL) || (return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT);8889uint32_t hash = hash_murmur3_one_32(has_return);90hash = hash_murmur3_one_32(arguments.size(), hash);9192if (has_return) {93hash = hash_murmur3_one_32(return_val.type, hash);94if (return_val.class_name != StringName()) {95hash = hash_murmur3_one_32(return_val.class_name.hash(), hash);96}97}9899for (const PropertyInfo &arg : arguments) {100hash = hash_murmur3_one_32(arg.type, hash);101if (arg.class_name != StringName()) {102hash = hash_murmur3_one_32(arg.class_name.hash(), hash);103}104}105106hash = hash_murmur3_one_32(default_arguments.size(), hash);107for (const Variant &v : default_arguments) {108hash = hash_murmur3_one_32(v.hash(), hash);109}110111hash = hash_murmur3_one_32(flags & METHOD_FLAG_CONST ? 1 : 0, hash);112hash = hash_murmur3_one_32(flags & METHOD_FLAG_VARARG ? 1 : 0, hash);113114return hash_fmix32(hash);115}116117118