From ef00a3480208e92909f444e490c5ca3559eff5aa Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 28 Oct 2017 18:19:14 +0200 Subject: [PATCH 1/1] Sonar: remove nested blocks. --- src/mc/DwarfExpression.cpp | 44 ++++++------ src/mc/mc_request.cpp | 6 +- src/surf/xml/surfxml_parseplatf.cpp | 100 ++++++++++++++-------------- 3 files changed, 72 insertions(+), 78 deletions(-) diff --git a/src/mc/DwarfExpression.cpp b/src/mc/DwarfExpression.cpp index b20366d122..696d262f8b 100644 --- a/src/mc/DwarfExpression.cpp +++ b/src/mc/DwarfExpression.cpp @@ -31,6 +31,8 @@ void execute( for (size_t i = 0; i != n; ++i) { const Dwarf_Op *op = ops + i; std::uint8_t atom = op->atom; + intptr_t first; + intptr_t second; switch (atom) { @@ -204,19 +206,17 @@ void execute( // and replace the top of the stack with the computed value // (stack.top() += stack.before_top()). - case DW_OP_plus: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_plus: + first = stack.pop(); + second = stack.pop(); stack.push(first + second); break; - } - case DW_OP_mul: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_mul: + first = stack.pop(); + second = stack.pop(); stack.push(first * second); break; - } case DW_OP_plus_uconst: stack.top() += op->number; @@ -230,33 +230,29 @@ void execute( stack.top() = - (intptr_t) stack.top(); break; - case DW_OP_minus: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_minus: + first = stack.pop(); + second = stack.pop(); stack.push(second - first); break; - } - case DW_OP_and: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_and: + first = stack.pop(); + second = stack.pop(); stack.push(first & second); break; - } - case DW_OP_or: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_or: + first = stack.pop(); + second = stack.pop(); stack.push(first | second); break; - } - case DW_OP_xor: { - intptr_t first = stack.pop(); - intptr_t second = stack.pop(); + case DW_OP_xor: + first = stack.pop(); + second = stack.pop(); stack.push(first ^ second); break; - } case DW_OP_nop: break; diff --git a/src/mc/mc_request.cpp b/src/mc/mc_request.cpp index 42d5c79432..6a800b7934 100644 --- a/src/mc/mc_request.cpp +++ b/src/mc/mc_request.cpp @@ -407,10 +407,9 @@ bool request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx) remote_act = simcall_comm_wait__getraw__comm(req); break; - case SIMCALL_COMM_WAITANY: { + case SIMCALL_COMM_WAITANY: read_element(mc_model_checker->process(), &remote_act, remote(simcall_comm_waitany__getraw__comms(req)), idx, sizeof(remote_act)); - } break; case SIMCALL_COMM_TESTANY: @@ -470,7 +469,7 @@ std::string request_get_dot_output(smx_simcall_t req, int value) label = simgrid::xbt::string_printf("[(%lu)] iRecv", issuer->pid); break; - case SIMCALL_COMM_WAIT: { + case SIMCALL_COMM_WAIT: if (value == -1) { if (issuer->host) label = simgrid::xbt::string_printf("[(%lu)%s] WaitTimeout", issuer->pid, MC_smx_actor_get_host_name(issuer)); @@ -496,7 +495,6 @@ std::string request_get_dot_output(smx_simcall_t req, int value) dst_proc ? dst_proc->pid : 0); } break; - } case SIMCALL_COMM_TEST: { simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req); diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 38e43ad2ef..d53478027e 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -102,72 +102,72 @@ void parse_platform_file(const char *file) xbt_die("Lua call failed. See Log"); } lua_close(L); + return; } - else #endif - { // Use XML parser - int parse_status; + // Use XML parser - /* init the flex parser */ - after_config_done = 0; - surf_parse_open(file); + int parse_status; - /* Do the actual parsing */ - parse_status = surf_parse(); + /* init the flex parser */ + after_config_done = 0; + surf_parse_open(file); - /* connect all traces relative to hosts */ - for (auto const& elm : trace_connect_list_host_avail) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - tmgr_trace_t trace = traces_set_list.at(elm.first); + /* Do the actual parsing */ + parse_status = surf_parse(); - simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); - xbt_assert(host, "Host %s undefined", elm.second.c_str()); - simgrid::surf::Cpu *cpu = host->pimpl_cpu; + /* connect all traces relative to hosts */ + for (auto const& elm : trace_connect_list_host_avail) { + xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); + tmgr_trace_t trace = traces_set_list.at(elm.first); - cpu->setStateTrace(trace); - } - - for (auto const& elm : trace_connect_list_host_speed) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - tmgr_trace_t trace = traces_set_list.at(elm.first); + simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); + xbt_assert(host, "Host %s undefined", elm.second.c_str()); + simgrid::surf::Cpu* cpu = host->pimpl_cpu; - simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); - xbt_assert(host, "Host %s undefined", elm.second.c_str()); - simgrid::surf::Cpu *cpu = host->pimpl_cpu; + cpu->setStateTrace(trace); + } - cpu->setSpeedTrace(trace); - } + for (auto const& elm : trace_connect_list_host_speed) { + xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); + tmgr_trace_t trace = traces_set_list.at(elm.first); - for (auto const& elm : trace_connect_list_link_avail) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - tmgr_trace_t trace = traces_set_list.at(elm.first); + simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); + xbt_assert(host, "Host %s undefined", elm.second.c_str()); + simgrid::surf::Cpu* cpu = host->pimpl_cpu; - sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); - link->setStateTrace(trace); - } + cpu->setSpeedTrace(trace); + } - for (auto const& elm : trace_connect_list_link_bw) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - tmgr_trace_t trace = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); - link->setBandwidthTrace(trace); - } + for (auto const& elm : trace_connect_list_link_avail) { + xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); + tmgr_trace_t trace = traces_set_list.at(elm.first); - for (auto const& elm : trace_connect_list_link_lat) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - tmgr_trace_t trace = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); - link->setLatencyTrace(trace); - } + sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); + xbt_assert(link, "Link %s undefined", elm.second.c_str()); + link->setStateTrace(trace); + } - surf_parse_close(); + for (auto const& elm : trace_connect_list_link_bw) { + xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); + tmgr_trace_t trace = traces_set_list.at(elm.first); + sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); + xbt_assert(link, "Link %s undefined", elm.second.c_str()); + link->setBandwidthTrace(trace); + } - if (parse_status) - surf_parse_error(std::string("Parse error in ") + file); + for (auto const& elm : trace_connect_list_link_lat) { + xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); + tmgr_trace_t trace = traces_set_list.at(elm.first); + sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str()); + xbt_assert(link, "Link %s undefined", elm.second.c_str()); + link->setLatencyTrace(trace); } + + surf_parse_close(); + + if (parse_status) + surf_parse_error(std::string("Parse error in ") + file); } } -- 2.20.1