From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- core/object.cpp | 215 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 142 insertions(+), 73 deletions(-) (limited to 'core/object.cpp') diff --git a/core/object.cpp b/core/object.cpp index 64b519f1b9..0a4e8a5890 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -75,24 +75,29 @@ PropertyInfo::operator Dictionary() const { PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { PropertyInfo pi; - if (p_dict.has("type")) + if (p_dict.has("type")) { pi.type = Variant::Type(int(p_dict["type"])); + } - if (p_dict.has("name")) + if (p_dict.has("name")) { pi.name = p_dict["name"]; + } - if (p_dict.has("class_name")) + if (p_dict.has("class_name")) { pi.class_name = p_dict["class_name"]; + } - if (p_dict.has("hint")) + if (p_dict.has("hint")) { pi.hint = PropertyHint(int(p_dict["hint"])); + } - if (p_dict.has("hint_string")) - + if (p_dict.has("hint_string")) { pi.hint_string = p_dict["hint_string"]; + } - if (p_dict.has("usage")) + if (p_dict.has("usage")) { pi.usage = p_dict["usage"]; + } return pi; } @@ -111,8 +116,9 @@ MethodInfo::operator Dictionary() const { d["name"] = name; d["args"] = convert_property_list(&arguments); Array da; - for (int i = 0; i < default_arguments.size(); i++) + 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; @@ -124,8 +130,9 @@ MethodInfo::operator Dictionary() const { MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { MethodInfo mi; - if (p_dict.has("name")) + if (p_dict.has("name")) { mi.name = p_dict["name"]; + } Array args; if (p_dict.has("args")) { args = p_dict["args"]; @@ -147,8 +154,9 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { mi.return_val = PropertyInfo::from_dict(p_dict["return"]); } - if (p_dict.has("flags")) + if (p_dict.has("flags")) { mi.flags = p_dict["flags"]; + } return mi; } @@ -327,14 +335,18 @@ bool Object::Connection::operator<(const Connection &p_conn) const { Object::Connection::Connection(const Variant &p_variant) { Dictionary d = p_variant; - if (d.has("signal")) + if (d.has("signal")) { signal = d["signal"]; - if (d.has("callable")) + } + if (d.has("callable")) { callable = d["callable"]; - if (d.has("flags")) + } + if (d.has("flags")) { flags = d["flags"]; - if (d.has("binds")) + } + if (d.has("binds")) { binds = d["binds"]; + } } bool Object::_predelete() { @@ -366,8 +378,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid if (script_instance) { if (script_instance->set(p_name, p_value)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } @@ -385,23 +398,26 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid if (p_name == CoreStringNames::get_singleton()->_script) { set_script(p_value); - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } else if (p_name == CoreStringNames::get_singleton()->_meta) { //set_meta(p_name,p_value); metadata = p_value.duplicate(); - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } //something inside the object... :| bool success = _setv(p_name, p_value); if (success) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } @@ -409,8 +425,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid bool valid; setvar(p_name, p_value, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } @@ -420,15 +437,17 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid bool valid; script_instance->property_set_fallback(p_name, p_value, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } #endif - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant Object::get(const StringName &p_name, bool *r_valid) const { @@ -436,8 +455,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { if (script_instance) { if (script_instance->get(p_name, ret)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } @@ -445,30 +465,34 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { //try built-in setgetter { if (ClassDB::get_property(const_cast(this), p_name, ret)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } if (p_name == CoreStringNames::get_singleton()->_script) { ret = get_script(); - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } else if (p_name == CoreStringNames::get_singleton()->_meta) { ret = metadata; - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } else { //something inside the object... :| bool success = _getv(p_name, ret); if (success) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } @@ -477,8 +501,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { bool valid; ret = getvar(p_name, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } @@ -488,23 +513,26 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { bool valid; ret = script_instance->property_get_fallback(p_name, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } #endif - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } } void Object::set_indexed(const Vector &p_names, const Variant &p_value, bool *r_valid) { if (p_names.empty()) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return; } if (p_names.size() == 1) { @@ -513,8 +541,9 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val } bool valid = false; - if (!r_valid) + if (!r_valid) { r_valid = &valid; + } List value_stack; @@ -554,8 +583,9 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val Variant Object::get_indexed(const Vector &p_names, bool *r_valid) const { if (p_names.empty()) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } bool valid = false; @@ -564,11 +594,13 @@ Variant Object::get_indexed(const Vector &p_names, bool *r_valid) co for (int i = 1; i < p_names.size(); i++) { current_value = current_value.get_named(p_names[i], &valid); - if (!valid) + if (!valid) { break; + } } - if (r_valid) + if (r_valid) { *r_valid = valid; + } return current_value; } @@ -741,14 +773,16 @@ bool Object::has_method(const StringName &p_method) const { } Variant Object::getvar(const Variant &p_key, bool *r_valid) const { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant Object::callv(const StringName &p_method, const Array &p_args) { @@ -774,8 +808,9 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -790,8 +825,9 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -871,8 +907,9 @@ String Object::to_string() { if (script_instance) { bool valid; String ret = script_instance->to_string(&valid); - if (valid) + if (valid) { return ret; + } } return "[" + get_class() + ":" + itos(get_instance_id()) + "]"; } @@ -907,8 +944,9 @@ void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_ } void Object::set_script(const Variant &p_script) { - if (script == p_script) + if (script == p_script) { return; + } if (script_instance) { memdelete(script_instance); @@ -933,18 +971,21 @@ void Object::set_script(const Variant &p_script) { } void Object::set_script_instance(ScriptInstance *p_instance) { - if (script_instance == p_instance) + if (script_instance == p_instance) { return; + } - if (script_instance) + if (script_instance) { memdelete(script_instance); + } script_instance = p_instance; - if (p_instance) + if (p_instance) { script = p_instance->get_script(); - else + } else { script = Variant(); + } } Variant Object::get_script() const { @@ -1023,8 +1064,9 @@ void Object::add_user_signal(const MethodInfo &p_signal) { } bool Object::_has_user_signal(const StringName &p_name) const { - if (!signal_map.has(p_name)) + if (!signal_map.has(p_name)) { return false; + } return signal_map[p_name].user.name.length() > 0; } @@ -1061,8 +1103,9 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C } Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) { - if (_block_signals) + if (_block_signals) { return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked + } SignalData *s = signal_map.getptr(p_name); if (!s) { @@ -1128,8 +1171,9 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int if (ce.error != Callable::CallError::CALL_OK) { #ifdef DEBUG_ENABLED - if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref