Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sonar fixes
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Feb 2022 11:15:01 +0000 (12:15 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Feb 2022 11:26:28 +0000 (12:26 +0100)
- Pass the constructor parameters to the ancestor (!)
- Make some stuff const
- don't overuse initializer list of constructors for stuff that can be
  initialized in the class
- Kill dead code
- 'auto' instead of redundent type
- true/false instead of 1/0
- Also inline a useless function

src/kernel/activity/MailboxImpl.hpp
src/mc/api.cpp
src/mc/api/TransitionComm.cpp
src/mc/checker/CommunicationDeterminismChecker.cpp
src/mc/mc_base.cpp

index e82979e..33fd74b 100644 (file)
@@ -37,12 +37,12 @@ class MailboxImpl {
   friend mc::CommunicationDeterminismChecker;
 
   static unsigned next_id_; // Next ID to be given
-  unsigned id_;
-  explicit MailboxImpl(const std::string& name) : piface_(this), name_(name), id_(next_id_++) {}
+  const unsigned id_ = next_id_++;
+  explicit MailboxImpl(const std::string& name) : piface_(this), name_(name) {}
 
 public:
   /** @brief Public interface */
-  unsigned get_id() { return id_; }
+  unsigned get_id() const { return id_; }
 
   const s4u::Mailbox* get_iface() const { return &piface_; }
   s4u::Mailbox* get_iface() { return &piface_; }
index 09764e4..a888c11 100644 (file)
@@ -34,24 +34,6 @@ using Simcall = simgrid::simix::Simcall;
 namespace simgrid {
 namespace mc {
 
-static inline const char* get_color(int id)
-{
-  static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
-                                                       "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
-                                                       "lightblue", "tan"}};
-  return colors[id % colors.size()];
-}
-
-static std::string pointer_to_string(void* pointer)
-{
-  return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? xbt::string_printf("%p", pointer) : "(verbose only)";
-}
-
-static std::string buff_size_to_string(size_t buff_size)
-{
-  return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? std::to_string(buff_size) : "(verbose only)";
-}
-
 /** Statically "upcast" a s_smx_actor_t into an ActorInformation
  *
  *  This gets 'actorInfo' from '&actorInfo->copy'. It upcasts in the
@@ -353,7 +335,11 @@ void Api::mc_exit(int status) const
 
 std::string Api::request_get_dot_output(const Transition* t) const
 {
-  const char* color = get_color(t->aid_ - 1);
+  static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
+                                                       "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
+                                                       "lightblue", "tan"}};
+  const char* color = colors[(t->aid_ - 1) % colors.size()];
+
   return "label = \"" + t->dot_label() + "\", color = " + color + ", fontcolor = " + color;
 }
 
index 21a827c..28962de 100644 (file)
@@ -177,6 +177,7 @@ std::string CommSendTransition::to_string(bool verbose = false) const
   return res;
 }
 TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
+    : Transition(Type::TESTANY, issuer, times_considered)
 {
   int size;
   stream >> size;
@@ -242,7 +243,7 @@ Transition* recv_transition(aid_t issuer, int times_considered, std::stringstrea
   xbt_assert(type >= 0 && type <= static_cast<short>(Transition::Type::UNKNOWN), "Invalid transition type %d received",
              type);
 
-  Transition::Type simcall = static_cast<Transition::Type>(type);
+  auto simcall = static_cast<Transition::Type>(type);
 
   switch (simcall) {
     case Transition::Type::COMM_RECV:
index 249d869..91f9f4a 100644 (file)
@@ -365,7 +365,7 @@ void CommunicationDeterminismChecker::restoreState()
     /* TODO : handle test and testany simcalls */
     CallType call = MC_get_call_type(req);
     state->get_transition()->replay();
-    handle_comm_pattern(call, req, req_num, 1);
+    handle_comm_pattern(call, req, req_num, true);
 
     /* Update statistics */
     api::get().mc_inc_visited_states();
@@ -434,7 +434,7 @@ void CommunicationDeterminismChecker::real_run()
       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
         call = MC_get_call_type(req);
 
-      handle_comm_pattern(call, req, req_num, 0);
+      handle_comm_pattern(call, req, req_num, false);
 
       /* Create the new expanded state */
       auto next_state = std::make_unique<State>();
index 236aab7..1388a23 100644 (file)
@@ -58,7 +58,7 @@ void execute_actors()
   engine->reset_actor_dynar();
   for (auto const& kv : engine->get_actor_list()) {
     auto actor = kv.second;
-    if (auto* observer = actor->simcall_.observer_)
+    if (const auto* observer = actor->simcall_.observer_)
       actor->simcall_.mc_max_consider_ = observer->get_max_consider();
     engine->add_actor_to_dynar(actor);
   }