Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable method type information on release builds #53545

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
#define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);

#ifdef DEBUG_METHODS_ENABLED

MethodDefinition D_METHOD(const char *p_name) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
Expand Down Expand Up @@ -226,8 +224,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
return md;
}

#endif

ClassDB::APIType ClassDB::current_api = API_CORE;

void ClassDB::set_current_api(APIType p_api) {
Expand Down Expand Up @@ -589,7 +585,6 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit
}
}

#ifdef DEBUG_METHODS_ENABLED
static MethodInfo info_from_bind(MethodBind *p_method) {
MethodInfo minfo;
minfo.name = p_method->get_name();
Expand All @@ -610,7 +605,6 @@ static MethodInfo info_from_bind(MethodBind *p_method) {

return minfo;
}
#endif

void ClassDB::get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
Expand Down Expand Up @@ -650,9 +644,8 @@ void ClassDB::get_method_list(const StringName &p_class, List<MethodInfo> *p_met

while ((K = type->method_map.next(K))) {
MethodBind *m = type->method_map[*K];
MethodInfo mi;
mi.name = m->get_name();
p_methods->push_back(mi);
MethodInfo minfo = info_from_bind(m);
p_methods->push_back(minfo);
}

#endif
Expand Down Expand Up @@ -698,9 +691,8 @@ bool ClassDB::get_method_info(const StringName &p_class, const StringName &p_met
if (type->method_map.has(p_method)) {
if (r_info) {
MethodBind *m = type->method_map[p_method];
MethodInfo mi;
mi.name = m->get_name();
*r_info = mi;
MethodInfo minfo = info_from_bind(m);
*r_info = minfo;
}
return true;
}
Expand Down Expand Up @@ -1411,13 +1403,8 @@ void ClassDB::bind_method_custom(const StringName &p_class, MethodBind *p_method
type->method_map[p_method->get_name()] = p_method;
}

#ifdef DEBUG_METHODS_ENABLED
MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
StringName mdname = method_name.name;
#else
MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount) {
StringName mdname = StaticCString::create(method_name);
#endif

OBJTYPE_WLOCK;
ERR_FAIL_COND_V(!p_bind, nullptr);
Expand Down
26 changes: 0 additions & 26 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@

#define DEFVAL(m_defval) (m_defval)

#ifdef DEBUG_METHODS_ENABLED

struct MethodDefinition {
StringName name;
Vector<StringName> args;
Expand All @@ -72,26 +70,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13);

#else

//#define NO_VARIADIC_MACROS

#ifdef NO_VARIADIC_MACROS

static _FORCE_INLINE_ const char *D_METHOD(const char *m_name, ...) {
return m_name;
}

#else

// When DEBUG_METHODS_ENABLED is set this will let the engine know
// the argument names for easier debugging.
#define D_METHOD(m_c, ...) m_c

#endif

#endif

class ClassDB {
public:
enum APIType {
Expand Down Expand Up @@ -156,11 +134,7 @@ class ClassDB {
static HashMap<StringName, StringName> resource_base_extensions;
static HashMap<StringName, StringName> compat_classes;

#ifdef DEBUG_METHODS_ENABLED
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
#else
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount);
#endif

static APIType current_api;

Expand Down
9 changes: 4 additions & 5 deletions core/object/method_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ uint32_t MethodBind::get_hash() const {
return hash;
}

#ifdef DEBUG_METHODS_ENABLED
PropertyInfo MethodBind::get_argument_info(int p_argument) const {
ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo());

PropertyInfo info = _gen_argument_type_info(p_argument);
#ifdef DEBUG_METHODS_ENABLED
info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument));
#else
info.name = String("arg" + itos(p_argument));
#endif
return info;
}

PropertyInfo MethodBind::get_return_info() const {
return _gen_argument_type_info(-1);
}

#endif
void MethodBind::_set_const(bool p_const) {
_const = p_const;
}
Expand Down Expand Up @@ -109,7 +111,6 @@ void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) {
default_argument_count = default_arguments.size();
}

#ifdef DEBUG_METHODS_ENABLED
void MethodBind::_generate_argument_types(int p_count) {
set_argument_count(p_count);

Expand All @@ -123,8 +124,6 @@ void MethodBind::_generate_argument_types(int p_count) {
argument_types = argt;
}

#endif

MethodBind::MethodBind() {
static int last_id = 0;
method_id = last_id++;
Expand Down
38 changes: 9 additions & 29 deletions core/object/method_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,16 @@ class MethodBind {
bool _returns = false;

protected:
#ifdef DEBUG_METHODS_ENABLED
Variant::Type *argument_types = nullptr;
#ifdef DEBUG_METHODS_ENABLED
Vector<StringName> arg_names;
#endif
void _set_const(bool p_const);
void _set_returns(bool p_returns);
#ifdef DEBUG_METHODS_ENABLED
virtual Variant::Type _gen_argument_type(int p_arg) const = 0;
virtual PropertyInfo _gen_argument_type_info(int p_arg) const = 0;
void _generate_argument_types(int p_count);

#endif
void set_argument_count(int p_count) { argument_count = p_count; }

public:
Expand All @@ -102,7 +100,6 @@ class MethodBind {
}
}

#ifdef DEBUG_METHODS_ENABLED
_FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL);
return argument_types[p_argument + 1];
Expand All @@ -111,6 +108,7 @@ class MethodBind {
PropertyInfo get_argument_info(int p_argument) const;
PropertyInfo get_return_info() const;

#ifdef DEBUG_METHODS_ENABLED
void set_argument_names(const Vector<StringName> &p_names); // Set by ClassDB, can't be inferred otherwise.
Vector<StringName> get_argument_names() const;

Expand Down Expand Up @@ -149,12 +147,9 @@ class MethodBindVarArg : public MethodBind {

protected:
NativeCall call_method = nullptr;
#ifdef DEBUG_METHODS_ENABLED
MethodInfo arguments;
#endif

public:
#ifdef DEBUG_METHODS_ENABLED
virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
if (p_arg < 0) {
return arguments.return_val;
Expand All @@ -169,13 +164,10 @@ class MethodBindVarArg : public MethodBind {
return _gen_argument_type_info(p_arg).type;
}

#ifdef DEBUG_METHODS_ENABLED
virtual GodotTypeInfo::Metadata get_argument_meta(int) const {
return GodotTypeInfo::METADATA_NONE;
}
#else
virtual Variant::Type _gen_argument_type(int p_arg) const {
return Variant::NIL;
}
#endif

virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
Expand All @@ -185,25 +177,29 @@ class MethodBindVarArg : public MethodBind {

void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) {
set_argument_count(p_info.arguments.size());
#ifdef DEBUG_METHODS_ENABLED
Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1);
at[0] = p_info.return_val.type;
if (p_info.arguments.size()) {
#ifdef DEBUG_METHODS_ENABLED
Vector<StringName> names;
names.resize(p_info.arguments.size());
#endif
for (int i = 0; i < p_info.arguments.size(); i++) {
at[i + 1] = p_info.arguments[i].type;
#ifdef DEBUG_METHODS_ENABLED
names.write[i] = p_info.arguments[i].name;
#endif
}

#ifdef DEBUG_METHODS_ENABLED
set_argument_names(names);
#endif
}
argument_types = at;
arguments = p_info;
if (p_return_nil_is_variant) {
arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
#endif
}

virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
Expand Down Expand Up @@ -248,7 +244,6 @@ class MethodBindT : public MethodBind {
void (MB_T::*method)(P...);

protected:
#ifdef DEBUG_METHODS_ENABLED
// GCC raises warnings in the case P = {} as the comparison is always false...
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
Expand All @@ -270,7 +265,6 @@ class MethodBindT : public MethodBind {
call_get_argument_type_info<P...>(p_arg, pi);
return pi;
}
#endif

public:
#ifdef DEBUG_METHODS_ENABLED
Expand Down Expand Up @@ -298,9 +292,7 @@ class MethodBindT : public MethodBind {

MethodBindT(void (MB_T::*p_method)(P...)) {
method = p_method;
#ifdef DEBUG_METHODS_ENABLED
_generate_argument_types(sizeof...(P));
#endif
set_argument_count(sizeof...(P));
}
};
Expand All @@ -327,7 +319,6 @@ class MethodBindTC : public MethodBind {
void (MB_T::*method)(P...) const;

protected:
#ifdef DEBUG_METHODS_ENABLED
// GCC raises warnings in the case P = {} as the comparison is always false...
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
Expand All @@ -349,7 +340,6 @@ class MethodBindTC : public MethodBind {
call_get_argument_type_info<P...>(p_arg, pi);
return pi;
}
#endif

public:
#ifdef DEBUG_METHODS_ENABLED
Expand Down Expand Up @@ -378,9 +368,7 @@ class MethodBindTC : public MethodBind {
MethodBindTC(void (MB_T::*p_method)(P...) const) {
method = p_method;
_set_const(true);
#ifdef DEBUG_METHODS_ENABLED
_generate_argument_types(sizeof...(P));
#endif
set_argument_count(sizeof...(P));
}
};
Expand Down Expand Up @@ -408,7 +396,6 @@ class MethodBindTR : public MethodBind {
(P...);

protected:
#ifdef DEBUG_METHODS_ENABLED
// GCC raises warnings in the case P = {} as the comparison is always false...
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
Expand All @@ -434,7 +421,6 @@ class MethodBindTR : public MethodBind {
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif

public:
#ifdef DEBUG_METHODS_ENABLED
Expand Down Expand Up @@ -468,9 +454,7 @@ class MethodBindTR : public MethodBind {
MethodBindTR(R (MB_T::*p_method)(P...)) {
method = p_method;
_set_returns(true);
#ifdef DEBUG_METHODS_ENABLED
_generate_argument_types(sizeof...(P));
#endif
set_argument_count(sizeof...(P));
}
};
Expand Down Expand Up @@ -499,7 +483,6 @@ class MethodBindTRC : public MethodBind {
(P...) const;

protected:
#ifdef DEBUG_METHODS_ENABLED
// GCC raises warnings in the case P = {} as the comparison is always false...
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
Expand All @@ -525,7 +508,6 @@ class MethodBindTRC : public MethodBind {
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif

public:
#ifdef DEBUG_METHODS_ENABLED
Expand Down Expand Up @@ -560,9 +542,7 @@ class MethodBindTRC : public MethodBind {
method = p_method;
_set_returns(true);
_set_const(true);
#ifdef DEBUG_METHODS_ENABLED
_generate_argument_types(sizeof...(P));
#endif
set_argument_count(sizeof...(P));
}
};
Expand Down
Loading