Skip to content

Commit

Permalink
Created separate files for PropertyInfo and MethodInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlupugla committed Sep 8, 2024
1 parent 5675c76 commit da81925
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 338 deletions.
83 changes: 83 additions & 0 deletions core/object/method_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**************************************************************************/
/* method_info.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 "method_info.h"

#include "core/variant/typed_array.h"

MethodInfo::operator Dictionary() const {
Dictionary d;
d["name"] = name;
d["args"] = convert_property_list(&arguments);
Array da;
for (int i = 0; i < default_arguments.size(); i++) {
da.push_back(default_arguments[i]);
}
d["default_args"] = da;
d["flags"] = flags;
d["id"] = id;
Dictionary r = return_val;
d["return"] = r;
return d;
}

MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
MethodInfo mi;

if (p_dict.has("name")) {
mi.name = p_dict["name"];
}
Array args;
if (p_dict.has("args")) {
args = p_dict["args"];
}

for (const Variant &arg : args) {
Dictionary d = arg;
mi.arguments.push_back(PropertyInfo::from_dict(d));
}
Array defargs;
if (p_dict.has("default_args")) {
defargs = p_dict["default_args"];
}
for (const Variant &defarg : defargs) {
mi.default_arguments.push_back(defarg);
}

if (p_dict.has("return")) {
mi.return_val = PropertyInfo::from_dict(p_dict["return"]);
}

if (p_dict.has("flags")) {
mi.flags = p_dict["flags"];
}

return mi;
}
133 changes: 133 additions & 0 deletions core/object/method_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**************************************************************************/
/* method_info.h */
/**************************************************************************/
/* 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. */
/**************************************************************************/

#ifndef METHOD_INFO_H
#define METHOD_INFO_H

#include "core/object/property_info.h"
#include "core/variant/variant.h"

enum MethodFlags {
METHOD_FLAG_NORMAL = 1,
METHOD_FLAG_EDITOR = 2,
METHOD_FLAG_CONST = 4,
METHOD_FLAG_VIRTUAL = 8,
METHOD_FLAG_VARARG = 16,
METHOD_FLAG_STATIC = 32,
METHOD_FLAG_OBJECT_CORE = 64,
METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL,
};

struct MethodInfo {
String name;
PropertyInfo return_val;
uint32_t flags = METHOD_FLAGS_DEFAULT;
int id = 0;
List<PropertyInfo> arguments;
Vector<Variant> default_arguments;
int return_val_metadata = 0;
Vector<int> arguments_metadata;

int get_argument_meta(int p_arg) const {
ERR_FAIL_COND_V(p_arg < -1 || p_arg > arguments.size(), 0);
if (p_arg == -1) {
return return_val_metadata;
}
return arguments_metadata.size() > p_arg ? arguments_metadata[p_arg] : 0;
}

inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id && name == p_method.name; }
inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); }

operator Dictionary() const;

static MethodInfo from_dict(const Dictionary &p_dict);

MethodInfo() {}

explicit MethodInfo(const GDExtensionMethodInfo &pinfo) :
name(*reinterpret_cast<StringName *>(pinfo.name)),
return_val(PropertyInfo(pinfo.return_value)),
flags(pinfo.flags),
id(pinfo.id) {
for (uint32_t j = 0; j < pinfo.argument_count; j++) {
arguments.push_back(PropertyInfo(pinfo.arguments[j]));
}
const Variant *def_values = (const Variant *)pinfo.default_arguments;
for (uint32_t j = 0; j < pinfo.default_argument_count; j++) {
default_arguments.push_back(def_values[j]);
}
}

void _push_params(const PropertyInfo &p_param) {
arguments.push_back(p_param);
}

template <typename... VarArgs>
void _push_params(const PropertyInfo &p_param, VarArgs... p_params) {
arguments.push_back(p_param);
_push_params(p_params...);
}

MethodInfo(const String &p_name) { name = p_name; }

template <typename... VarArgs>
MethodInfo(const String &p_name, VarArgs... p_params) {
name = p_name;
_push_params(p_params...);
}

MethodInfo(Variant::Type ret) { return_val.type = ret; }
MethodInfo(Variant::Type ret, const String &p_name) {
return_val.type = ret;
name = p_name;
}

template <typename... VarArgs>
MethodInfo(Variant::Type ret, const String &p_name, VarArgs... p_params) {
name = p_name;
return_val.type = ret;
_push_params(p_params...);
}

MethodInfo(const PropertyInfo &p_ret, const String &p_name) {
return_val = p_ret;
name = p_name;
}

template <typename... VarArgs>
MethodInfo(const PropertyInfo &p_ret, const String &p_name, VarArgs... p_params) {
return_val = p_ret;
name = p_name;
_push_params(p_params...);
}
};

#endif // METHOD_INFO_H
100 changes: 0 additions & 100 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,106 +64,6 @@ struct _ObjectDebugLock {

#endif

PropertyInfo::operator Dictionary() const {
Dictionary d;
d["name"] = name;
d["class_name"] = class_name;
d["type"] = type;
d["hint"] = hint;
d["hint_string"] = hint_string;
d["usage"] = usage;
return d;
}

PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) {
PropertyInfo pi;

if (p_dict.has("type")) {
pi.type = Variant::Type(int(p_dict["type"]));
}

if (p_dict.has("name")) {
pi.name = p_dict["name"];
}

if (p_dict.has("class_name")) {
pi.class_name = p_dict["class_name"];
}

if (p_dict.has("hint")) {
pi.hint = PropertyHint(int(p_dict["hint"]));
}

if (p_dict.has("hint_string")) {
pi.hint_string = p_dict["hint_string"];
}

if (p_dict.has("usage")) {
pi.usage = p_dict["usage"];
}

return pi;
}

TypedArray<Dictionary> convert_property_list(const List<PropertyInfo> *p_list) {
TypedArray<Dictionary> va;
for (const List<PropertyInfo>::Element *E = p_list->front(); E; E = E->next()) {
va.push_back(Dictionary(E->get()));
}

return va;
}

MethodInfo::operator Dictionary() const {
Dictionary d;
d["name"] = name;
d["args"] = convert_property_list(&arguments);
Array da;
for (int i = 0; i < default_arguments.size(); i++) {
da.push_back(default_arguments[i]);
}
d["default_args"] = da;
d["flags"] = flags;
d["id"] = id;
Dictionary r = return_val;
d["return"] = r;
return d;
}

MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
MethodInfo mi;

if (p_dict.has("name")) {
mi.name = p_dict["name"];
}
Array args;
if (p_dict.has("args")) {
args = p_dict["args"];
}

for (const Variant &arg : args) {
Dictionary d = arg;
mi.arguments.push_back(PropertyInfo::from_dict(d));
}
Array defargs;
if (p_dict.has("default_args")) {
defargs = p_dict["default_args"];
}
for (const Variant &defarg : defargs) {
mi.default_arguments.push_back(defarg);
}

if (p_dict.has("return")) {
mi.return_val = PropertyInfo::from_dict(p_dict["return"]);
}

if (p_dict.has("flags")) {
mi.flags = p_dict["flags"];
}

return mi;
}

Object::Connection::operator Variant() const {
Dictionary d;
d["signal"] = signal;
Expand Down
Loading

0 comments on commit da81925

Please sign in to comment.