Skip to content

Commit

Permalink
Some code changed with Clang-Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Jun 26, 2019
1 parent 5c66771 commit 4e5310c
Show file tree
Hide file tree
Showing 175 changed files with 455 additions and 662 deletions.
2 changes: 1 addition & 1 deletion core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool

if (err != OK) {
ERR_EXPLAIN("Error loading resource: '" + p_path + "'");
ERR_FAIL_COND_V(err != OK, ret);
ERR_FAIL_V(ret);
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit

OBJTYPE_WLOCK;

StringName name = p_class;
const StringName &name = p_class;

ERR_FAIL_COND(classes.has(name));

Expand Down
2 changes: 1 addition & 1 deletion core/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct Color {
static Color named(const String &p_name);
String to_html(bool p_alpha = true) const;
Color from_hsv(float p_h, float p_s, float p_v, float p_a) const;
static Color from_rgbe9995(uint32_t p_color);
static Color from_rgbe9995(uint32_t p_rgbe);

_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
operator String() const;
Expand Down
36 changes: 18 additions & 18 deletions core/error_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ extern bool _err_error_exists;
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
} while (0); // (*)

/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
Expand All @@ -150,8 +150,8 @@ extern bool _err_error_exists;
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
} while (0); // (*)

/** An index has failed if m_index >=m_size, the function exits.
Expand All @@ -164,8 +164,8 @@ extern bool _err_error_exists;
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
} while (0); // (*)

/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
Expand All @@ -188,17 +188,17 @@ extern bool _err_error_exists;
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

#define ERR_FAIL_NULL_V(m_param, m_retval) \
{ \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return m_retval; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
Expand All @@ -210,8 +210,8 @@ extern bool _err_error_exists;
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
return; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
Expand All @@ -236,8 +236,8 @@ extern bool _err_error_exists;
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
return m_retval; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
Expand All @@ -249,8 +249,8 @@ extern bool _err_error_exists;
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
continue; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
Expand All @@ -262,8 +262,8 @@ extern bool _err_error_exists;
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
break; \
} else \
_err_error_exists = false; \
} \
_err_error_exists = false; \
}

/** Print an error string and return
Expand Down
4 changes: 2 additions & 2 deletions core/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ Color Image::get_pixel(int p_x, int p_y) const {
#ifdef DEBUG_ENABLED
if (!ptr) {
ERR_EXPLAIN("Image must be locked with 'lock()' before using get_pixel()");
ERR_FAIL_COND_V(!ptr, Color());
ERR_FAIL_V(Color());
}

ERR_FAIL_INDEX_V(p_x, width, Color());
Expand Down Expand Up @@ -2541,7 +2541,7 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
#ifdef DEBUG_ENABLED
if (!ptr) {
ERR_EXPLAIN("Image must be locked with 'lock()' before using set_pixel()");
ERR_FAIL_COND(!ptr);
ERR_FAIL();
}

ERR_FAIL_INDEX(p_x, width);
Expand Down
2 changes: 1 addition & 1 deletion core/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Image : public Resource {

Color get_pixelv(const Point2 &p_src) const;
Color get_pixel(int p_x, int p_y) const;
void set_pixelv(const Point2 &p_dest, const Color &p_color);
void set_pixelv(const Point2 &p_dst, const Color &p_color);
void set_pixel(int p_x, int p_y, const Color &p_color);

void copy_internals_from(const Ref<Image> &p_image) {
Expand Down
2 changes: 1 addition & 1 deletion core/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E) {
ERR_EXPLAIN("Request for nonexistent InputMap action: " + String(p_action));
ERR_FAIL_COND_V(!E, false);
ERR_FAIL_V(false);
}

Ref<InputEventAction> input_event_action = p_event;
Expand Down
1 change: 0 additions & 1 deletion core/io/file_access_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {

_queue_page(page + j);
}
buff = pages.write[page].buffer.ptrw();
//queue pages
buffer_mutex->unlock();
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
get_response_headers(&rh);
Dictionary ret;
for (const List<String>::Element *E = rh.front(); E; E = E->next()) {
String s = E->get();
const String &s = E->get();
int sp = s.find(":");
if (sp == -1)
continue;
Expand Down
7 changes: 0 additions & 7 deletions core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int

if (r_len)
(*r_len) += adv;
len -= adv;
buf += adv;
}

r_variant = varray;
Expand Down Expand Up @@ -719,8 +717,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int

if (r_len)
(*r_len) += adv;
len -= adv;
buf += adv;
}

r_variant = varray;
Expand Down Expand Up @@ -758,8 +754,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int

if (r_len)
(*r_len) += adv;
len -= adv;
buf += adv;
}

r_variant = carray;
Expand Down Expand Up @@ -1092,7 +1086,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
if (!obj) {
if (buf) {
encode_uint32(0, buf);
buf += 4;
}
r_len += 4;

Expand Down
2 changes: 1 addition & 1 deletion core/io/multiplayer_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MultiplayerAPI : public Reference {
void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len);

void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount);
bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_from);
bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target);

public:
enum NetworkCommands {
Expand Down
5 changes: 1 addition & 4 deletions core/io/pck_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) {

Error PCKPacker::flush(bool p_verbose) {

if (!file) {
ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER);
return ERR_INVALID_PARAMETER;
};
ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER);

// write the index

Expand Down
4 changes: 2 additions & 2 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Error ResourceInteractiveLoaderBinary::poll() {
error = ERR_FILE_CORRUPT;
memdelete(obj); //bye
ERR_EXPLAIN(local_path + ":Resource type in resource field not a resource, type is: " + obj->get_class());
ERR_FAIL_COND_V(!r, ERR_FILE_CORRUPT);
ERR_FAIL_V(ERR_FILE_CORRUPT);
}

RES res = RES(r);
Expand Down Expand Up @@ -1694,7 +1694,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
int len = varray.size();
for (int i = 0; i < len; i++) {

Variant v = varray.get(i);
const Variant &v = varray.get(i);
_find_resources(v);
}

Expand Down
1 change: 0 additions & 1 deletion core/io/stream_peer_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ void StreamPeerTCP::_bind_methods() {
StreamPeerTCP::StreamPeerTCP() :
_sock(Ref<NetSocket>(NetSocket::create())),
status(STATUS_NONE),
peer_host(IP_Address()),
peer_port(0) {
}

Expand Down
6 changes: 1 addition & 5 deletions core/io/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ bool TCP_Server::is_connection_available() const {
return false;

Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
if (err != OK) {
return false;
}

return true;
return (err == OK);
}

Ref<StreamPeerTCP> TCP_Server::take_connection() {
Expand Down
2 changes: 1 addition & 1 deletion core/math/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ Expression::ENode *Expression::_parse_expression() {
if (next_op == -1) {

_set_error("Yet another parser bug....");
ERR_FAIL_COND_V(next_op == -1, NULL);
ERR_FAIL_V(NULL);
}

// OK! create operator..
Expand Down
3 changes: 1 addition & 2 deletions core/math/random_number_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

#include "random_number_generator.h"

RandomNumberGenerator::RandomNumberGenerator() :
randbase() {}
RandomNumberGenerator::RandomNumberGenerator() {}

void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &RandomNumberGenerator::set_seed);
Expand Down
2 changes: 1 addition & 1 deletion core/math/triangle_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class TriangleMesh : public Reference {

PoolVector<Triangle> get_triangles() const { return triangles; }
PoolVector<Vector3> get_vertices() const { return vertices; }
void get_indices(PoolVector<int> *p_triangles_indices) const;
void get_indices(PoolVector<int> *r_triangles_indices) const;

void create(const PoolVector<Vector3> &p_faces);
TriangleMesh();
Expand Down
10 changes: 5 additions & 5 deletions core/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ NodePath::NodePath(const String &p_path) {
String path = p_path;
Vector<StringName> subpath;

int absolute = (path[0] == '/') ? 1 : 0;
bool absolute = (path[0] == '/');
bool last_is_slash = true;
bool has_slashes = false;
int slices = 0;
Expand Down Expand Up @@ -387,7 +387,7 @@ NodePath::NodePath(const String &p_path) {
path = path.substr(0, subpath_pos);
}

for (int i = absolute; i < path.length(); i++) {
for (int i = (int)absolute; i < path.length(); i++) {

if (path[i] == '/') {

Expand All @@ -407,7 +407,7 @@ NodePath::NodePath(const String &p_path) {

data = memnew(Data);
data->refcount.init();
data->absolute = absolute ? true : false;
data->absolute = absolute;
data->has_slashes = has_slashes;
data->subpath = subpath;
data->hash_cache_valid = false;
Expand All @@ -416,10 +416,10 @@ NodePath::NodePath(const String &p_path) {
return;
data->path.resize(slices);
last_is_slash = true;
int from = absolute;
int from = (int)absolute;
int slice = 0;

for (int i = absolute; i < path.length() + 1; i++) {
for (int i = (int)absolute; i < path.length() + 1; i++) {

if (path[i] == '/' || path[i] == 0) {

Expand Down
13 changes: 4 additions & 9 deletions core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid

if (r_valid)
*r_valid = false;
return;
}

Variant Object::get(const StringName &p_name, bool *r_valid) const {
Expand Down Expand Up @@ -810,11 +809,7 @@ bool Object::has_method(const StringName &p_method) const {

MethodBind *method = ClassDB::get_method(get_class_name(), p_method);

if (method) {
return true;
}

return false;
return method != NULL;
}

Variant Object::getvar(const Variant &p_key, bool *r_valid) const {
Expand Down Expand Up @@ -1485,7 +1480,7 @@ Error Object::connect(const StringName &p_signal, Object *p_to_object, const Str
return OK;
} else {
ERR_EXPLAIN("Signal '" + p_signal + "' is already connected to given method '" + p_to_method + "' in that object.");
ERR_FAIL_COND_V(s->slot_map.has(target), ERR_INVALID_PARAMETER);
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}
}

Expand Down Expand Up @@ -1542,11 +1537,11 @@ void Object::_disconnect(const StringName &p_signal, Object *p_to_object, const
Signal *s = signal_map.getptr(p_signal);
if (!s) {
ERR_EXPLAIN("Nonexistent signal: " + p_signal);
ERR_FAIL_COND(!s);
ERR_FAIL();
}
if (s->lock > 0) {
ERR_EXPLAIN("Attempt to disconnect signal '" + p_signal + "' while emitting (locks: " + itos(s->lock) + ")");
ERR_FAIL_COND(s->lock > 0);
ERR_FAIL();
}

Signal::Target target(p_to_object->get_instance_id(), p_to_method);
Expand Down
2 changes: 1 addition & 1 deletion core/os/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag
if (current_is_dir())
dirs.push_back(n);
else {
String rel_path = n;
const String &rel_path = n;
if (!n.is_rel_path()) {
list_dir_end();
return ERR_BUG;
Expand Down
Loading

0 comments on commit 4e5310c

Please sign in to comment.