diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnative/arvr/arvr_interface_gdnative.cpp | 3 | ||||
-rw-r--r-- | modules/gdnative/gdnative.cpp | 3 | ||||
-rw-r--r-- | modules/gdnative/nativescript/godot_nativescript.cpp | 74 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 45 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_script.cpp | 25 | ||||
-rw-r--r-- | modules/gdscript/gdscript.cpp | 33 | ||||
-rw-r--r-- | modules/gdscript/gdscript_compiler.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.cpp | 9 | ||||
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 3 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 18 | ||||
-rw-r--r-- | modules/gdscript/gdscript_tokenizer.cpp | 9 |
11 files changed, 62 insertions, 166 deletions
diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.cpp b/modules/gdnative/arvr/arvr_interface_gdnative.cpp index 64e2c362b2..bd6eb575d0 100644 --- a/modules/gdnative/arvr/arvr_interface_gdnative.cpp +++ b/modules/gdnative/arvr/arvr_interface_gdnative.cpp @@ -245,8 +245,7 @@ extern "C" { void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) { // If our major version is 0 or bigger then 10, we're likely looking at our constructor pointer from an older plugin - ERR_EXPLAINC("GDNative ARVR interfaces build for Godot 3.0 are not supported"); - ERR_FAIL_COND((p_interface->version.major == 0) || (p_interface->version.major > 10)); + ERR_FAIL_COND_MSG((p_interface->version.major == 0) || (p_interface->version.major > 10), "GDNative ARVR interfaces build for Godot 3.0 are not supported."); Ref<ARVRInterfaceGDNative> new_interface; new_interface.instance(); diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 4eb9a2a0a3..783ad4e147 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -268,8 +268,7 @@ void GDNative::_bind_methods() { } void GDNative::set_library(Ref<GDNativeLibrary> p_library) { - ERR_EXPLAIN("Tried to change library of GDNative when it is already set"); - ERR_FAIL_COND(library.is_valid()); + ERR_FAIL_COND_MSG(library.is_valid(), "Tried to change library of GDNative when it is already set."); library = p_library; } diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index 863999d6d4..979e47f7b9 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -104,11 +104,7 @@ void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const cha String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); NativeScriptDesc::Method method; method.method = p_method; @@ -123,11 +119,7 @@ void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const c String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); NativeScriptDesc::Property property; property.default_value = *(Variant *)&p_attr->default_value; @@ -148,11 +140,7 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); List<PropertyInfo> args; Vector<Variant> default_args; @@ -213,17 +201,10 @@ void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_h String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add argument information for a method on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add argument information for a method on a non-existent class."); Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - if (!method) { - ERR_EXPLAIN("Attempted to add argument information to non-existent method!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!method, "Attempted to add argument information to non-existent method."); MethodInfo *method_information = &method->get().info; @@ -247,11 +228,7 @@ void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, c String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a non-existent class."); E->get().documentation = *(String *)&p_documentation; } @@ -260,17 +237,10 @@ void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a method on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a method on a non-existent class."); Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - if (!method) { - ERR_EXPLAIN("Attempted to add documentatino to non-existent method!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!method, "Attempted to add documentation to non-existent method."); method->get().documentation = *(String *)&p_documentation; } @@ -279,17 +249,10 @@ void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a property on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a property on a non-existent class."); OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = E->get().properties.find(p_path); - if (!property) { - ERR_EXPLAIN("Attempted to add documentation to non-existent property!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!property, "Attempted to add documentation to non-existent property."); property.get().documentation = *(String *)&p_documentation; } @@ -298,17 +261,10 @@ void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a signal on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a signal on a non-existent class."); Map<StringName, NativeScriptDesc::Signal>::Element *signal = E->get().signals_.find(p_signal_name); - if (!signal) { - ERR_EXPLAIN("Attempted to add documentation to non-existent signal!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!signal, "Attempted to add documentation to non-existent signal."); signal->get().documentation = *(String *)&p_documentation; } @@ -325,11 +281,7 @@ void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char * String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to set type tag on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to set type tag on a non-existent class."); E->get().type_tag = p_type_tag; } diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index f30c9da4c1..9f7c3880ec 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -402,10 +402,7 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { String NativeScript::get_class_documentation() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get class documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get class documentation on invalid NativeScript."); return script_data->documentation; } @@ -413,10 +410,7 @@ String NativeScript::get_class_documentation() const { String NativeScript::get_method_documentation(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get method documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); while (script_data) { @@ -429,17 +423,13 @@ String NativeScript::get_method_documentation(const StringName &p_method) const script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get method documentation for non-existent method"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get method documentation for non-existent method."); } String NativeScript::get_signal_documentation(const StringName &p_signal_name) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get signal documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); while (script_data) { @@ -452,17 +442,13 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get signal documentation for non-existent signal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get signal documentation for non-existent signal."); } String NativeScript::get_property_documentation(const StringName &p_path) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get property documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); while (script_data) { @@ -475,8 +461,7 @@ String NativeScript::get_property_documentation(const StringName &p_path) const script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get property documentation for non-existent signal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get property documentation for non-existent signal."); } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { @@ -655,10 +640,7 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c Variant res = *(Variant *)&result; godot_variant_destroy(&result); - if (res.get_type() != Variant::ARRAY) { - ERR_EXPLAIN("_get_property_list must return an array of dictionaries"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(res.get_type() != Variant::ARRAY, "_get_property_list must return an array of dictionaries."); Array arr = res; for (int i = 0; i < arr.size(); i++) { @@ -780,8 +762,7 @@ String NativeScriptInstance::to_string(bool *r_valid) { if (ret.get_type() != Variant::STRING) { if (r_valid) *r_valid = false; - ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } if (r_valid) *r_valid = true; @@ -1344,10 +1325,7 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), NULL); - if (!binding_functions[p_idx].first) { - ERR_EXPLAIN("Tried to get binding data for a nativescript binding that does not exist"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, NULL, "Tried to get binding data for a nativescript binding that does not exist."); Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); @@ -1499,8 +1477,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { #endif // See if this library was "registered" already. const String &lib_path = lib->get_current_library_path(); - ERR_EXPLAIN(lib->get_name() + " does not have a library for the current platform"); - ERR_FAIL_COND(lib_path.length() == 0); + ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform."); Map<String, Ref<GDNative> >::Element *E = library_gdnatives.find(lib_path); if (!E) { diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 3ecb29404a..b82823ab64 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -35,16 +35,14 @@ #include "pluginscript_script.h" #ifdef DEBUG_ENABLED -#define __ASSERT_SCRIPT_REASON "Cannot retrieve pluginscript class for this script, is you code correct ?" -#define ASSERT_SCRIPT_VALID() \ - { \ - ERR_EXPLAIN(__ASSERT_SCRIPT_REASON); \ - ERR_FAIL_COND(!can_instance()); \ +#define __ASSERT_SCRIPT_REASON "Cannot retrieve PluginScript class for this script, is your code correct?" +#define ASSERT_SCRIPT_VALID() \ + { \ + ERR_FAIL_COND_MSG(!can_instance(), __ASSERT_SCRIPT_REASON); \ } -#define ASSERT_SCRIPT_VALID_V(ret) \ - { \ - ERR_EXPLAIN(__ASSERT_SCRIPT_REASON); \ - ERR_FAIL_COND_V(!can_instance(), ret); \ +#define ASSERT_SCRIPT_VALID_V(ret) \ + { \ + ERR_FAIL_COND_V_MSG(!can_instance(), ret, __ASSERT_SCRIPT_REASON); \ } #else #define ASSERT_SCRIPT_VALID() @@ -197,8 +195,7 @@ ScriptInstance *PluginScript::instance_create(Object *p_this) { // if (ScriptDebugger::get_singleton()) { // _language->debug_break_parse(get_path(), 0, msg); // } - ERR_EXPLAIN(msg); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, msg); } } @@ -272,8 +269,7 @@ Error PluginScript::reload(bool p_keep_state) { _ref_base_parent = res; } else { String name = *(StringName *)&manifest.name; - ERR_EXPLAIN(_path + ": Script '" + name + "' has an invalid parent '" + *base_name + "'."); - ERR_FAIL_V(ERR_PARSE_ERROR); + ERR_FAIL_V_MSG(ERR_PARSE_ERROR, _path + ": Script '" + name + "' has an invalid parent '" + *base_name + "'."); } } } @@ -420,8 +416,7 @@ Error PluginScript::load_source_code(const String &p_path) { String s; if (s.parse_utf8((const char *)w.ptr())) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); } _source = s; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index bc28f7009e..d929bdb3e5 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -67,10 +67,7 @@ void GDScriptNativeClass::_bind_methods() { Variant GDScriptNativeClass::_new() { Object *o = instance(); - if (!o) { - ERR_EXPLAIN("Class type: '" + String(name) + "' is not instantiable."); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(!o, Variant(), "Class type: '" + String(name) + "' is not instantiable."); Reference *ref = Object::cast_to<Reference>(o); if (ref) { @@ -158,8 +155,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallErro } else { owner = memnew(Reference); //by default, no base means use reference } - ERR_EXPLAIN("Can't inherit from a virtual class"); - ERR_FAIL_COND_V(!owner, Variant()); + ERR_FAIL_COND_V_MSG(!owner, Variant(), "Can't inherit from a virtual class."); Reference *r = Object::cast_to<Reference>(owner); if (r) { @@ -326,8 +322,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { if (ScriptDebugger::get_singleton()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } - ERR_EXPLAIN("Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + "."); } } @@ -648,10 +643,7 @@ Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p Map<StringName, GDScriptFunction *>::Element *E = top->member_functions.find(p_method); if (E) { - if (!E->get()->is_static()) { - ERR_EXPLAIN("Can't call non-static function: '" + String(p_method) + "' in script."); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(!E->get()->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script."); return E->get()->call(NULL, p_args, p_argcount, r_error); } @@ -826,8 +818,7 @@ Error GDScript::load_source_code(const String &p_path) { String s; if (s.parse_utf8((const char *)w.ptr())) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); } source = s; @@ -1079,11 +1070,8 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const Variant ret = const_cast<GDScriptFunction *>(E->get())->call(const_cast<GDScriptInstance *>(this), NULL, 0, err); if (err.error == Variant::CallError::CALL_OK) { - if (ret.get_type() != Variant::ARRAY) { + ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); - ERR_EXPLAIN("Wrong type for _get_property list, must be an array of dictionaries."); - ERR_FAIL(); - } Array arr = ret; for (int i = 0; i < arr.size(); i++) { @@ -1243,8 +1231,7 @@ String GDScriptInstance::to_string(bool *r_valid) { if (ret.get_type() != Variant::STRING) { if (r_valid) *r_valid = false; - ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } if (r_valid) *r_valid = true; @@ -2057,8 +2044,7 @@ String GDScriptWarning::get_message() const { } break; case WARNING_MAX: break; // Can't happen, but silences warning } - ERR_EXPLAIN("Invalid GDScript warning code: " + get_name_from_code(code)); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + "."); #undef CHECK_SYMBOLS } @@ -2110,8 +2096,7 @@ GDScriptWarning::Code GDScriptWarning::get_code_from_name(const String &p_name) } } - ERR_EXPLAIN("Invalid GDScript warning name: " + p_name); - ERR_FAIL_V(WARNING_MAX); + ERR_FAIL_V_MSG(WARNING_MAX, "Invalid GDScript warning name: " + p_name); } #endif // DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 4c976bd2e0..7166189416 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1241,8 +1241,7 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; default: { - ERR_EXPLAIN("Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression."); - ERR_FAIL_V(0); //unreachable code + ERR_FAIL_V_MSG(0, "Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression."); //unreachable code } break; } @@ -1255,8 +1254,7 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //TYPE_TYPE, default: { - ERR_EXPLAIN("Bug in bytecode compiler, unexpected node in parse tree while parsing expression."); - ERR_FAIL_V(-1); //unreachable code + ERR_FAIL_V_MSG(-1, "Bug in bytecode compiler, unexpected node in parse tree while parsing expression."); //unreachable code } break; } } diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 42f349ffc0..dc0e64fd03 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -86,8 +86,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta o = o->_owner; } - ERR_EXPLAIN("GDScriptCompiler bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "GDScriptCompiler bug."); } break; case ADDR_TYPE_LOCAL_CONSTANT: { #ifdef DEBUG_ENABLED @@ -128,8 +127,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta } break; } - ERR_EXPLAIN("Bad Code! (Addressing Mode)"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Bad code! (unknown addressing mode)."); return NULL; } @@ -1834,8 +1832,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { ERR_FAIL_COND_V(!function, Variant()); if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { #ifdef DEBUG_ENABLED - ERR_EXPLAIN("Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line)); - ERR_FAIL_V(Variant()); + ERR_FAIL_V_MSG(Variant(), "Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line)); #else return Variant(); #endif diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index f5f245b25f..ad8bf5b2c0 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -349,8 +349,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); r_ret = Math::step_decimals((double)*p_args[0]); - ERR_EXPLAIN("GDScript method 'decimals' is deprecated and has been renamed to 'step_decimals', please update your code accordingly."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("GDScript method 'decimals' is deprecated and has been renamed to 'step_decimals', please update your code accordingly."); } break; case MATH_STEP_DECIMALS: { VALIDATE_ARG_COUNT(1); diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 357e9c9615..9a25e788c7 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -898,6 +898,10 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_IS && tokenizer->get_token(1) == GDScriptTokenizer::TK_BUILT_IN_TYPE) { // 'is' operator with built-in type + if (!expr) { + _set_error("Expected identifier before 'is' operator"); + return NULL; + } OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_IS_BUILTIN; op->arguments.push_back(expr); @@ -1136,10 +1140,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s return NULL; //nothing } - if (!expr) { - ERR_EXPLAIN("GDScriptParser bug, couldn't figure out what expression is..."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!expr, NULL, "GDScriptParser bug, couldn't figure out what expression is."); /******************/ /* Parse Indexing */ @@ -4019,8 +4020,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - ERR_EXPLAIN("Exporting bit flags hint requires string constants."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("Exporting bit flags hint requires string constants."); break; } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { @@ -6695,8 +6695,7 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String } if (!ClassDB::class_exists(native)) { if (!check_types) return false; - ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found."); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found."); } MethodBind *method = ClassDB::get_method(native, p_function); @@ -7204,8 +7203,7 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN } if (!ClassDB::class_exists(native)) { if (!check_types) return false; - ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found."); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found."); } bool valid = false; diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 59b53b5f9a..64b354bdb8 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -357,8 +357,7 @@ StringName GDScriptTokenizer::get_token_literal(int p_offset) const { } } } - ERR_EXPLAIN("Failed to get token literal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Failed to get token literal."); } static bool _is_text_char(CharType c) { @@ -1219,10 +1218,8 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) ERR_FAIL_COND_V(p_buffer.size() < 24 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA); int version = decode_uint32(&buf[4]); - if (version > BYTECODE_VERSION) { - ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version."); - ERR_FAIL_V(ERR_INVALID_DATA); - } + ERR_FAIL_COND_V_MSG(version > BYTECODE_VERSION, ERR_INVALID_DATA, "Bytecode is too recent! Please use a newer engine version."); + int identifier_count = decode_uint32(&buf[8]); int constant_count = decode_uint32(&buf[12]); int line_count = decode_uint32(&buf[16]); |