summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp2
-rw-r--r--core/io/marshalls.cpp4
-rw-r--r--core/io/resource_format_binary.cpp2
-rw-r--r--core/make_binders.py4
-rw-r--r--core/object.cpp4
-rw-r--r--core/object.h40
-rw-r--r--core/os/os.cpp2
-rw-r--r--core/ref_ptr.cpp2
-rw-r--r--core/reference.cpp2
-rw-r--r--core/reference.h12
-rw-r--r--core/undo_redo.cpp28
-rw-r--r--core/variant.cpp4
-rw-r--r--core/variant_parser.cpp2
13 files changed, 34 insertions, 74 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 5f534f63a8..7f4a83ed49 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -2354,7 +2354,7 @@ Variant _ClassDB::instance(const StringName &p_class) const {
if (!obj)
return Variant();
- Reference *r = obj->cast_to<Reference>();
+ Reference *r = Object::cast_to<Reference>(obj);
if (r) {
return REF(r);
} else {
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index e701a89c78..93002e5446 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -463,8 +463,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
obj->set(str, value);
}
- if (obj->cast_to<Reference>()) {
- REF ref = REF(obj->cast_to<Reference>());
+ if (Object::cast_to<Reference>(obj)) {
+ REF ref = REF(Object::cast_to<Reference>(obj));
r_variant = ref;
} else {
r_variant = obj;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index fd8928b8a0..b8e0bbf557 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -713,7 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll() {
}
ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT);
- Resource *r = obj->cast_to<Resource>();
+ Resource *r = Object::cast_to<Resource>(obj);
if (!r) {
error = ERR_FILE_CORRUPT;
memdelete(obj); //bye
diff --git a/core/make_binders.py b/core/make_binders.py
index 0252bb638b..6468c029f0 100644
--- a/core/make_binders.py
+++ b/core/make_binders.py
@@ -29,7 +29,7 @@ public:
virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Variant::CallError& r_error) {
- T *instance=p_object->cast_to<T>();
+ T *instance=Object::cast_to<T>(p_object);
r_error.error=Variant::CallError::CALL_OK;
#ifdef DEBUG_METHODS_ENABLED
@@ -57,7 +57,7 @@ public:
#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) {
- T *instance=p_object->cast_to<T>();
+ T *instance=Object::cast_to<T>(p_object);
$ifret PtrToArg<R>::encode( $ (instance->*method)($arg, PtrToArg<P@>::convert(p_args[@-1])$) $ifret ,r_ret)$ ;
}
#endif
diff --git a/core/object.cpp b/core/object.cpp
index 928e9bb978..5e6c809f7a 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -654,7 +654,7 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args,
if (p_method == CoreStringNames::get_singleton()->_free) {
#ifdef DEBUG_ENABLED
- if (cast_to<Reference>()) {
+ if (Object::cast_to<Reference>(this)) {
ERR_EXPLAIN("Can't 'free' a reference.");
ERR_FAIL();
return;
@@ -900,7 +900,7 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a
r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
return Variant();
}
- if (cast_to<Reference>()) {
+ if (Object::cast_to<Reference>(this)) {
r_error.argument = 0;
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
ERR_EXPLAIN("Can't 'free' a reference.");
diff --git a/core/object.h b/core/object.h
index ab1421e357..88229d27b6 100644
--- a/core/object.h
+++ b/core/object.h
@@ -598,46 +598,6 @@ public:
#endif
}
-// TODO: ensure 'this' is never NULL since it's UB, but by now, avoid warning flood
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wundefined-bool-conversion"
-#endif
-
- template <class T>
- T *cast_to() {
-
-#ifndef NO_SAFE_CAST
- return SAFE_CAST<T *>(this);
-#else
- if (!this)
- return NULL;
- if (is_class_ptr(T::get_class_ptr_static()))
- return static_cast<T *>(this);
- else
- return NULL;
-#endif
- }
-
- template <class T>
- const T *cast_to() const {
-
-#ifndef NO_SAFE_CAST
- return SAFE_CAST<const T *>(this);
-#else
- if (!this)
- return NULL;
- if (is_class_ptr(T::get_class_ptr_static()))
- return static_cast<const T *>(this);
- else
- return NULL;
-#endif
- }
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-
enum {
NOTIFICATION_POSTINITIALIZE = 0,
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 3a06a3fa8f..c49ab6f706 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -171,7 +171,7 @@ static FileAccess *_OSPRF = NULL;
static void _OS_printres(Object *p_obj) {
- Resource *res = p_obj->cast_to<Resource>();
+ Resource *res = Object::cast_to<Resource>(p_obj);
if (!res)
return;
diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp
index c2128fd45d..7bd8523292 100644
--- a/core/ref_ptr.cpp
+++ b/core/ref_ptr.cpp
@@ -69,7 +69,7 @@ RID RefPtr::get_rid() const {
Ref<Reference> *ref = reinterpret_cast<Ref<Reference> *>(&data[0]);
if (ref->is_null())
return RID();
- Resource *res = (*ref)->cast_to<Resource>();
+ Resource *res = Object::cast_to<Resource>(ref->ptr());
if (res)
return res->get_rid();
return RID();
diff --git a/core/reference.cpp b/core/reference.cpp
index e9629ee7c0..1380dbd56e 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -98,7 +98,7 @@ Variant WeakRef::get_ref() const {
Object *obj = ObjectDB::get_instance(ref);
if (!obj)
return Variant();
- Reference *r = obj->cast_to<Reference>();
+ Reference *r = cast_to<Reference>(obj);
if (r) {
return REF(r);
diff --git a/core/reference.h b/core/reference.h
index 764c924cdb..a8034a73c6 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -180,7 +180,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
@@ -194,7 +194,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
@@ -209,7 +209,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
@@ -230,7 +230,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
@@ -254,7 +254,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
@@ -269,7 +269,7 @@ public:
return;
}
Ref r;
- r.reference = refb->cast_to<T>();
+ r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = NULL;
}
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index bb70146396..00a468816a 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -111,8 +111,8 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- do_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
do_op.type = Operation::TYPE_METHOD;
do_op.name = p_method;
@@ -135,8 +135,8 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
undo_op.type = Operation::TYPE_METHOD;
undo_op.name = p_method;
@@ -152,8 +152,8 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- do_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
do_op.type = Operation::TYPE_PROPERTY;
do_op.name = p_property;
@@ -171,8 +171,8 @@ void UndoRedo::add_undo_property(Object *p_object, const String &p_property, con
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
undo_op.type = Operation::TYPE_PROPERTY;
undo_op.name = p_property;
@@ -185,8 +185,8 @@ void UndoRedo::add_do_reference(Object *p_object) {
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- do_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
do_op.type = Operation::TYPE_REFERENCE;
actions[current_action + 1].do_ops.push_back(do_op);
@@ -202,8 +202,8 @@ void UndoRedo::add_undo_reference(Object *p_object) {
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (p_object->cast_to<Resource>())
- undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>());
+ if (Object::cast_to<Resource>(p_object))
+ undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
undo_op.type = Operation::TYPE_REFERENCE;
actions[current_action + 1].undo_ops.push_back(undo_op);
@@ -270,7 +270,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
obj->call(op.name, VARIANT_ARGS_FROM_ARRAY(op.args));
#ifdef TOOLS_ENABLED
- Resource *res = obj->cast_to<Resource>();
+ Resource *res = Object::cast_to<Resource>(obj);
if (res)
res->set_edited(true);
@@ -284,7 +284,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
obj->set(op.name, op.args[0]);
#ifdef TOOLS_ENABLED
- Resource *res = obj->cast_to<Resource>();
+ Resource *res = Object::cast_to<Resource>(obj);
if (res)
res->set_edited(true);
#endif
diff --git a/core/variant.cpp b/core/variant.cpp
index 51c4b70bdc..e6a69edd08 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1764,14 +1764,14 @@ Variant::operator Object *() const {
Variant::operator Node *() const {
if (type == OBJECT)
- return _get_obj().obj ? _get_obj().obj->cast_to<Node>() : NULL;
+ return Object::cast_to<Node>(_get_obj().obj);
else
return NULL;
}
Variant::operator Control *() const {
if (type == OBJECT)
- return _get_obj().obj ? _get_obj().obj->cast_to<Control>() : NULL;
+ return Object::cast_to<Control>(_get_obj().obj);
else
return NULL;
}
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 5aa71f6704..a1b168621c 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -742,7 +742,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return err;
if (token.type == TK_PARENTHESIS_CLOSE) {
- Reference *reference = obj->cast_to<Reference>();
+ Reference *reference = Object::cast_to<Reference>(obj);
if (reference) {
value = REF(reference);
} else {