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. --- core/node_path.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'core/node_path.cpp') diff --git a/core/node_path.cpp b/core/node_path.cpp index f8001a354a..0e4f2eeaf0 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -33,7 +33,6 @@ #include "core/print_string.h" void NodePath::_update_hash_cache() const { - uint32_t h = data->absolute ? 1 : 0; int pc = data->path.size(); const StringName *sn = data->path.ptr(); @@ -51,7 +50,6 @@ void NodePath::_update_hash_cache() const { } void NodePath::prepend_period() { - if (data->path.size() && data->path[0].operator String() != ".") { data->path.insert(0, "."); data->hash_cache_valid = false; @@ -59,51 +57,43 @@ void NodePath::prepend_period() { } bool NodePath::is_absolute() const { - if (!data) return false; return data->absolute; } int NodePath::get_name_count() const { - if (!data) return 0; return data->path.size(); } StringName NodePath::get_name(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); return data->path[p_idx]; } int NodePath::get_subname_count() const { - if (!data) return 0; return data->subpath.size(); } StringName NodePath::get_subname(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); return data->subpath[p_idx]; } void NodePath::unref() { - if (data && data->refcount.unref()) { - memdelete(data); } data = nullptr; } bool NodePath::operator==(const NodePath &p_path) const { - if (data == p_path.data) return true; @@ -129,7 +119,6 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_path_ptr = p_path.data->path.ptr(); for (int i = 0; i < path_size; i++) { - if (l_path_ptr[i] != r_path_ptr[i]) return false; } @@ -138,7 +127,6 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_subpath_ptr = p_path.data->subpath.ptr(); for (int i = 0; i < subpath_size; i++) { - if (l_subpath_ptr[i] != r_subpath_ptr[i]) return false; } @@ -146,25 +134,21 @@ bool NodePath::operator==(const NodePath &p_path) const { return true; } bool NodePath::operator!=(const NodePath &p_path) const { - return (!(*this == p_path)); } void NodePath::operator=(const NodePath &p_path) { - if (this == &p_path) return; unref(); if (p_path.data && p_path.data->refcount.ref()) { - data = p_path.data; } } NodePath::operator String() const { - if (!data) return String(); @@ -173,14 +157,12 @@ NodePath::operator String() const { ret = "/"; for (int i = 0; i < data->path.size(); i++) { - if (i > 0) ret += "/"; ret += data->path[i].operator String(); } for (int i = 0; i < data->subpath.size(); i++) { - ret += ":" + data->subpath[i].operator String(); } @@ -188,14 +170,12 @@ NodePath::operator String() const { } Vector NodePath::get_names() const { - if (data) return data->path; return Vector(); } Vector NodePath::get_subnames() const { - if (data) return data->subpath; return Vector(); @@ -217,7 +197,6 @@ StringName NodePath::get_concatenated_subnames() const { } NodePath NodePath::rel_path_to(const NodePath &p_np) const { - ERR_FAIL_COND_V(!is_absolute(), NodePath()); ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); @@ -242,12 +221,10 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { Vector relpath; for (int i = src_dirs.size() - 1; i > common_parent; i--) { - relpath.push_back(".."); } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - relpath.push_back(dst_dirs[i]); } @@ -258,7 +235,6 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { } NodePath NodePath::get_as_property_path() const { - if (!data || !data->path.size()) { return *this; } else { @@ -280,7 +256,6 @@ bool NodePath::is_empty() const { } void NodePath::simplify() { - if (!data) return; for (int i = 0; i < data->path.size(); i++) { @@ -304,7 +279,6 @@ void NodePath::simplify() { } NodePath NodePath::simplified() const { - NodePath np = *this; np.simplify(); return np; @@ -355,13 +329,10 @@ NodePath::NodePath(const String &p_path) { int subpath_pos = path.find(":"); if (subpath_pos != -1) { - int from = subpath_pos + 1; for (int i = from; i <= path.length(); i++) { - if (path[i] == ':' || path[i] == 0) { - String str = path.substr(from, i - from); if (str == "") { if (path[i] == 0) @@ -379,13 +350,10 @@ NodePath::NodePath(const String &p_path) { } for (int i = (int)absolute; i < path.length(); i++) { - if (path[i] == '/') { - last_is_slash = true; has_slashes = true; } else { - if (last_is_slash) slices++; @@ -411,11 +379,8 @@ NodePath::NodePath(const String &p_path) { int slice = 0; for (int i = (int)absolute; i < path.length() + 1; i++) { - if (path[i] == '/' || path[i] == 0) { - if (!last_is_slash) { - String name = path.substr(from, i - from); ERR_FAIL_INDEX(slice, data->path.size()); data->path.write[slice++] = name; -- 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. --- core/node_path.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/node_path.cpp') diff --git a/core/node_path.cpp b/core/node_path.cpp index 0e4f2eeaf0..fd28815704 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -62,12 +62,14 @@ bool NodePath::is_absolute() const { return data->absolute; } + int NodePath::get_name_count() const { if (!data) return 0; return data->path.size(); } + StringName NodePath::get_name(int p_idx) const { ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); @@ -80,6 +82,7 @@ int NodePath::get_subname_count() const { return data->subpath.size(); } + StringName NodePath::get_subname(int p_idx) const { ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); @@ -133,6 +136,7 @@ bool NodePath::operator==(const NodePath &p_path) const { return true; } + bool NodePath::operator!=(const NodePath &p_path) const { return (!(*this == p_path)); } -- cgit v1.2.3 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/node_path.cpp | 81 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 27 deletions(-) (limited to 'core/node_path.cpp') diff --git a/core/node_path.cpp b/core/node_path.cpp index fd28815704..2a51dca74a 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -57,15 +57,17 @@ void NodePath::prepend_period() { } bool NodePath::is_absolute() const { - if (!data) + if (!data) { return false; + } return data->absolute; } int NodePath::get_name_count() const { - if (!data) + if (!data) { return 0; + } return data->path.size(); } @@ -77,8 +79,9 @@ StringName NodePath::get_name(int p_idx) const { } int NodePath::get_subname_count() const { - if (!data) + if (!data) { return 0; + } return data->subpath.size(); } @@ -97,14 +100,17 @@ void NodePath::unref() { } bool NodePath::operator==(const NodePath &p_path) const { - if (data == p_path.data) + if (data == p_path.data) { return true; + } - if (!data || !p_path.data) + if (!data || !p_path.data) { return false; + } - if (data->absolute != p_path.data->absolute) + if (data->absolute != p_path.data->absolute) { return false; + } int path_size = data->path.size(); @@ -122,16 +128,18 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_path_ptr = p_path.data->path.ptr(); for (int i = 0; i < path_size; i++) { - if (l_path_ptr[i] != r_path_ptr[i]) + if (l_path_ptr[i] != r_path_ptr[i]) { return false; + } } const StringName *l_subpath_ptr = data->subpath.ptr(); const StringName *r_subpath_ptr = p_path.data->subpath.ptr(); for (int i = 0; i < subpath_size; i++) { - if (l_subpath_ptr[i] != r_subpath_ptr[i]) + if (l_subpath_ptr[i] != r_subpath_ptr[i]) { return false; + } } return true; @@ -142,8 +150,9 @@ bool NodePath::operator!=(const NodePath &p_path) const { } void NodePath::operator=(const NodePath &p_path) { - if (this == &p_path) + if (this == &p_path) { return; + } unref(); @@ -153,16 +162,19 @@ void NodePath::operator=(const NodePath &p_path) { } NodePath::operator String() const { - if (!data) + if (!data) { return String(); + } String ret; - if (data->absolute) + if (data->absolute) { ret = "/"; + } for (int i = 0; i < data->path.size(); i++) { - if (i > 0) + if (i > 0) { ret += "/"; + } ret += data->path[i].operator String(); } @@ -174,14 +186,16 @@ NodePath::operator String() const { } Vector NodePath::get_names() const { - if (data) + if (data) { return data->path; + } return Vector(); } Vector NodePath::get_subnames() const { - if (data) + if (data) { return data->subpath; + } return Vector(); } @@ -211,12 +225,15 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { int common_parent = 0; while (true) { - if (src_dirs.size() == common_parent) + if (src_dirs.size() == common_parent) { break; - if (dst_dirs.size() == common_parent) + } + if (dst_dirs.size() == common_parent) { break; - if (src_dirs[common_parent] != dst_dirs[common_parent]) + } + if (src_dirs[common_parent] != dst_dirs[common_parent]) { break; + } common_parent++; } @@ -232,8 +249,9 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { relpath.push_back(dst_dirs[i]); } - if (relpath.size() == 0) + if (relpath.size() == 0) { relpath.push_back("."); + } return NodePath(relpath, p_np.get_subnames(), false); } @@ -260,11 +278,13 @@ bool NodePath::is_empty() const { } void NodePath::simplify() { - if (!data) + if (!data) { return; + } for (int i = 0; i < data->path.size(); i++) { - if (data->path.size() == 1) + if (data->path.size() == 1) { break; + } if (data->path[i].operator String() == ".") { data->path.remove(i); i--; @@ -289,8 +309,9 @@ NodePath NodePath::simplified() const { } NodePath::NodePath(const Vector &p_path, bool p_absolute) { - if (p_path.size() == 0) + if (p_path.size() == 0) { return; + } data = memnew(Data); data->refcount.init(); @@ -301,8 +322,9 @@ NodePath::NodePath(const Vector &p_path, bool p_absolute) { } NodePath::NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute) { - if (p_path.size() == 0 && p_subpath.size() == 0) + if (p_path.size() == 0 && p_subpath.size() == 0) { return; + } data = memnew(Data); data->refcount.init(); @@ -320,8 +342,9 @@ NodePath::NodePath(const NodePath &p_path) { } NodePath::NodePath(const String &p_path) { - if (p_path.length() == 0) + if (p_path.length() == 0) { return; + } String path = p_path; Vector subpath; @@ -339,8 +362,9 @@ NodePath::NodePath(const String &p_path) { if (path[i] == ':' || path[i] == 0) { String str = path.substr(from, i - from); if (str == "") { - if (path[i] == 0) + if (path[i] == 0) { continue; // Allow end-of-path : + } ERR_FAIL_MSG("Invalid NodePath '" + p_path + "'."); } @@ -358,15 +382,17 @@ NodePath::NodePath(const String &p_path) { last_is_slash = true; has_slashes = true; } else { - if (last_is_slash) + if (last_is_slash) { slices++; + } last_is_slash = false; } } - if (slices == 0 && !absolute && !subpath.size()) + if (slices == 0 && !absolute && !subpath.size()) { return; + } data = memnew(Data); data->refcount.init(); @@ -375,8 +401,9 @@ NodePath::NodePath(const String &p_path) { data->subpath = subpath; data->hash_cache_valid = false; - if (slices == 0) + if (slices == 0) { return; + } data->path.resize(slices); last_is_slash = true; int from = (int)absolute; -- cgit v1.2.3