From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- modules/gdnative/nativescript/nativescript.cpp | 49 -------------------------- 1 file changed, 49 deletions(-) (limited to 'modules/gdnative/nativescript/nativescript.cpp') diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index ed3ec44bf7..70a651be1e 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -169,7 +169,6 @@ String NativeScript::get_script_class_icon_path() const { } bool NativeScript::can_instance() const { - NativeScriptDesc *script_data = get_script_desc(); #ifdef TOOLS_ENABLED @@ -207,7 +206,6 @@ StringName NativeScript::get_instance_base_type() const { } ScriptInstance *NativeScript::instance_create(Object *p_this) { - NativeScriptDesc *script_data = get_script_desc(); if (!script_data) { @@ -336,7 +334,6 @@ void NativeScript::get_script_signal_list(List *r_signals) const { Set signals_; while (script_data) { - for (Map::Element *S = script_data->signals_.front(); S; S = S->next()) { signals_.insert(S->get().signal); } @@ -376,7 +373,6 @@ void NativeScript::get_script_method_list(List *p_list) const { Set methods; while (script_data) { - for (Map::Element *E = script_data->methods.front(); E; E = E->next()) { methods.insert(E->get().info); } @@ -408,13 +404,11 @@ void NativeScript::get_script_property_list(List *p_list) const { } Vector NativeScript::get_rpc_methods() const { - Vector v; NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -434,7 +428,6 @@ uint16_t NativeScript::get_rpc_method_id(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map::Element *E = script_data->methods.find(p_method); if (E) { return E->get().rpc_method_id; @@ -452,7 +445,6 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { return E->key(); @@ -466,13 +458,11 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { switch (E->get().rpc_mode) { @@ -503,11 +493,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode(const StringName &p_method) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map::Element *E = script_data->methods.find(p_method); if (E) { switch (E->get().rpc_mode) { @@ -542,7 +530,6 @@ Vector NativeScript::get_rset_properties() const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -561,7 +548,6 @@ uint16_t NativeScript::get_rset_property_id(const StringName &p_variable) const NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap::Element E = script_data->properties.find(p_variable); if (E) { return E.get().rset_property_id; @@ -579,7 +565,6 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { return E.key(); @@ -593,13 +578,11 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { switch (E.get().rset_mode) { @@ -630,11 +613,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode(const StringName &p_variable) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap::Element E = script_data->properties.find(p_variable); if (E) { switch (E.get().rset_mode) { @@ -677,7 +658,6 @@ String NativeScript::get_method_documentation(const StringName &p_method) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); while (script_data) { - Map::Element *method = script_data->methods.find(p_method); if (method) { @@ -696,7 +676,6 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); while (script_data) { - Map::Element *signal = script_data->signals_.find(p_signal_name); if (signal) { @@ -715,7 +694,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); while (script_data) { - OrderedHashMap::Element property = script_data->properties.find(p_path); if (property) { @@ -729,7 +707,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (lib_path.empty() || class_name.empty() || library.is_null()) { r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; return Variant(); @@ -884,10 +861,8 @@ void NativeScriptInstance::get_property_list(List *p_properties) c NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - Map::Element *E = script_data->methods.find("_get_property_list"); if (E) { - godot_variant result; result = E->get().method.method((godot_object *)owner, E->get().method.method_data, @@ -936,11 +911,9 @@ void NativeScriptInstance::get_property_list(List *p_properties) c } Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - OrderedHashMap::Element P = script_data->properties.find(p_name); if (P) { *r_is_valid = true; @@ -961,7 +934,6 @@ bool NativeScriptInstance::has_method(const StringName &p_method) const { } Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { @@ -1127,7 +1099,6 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, } NativeScriptInstance::~NativeScriptInstance() { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); if (!script_data) @@ -1145,16 +1116,13 @@ NativeScriptInstance::~NativeScriptInstance() { NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { - Map> erase_and_unload; for (Map>::Element *L = library_classes.front(); L; L = L->next()) { - String lib_path = L->key(); Map classes = L->get(); if (p_reload) { - Map>::Element *E = library_gdnatives.find(lib_path); Ref gdn; @@ -1184,7 +1152,6 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { } for (Map::Element *C = classes.front(); C; C = C->next()) { - // free property stuff first for (OrderedHashMap::Element P = C->get().properties.front(); P; P = P.next()) { if (P.get().getter.free_func) @@ -1253,13 +1220,10 @@ NativeScriptLanguage::NativeScriptLanguage() { } NativeScriptLanguage::~NativeScriptLanguage() { - for (Map>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref lib = L->get(); // only shut down valid libs, duh! if (lib.is_valid()) { - // If it's a singleton-library then the gdnative module // manages the destruction at engine shutdown, not NativeScript. if (!lib->get_library()->is_singleton()) { @@ -1285,7 +1249,6 @@ void _add_reload_node() { } void NativeScriptLanguage::init() { - #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) List args = OS::get_singleton()->get_cmdline_args(); @@ -1490,7 +1453,6 @@ void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p } int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) { - // find index int idx = -1; @@ -1553,7 +1515,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } if (!(*binding_data)[p_idx]) { - const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name()); // no binding data yet, soooooo alloc new one \o/ @@ -1564,7 +1525,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { - Vector *binding_data = new Vector; binding_data->resize(binding_functions.size()); @@ -1579,7 +1539,6 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { - if (!p_data) return; @@ -1600,7 +1559,6 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) { } void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); if (!data) @@ -1622,7 +1580,6 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec } bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); if (!data) @@ -1741,13 +1698,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here for (Map>::Element *L = library_gdnatives.front(); L; L = L->next()) { - if (L->get().is_null()) { continue; } if (L->get()->is_initialized()) { - void *proc_ptr; Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); @@ -1835,14 +1790,12 @@ void NativeReloadNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_WM_FOCUS_OUT: { - if (unloaded) break; MutexLock lock(NSL->mutex); NSL->_unload_stuff(true); for (Map>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref gdn = L->get(); if (gdn.is_null()) { @@ -1870,14 +1823,12 @@ void NativeReloadNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_IN: { - if (!unloaded) break; MutexLock lock(NSL->mutex); Set libs_to_remove; for (Map>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref gdn = L->get(); if (gdn.is_null()) { -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- modules/gdnative/nativescript/nativescript.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'modules/gdnative/nativescript/nativescript.cpp') diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 70a651be1e..fe9496702a 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -817,6 +817,7 @@ bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) } return false; } + bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { NativeScriptDesc *script_data = GET_SCRIPT_DESC(); @@ -1267,22 +1268,29 @@ void NativeScriptLanguage::init() { EditorNode::add_init_callback(&_add_reload_node); #endif } + String NativeScriptLanguage::get_type() const { return "NativeScript"; } + String NativeScriptLanguage::get_extension() const { return "gdns"; } + Error NativeScriptLanguage::execute_file(const String &p_path) { return OK; // Qué? } + void NativeScriptLanguage::finish() { _unload_stuff(); } + void NativeScriptLanguage::get_reserved_words(List *p_words) const { } + void NativeScriptLanguage::get_comment_delimiters(List *p_delimiters) const { } + void NativeScriptLanguage::get_string_delimiters(List *p_delimiters) const { } @@ -1291,6 +1299,7 @@ Ref