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
This commit is contained in:
Rémi Verschelde
2020-05-14 16:41:43 +02:00
parent 07bc4e2f96
commit 0ee0fa42e6
683 changed files with 22803 additions and 12225 deletions

View File

@ -228,8 +228,9 @@ Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) {
int len = 0;
Error err = encode_variant(var, nullptr, len, true);
if (err != OK)
if (err != OK) {
ERR_PRINT("Failed to encode variant.");
}
if (len > max_size) {
arr.push_back(Variant());

View File

@ -111,8 +111,9 @@ Error EngineDebugger::capture_parse(const StringName &p_name, const String &p_ms
void EngineDebugger::line_poll() {
// The purpose of this is just processing events every now and then when the script might get too busy otherwise bugs like infinite loops can't be caught
if (poll_every % 2048 == 0)
if (poll_every % 2048 == 0) {
poll_events(false);
}
poll_every++;
}
@ -124,8 +125,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
// Notify tick to running profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
Profiler &p = E->get();
if (!p.active || !p.tick)
if (!p.active || !p.tick) {
continue;
}
p.tick(p.data, frame_time, idle_time, physics_time, physics_frame_time);
}
singleton->poll_events(true);
@ -133,8 +135,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints) {
register_uri_handler("tcp://", RemoteDebuggerPeerTCP::create); // TCP is the default protocol. Platforms/modules can add more.
if (p_uri.empty())
if (p_uri.empty()) {
return;
}
if (p_uri == "local://") {
singleton = memnew(LocalDebugger);
script_debugger = memnew(ScriptDebugger);
@ -142,11 +145,13 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
OS::get_singleton()->initialize_debugging();
} else if (p_uri.find("://") >= 0) {
const String proto = p_uri.substr(0, p_uri.find("://") + 3);
if (!protocols.has(proto))
if (!protocols.has(proto)) {
return;
}
RemoteDebuggerPeer *peer = protocols[proto](p_uri);
if (!peer)
if (!peer) {
return;
}
singleton = memnew(RemoteDebugger(Ref<RemoteDebuggerPeer>(peer)));
script_debugger = memnew(ScriptDebugger);
// Notify editor of our pid (to allow focus stealing).
@ -154,8 +159,9 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
msg.push_back(OS::get_singleton()->get_process_id());
singleton->send_message("set_pid", msg);
}
if (!singleton)
if (!singleton) {
return;
}
// There is a debugger, parse breakpoints.
ScriptDebugger *singleton_script_debugger = singleton->get_script_debugger();
@ -174,8 +180,9 @@ void EngineDebugger::deinitialize() {
if (singleton) {
// Stop all profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
if (E->get().active)
if (E->get().active) {
singleton->profiler_enable(E->key(), false);
}
}
// Flush any remaining message
@ -192,8 +199,9 @@ void EngineDebugger::deinitialize() {
}
EngineDebugger::~EngineDebugger() {
if (script_debugger)
if (script_debugger) {
memdelete(script_debugger);
}
script_debugger = nullptr;
singleton = nullptr;
}

View File

@ -69,17 +69,19 @@ struct LocalDebugger::ScriptsProfiler {
void _print_frame_data(bool p_accumulated) {
uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum;
if (!p_accumulated && diff < 1000000) //show every one second
if (!p_accumulated && diff < 1000000) { //show every one second
return;
}
idle_accum = OS::get_singleton()->get_ticks_usec();
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
if (p_accumulated)
if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs);
else
} else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs);
}
}
SortArray<ScriptLanguage::ProfilingInfo, ProfileInfoSort> sort;
@ -141,9 +143,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'");
print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'");
print_line("Enter \"help\" for assistance.");
} else if (line == "c" || line == "continue")
} else if (line == "c" || line == "continue") {
break;
else if (line == "bt" || line == "breakpoint") {
} else if (line == "bt" || line == "breakpoint") {
for (int i = 0; i < total_frames; i++) {
String cfi = (current_frame == i) ? "*" : " "; //current frame indicator
print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'");
@ -257,8 +259,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
String source = breakpoint.first;
int linenr = breakpoint.second;
if (source.empty())
if (source.empty()) {
continue;
}
script_debugger->insert_breakpoint(linenr, source);
@ -282,8 +285,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
String source = breakpoint.first;
int linenr = breakpoint.second;
if (source.empty())
if (source.empty()) {
continue;
}
script_debugger->remove_breakpoint(linenr, source);
@ -377,6 +381,7 @@ LocalDebugger::LocalDebugger() {
LocalDebugger::~LocalDebugger() {
unregister_profiler("scripts");
if (scripts_profiler)
if (scripts_profiler) {
memdelete(scripts_profiler);
}
}

View File

@ -96,8 +96,9 @@ public:
}
void init_node(const ObjectID p_node) {
if (multiplayer_node_data.has(p_node))
if (multiplayer_node_data.has(p_node)) {
return;
}
multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo());
multiplayer_node_data[p_node].node = p_node;
multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path();
@ -218,10 +219,11 @@ struct RemoteDebugger::ScriptsProfiler {
void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) {
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
if (p_accumulated)
if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs);
else
} else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs);
}
}
for (int i = 0; i < ofs; i++) {
@ -358,8 +360,9 @@ struct RemoteDebugger::VisualProfiler {
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile();
DebuggerMarshalls::VisualProfilerFrame frame;
if (!profile_areas.size())
if (!profile_areas.size()) {
return;
}
frame.frame_number = RS::get_singleton()->get_frame_profile_frame();
frame.areas.append_array(profile_areas);
@ -374,12 +377,14 @@ struct RemoteDebugger::PerformanceProfiler {
void toggle(bool p_enable, const Array &p_opts) {}
void add(const Array &p_data) {}
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
if (!performance)
if (!performance) {
return;
}
uint64_t pt = OS::get_singleton()->get_ticks_msec();
if (pt - last_perf_time < 1000)
if (pt - last_perf_time < 1000) {
return;
}
last_perf_time = pt;
int max = performance->get("MONITOR_MAX");
Array arr;
@ -423,25 +428,29 @@ Error RemoteDebugger::_put_msg(String p_message, Array p_data) {
msg.push_back(p_message);
msg.push_back(p_data);
Error err = peer->put_message(msg);
if (err != OK)
if (err != OK) {
n_messages_dropped++;
}
return err;
}
void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
if (p_type == ERR_HANDLER_SCRIPT)
if (p_type == ERR_HANDLER_SCRIPT) {
return; //ignore script errors, those go through debugger
}
RemoteDebugger *rd = (RemoteDebugger *)p_this;
if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive errors during flush.
if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive errors during flush.
return;
}
Vector<ScriptLanguage::StackInfo> si;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
si = ScriptServer::get_language(i)->debug_get_current_stack_info();
if (si.size())
if (si.size()) {
break;
}
}
// send_error will lock internally.
@ -451,14 +460,16 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *
void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) {
RemoteDebugger *rd = (RemoteDebugger *)p_this;
if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush.
if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive prints during flush.
return;
}
String s = p_string;
int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length());
if (allowed_chars == 0 && s.length() > 0)
if (allowed_chars == 0 && s.length() > 0) {
return;
}
if (allowed_chars < s.length()) {
s = s.substr(0, allowed_chars);
@ -469,8 +480,9 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p
rd->char_count += allowed_chars;
bool overflowed = rd->char_count >= rd->max_chars_per_second;
if (rd->is_peer_connected()) {
if (overflowed)
if (overflowed) {
s += "[...]";
}
OutputString output_string;
output_string.message = s;
@ -502,13 +514,15 @@ void RemoteDebugger::flush_output() {
flush_thread = Thread::get_caller_id();
flushing = true;
MutexLock lock(mutex);
if (!is_peer_connected())
if (!is_peer_connected()) {
return;
}
if (n_messages_dropped > 0) {
ErrorMessage err_msg = _create_overflow_error("TOO_MANY_MESSAGES", "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped. Profiling might misbheave, try raising 'network/limits/debugger/max_queued_messages' in project setting.");
if (_put_msg("error", err_msg.serialize()) == OK)
if (_put_msg("error", err_msg.serialize()) == OK) {
n_messages_dropped = 0;
}
}
if (output_strings.size()) {
@ -585,8 +599,9 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int
oe.msec = time % 1000;
oe.callstack.append_array(script_debugger->get_error_stack_info());
if (flushing && Thread::get_caller_id() == flush_thread) // Can't handle recursive errors during flush.
if (flushing && Thread::get_caller_id() == flush_thread) { // Can't handle recursive errors during flush.
return;
}
MutexLock lock(mutex);
@ -644,8 +659,9 @@ Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, boo
return OK;
}
const String cap = p_msg.substr(0, idx);
if (!has_capture(cap))
if (!has_capture(cap)) {
return ERR_UNAVAILABLE; // Unknown message...
}
const String msg = p_msg.substr(idx + 1);
return capture_parse(cap, msg, p_data, r_captured);
}
@ -654,13 +670,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
//this function is called when there is a debugger break (bug on script)
//or when execution is paused from editor
if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint)
if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) {
return;
}
ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway.");
if (!peer->can_block())
if (!peer->can_block()) {
return; // Peer does not support blocking IO. We could at least send the error though.
}
ScriptLanguage *script_lang = script_debugger->get_break_language();
const String error_str = script_lang ? script_lang->debug_get_error() : "";
@ -672,8 +690,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug.
Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
}
uint64_t loop_begin_usec = 0;
uint64_t loop_time_sec = 0;
@ -761,10 +780,11 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else if (command == "breakpoint") {
ERR_FAIL_COND(data.size() < 3);
bool set = data[2];
if (set)
if (set) {
script_debugger->insert_breakpoint(data[1], data[0]);
else
} else {
script_debugger->remove_breakpoint(data[1], data[0]);
}
} else if (command == "set_skip_breakpoints") {
ERR_FAIL_COND(data.size() < 1);
@ -772,8 +792,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else {
bool captured = false;
ERR_CONTINUE(_try_capture(command, data, captured) != OK);
if (!captured)
if (!captured) {
WARN_PRINT("Unknown message received from debugger: " + command);
}
}
} else {
OS::get_singleton()->delay_usec(10000);
@ -790,13 +811,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
send_message("debug_exit", Array());
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(mouse_mode);
}
}
void RemoteDebugger::poll_events(bool p_is_idle) {
if (peer.is_null())
if (peer.is_null()) {
return;
}
flush_output();
peer->poll();
@ -816,8 +839,9 @@ void RemoteDebugger::poll_events(bool p_is_idle) {
}
const String cap = cmd.substr(0, idx);
if (!has_capture(cap))
if (!has_capture(cap)) {
continue; // Unknown message...
}
const String msg = cmd.substr(idx + 1);
capture_parse(cap, msg, arr[1], parsed);
@ -840,10 +864,11 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo
} else if (p_cmd == "breakpoint") {
ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA);
bool set = p_data[2];
if (set)
if (set) {
script_debugger->insert_breakpoint(p_data[1], p_data[0]);
else
} else {
script_debugger->remove_breakpoint(p_data[1], p_data[0]);
}
} else if (p_cmd == "set_skip_breakpoints") {
ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA);
@ -934,6 +959,7 @@ RemoteDebugger::~RemoteDebugger() {
memdelete(servers_profiler);
memdelete(network_profiler);
memdelete(visual_profiler);
if (performance_profiler)
if (performance_profiler) {
memdelete(performance_profiler);
}
}

View File

@ -52,8 +52,9 @@ Array RemoteDebuggerPeerTCP::get_message() {
Error RemoteDebuggerPeerTCP::put_message(const Array &p_arr) {
MutexLock lock(mutex);
if (out_queue.size() >= max_queued_messages)
if (out_queue.size() >= max_queued_messages) {
return ERR_OUT_OF_MEMORY;
}
out_queue.push_back(p_arr);
return OK;
@ -99,8 +100,9 @@ void RemoteDebuggerPeerTCP::_write_out() {
while (tcp_client->poll(NetSocket::POLL_TYPE_OUT) == OK) {
uint8_t *buf = out_buf.ptrw();
if (out_left <= 0) {
if (out_queue.size() == 0)
if (out_queue.size() == 0) {
break; // Nothing left to send
}
mutex.lock();
Variant var = out_queue[0];
out_queue.pop_front();
@ -155,10 +157,11 @@ void RemoteDebuggerPeerTCP::_read_in() {
Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) {
IP_Address ip;
if (p_host.is_valid_ip_address())
if (p_host.is_valid_ip_address()) {
ip = p_host;
else
} else {
ip = IP::get_singleton()->resolve_hostname(p_host);
}
int port = p_port;
@ -194,8 +197,9 @@ void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) {
RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud;
while (peer->running && peer->is_peer_connected()) {
peer->_poll();
if (!peer->is_peer_connected())
if (!peer->is_peer_connected()) {
break;
}
peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1);
}
}

View File

@ -49,23 +49,27 @@ int ScriptDebugger::get_depth() const {
}
void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
if (!breakpoints.has(p_line))
if (!breakpoints.has(p_line)) {
breakpoints[p_line] = Set<StringName>();
}
breakpoints[p_line].insert(p_source);
}
void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) {
if (!breakpoints.has(p_line))
if (!breakpoints.has(p_line)) {
return;
}
breakpoints[p_line].erase(p_source);
if (breakpoints[p_line].size() == 0)
if (breakpoints[p_line].size() == 0) {
breakpoints.erase(p_line);
}
}
bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
if (!breakpoints.has(p_line))
if (!breakpoints.has(p_line)) {
return false;
}
return breakpoints[p_line].has(p_source);
}