Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce code dupplication to please sonar
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 14 Feb 2022 19:15:35 +0000 (20:15 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 14 Feb 2022 19:15:35 +0000 (20:15 +0100)
src/mc/api/Transition.hpp
src/mc/api/TransitionComm.cpp

index 3273f13..8b37b05 100644 (file)
@@ -32,7 +32,8 @@ class Transition {
   friend State; // FIXME remove this once we have a proper class to handle the statistics
 
 public:
-  XBT_DECLARE_ENUM_CLASS(Type, RANDOM, COMM_RECV, COMM_SEND, COMM_TEST, COMM_WAIT, TESTANY, WAITANY,
+  /* Ordering is important here. depends() implementations only consider subsequent types in this ordering */
+  XBT_DECLARE_ENUM_CLASS(Type, RANDOM, TESTANY, WAITANY, COMM_RECV, COMM_SEND, COMM_TEST, COMM_WAIT,
                          /* UNKNOWN must be last */ UNKNOWN);
   Type type_ = Type::UNKNOWN;
 
index 35eadf0..eb2bd22 100644 (file)
@@ -43,22 +43,8 @@ bool CommWaitTransition::depends(const Transition* other) const
   if (aid_ == other->aid_)
     return false;
 
-  if (dynamic_cast<const RandomTransition*>(other) != nullptr)
-    return false; // Random is indep with any transition
-
-  if (auto* any = dynamic_cast<const WaitAnyTransition*>(other))
-    return any->depends(this);
-  if (auto* any = dynamic_cast<const TestAnyTransition*>(other))
-    return any->depends(this);
-
-  if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
-    return recv->depends(this);
-
-  if (auto* send = dynamic_cast<const CommSendTransition*>(other))
-    return send->depends(this);
-
-  if (auto* test = dynamic_cast<const CommTestTransition*>(other))
-    return test->depends(this);
+  if (other->type_ < type_)
+    return other->depends(this);
 
   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
     if (timeout_ || wait->timeout_)
@@ -95,19 +81,8 @@ bool CommTestTransition::depends(const Transition* other) const
   if (aid_ == other->aid_)
     return false;
 
-  if (dynamic_cast<const RandomTransition*>(other) != nullptr)
-    return false; // Test & Random are independent (Random is independent with anything)
-
-  if (auto* any = dynamic_cast<const WaitAnyTransition*>(other))
-    return any->depends(this);
-  if (auto* any = dynamic_cast<const TestAnyTransition*>(other))
-    return any->depends(this);
-
-  if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
-    return recv->depends(this); // Recv < Test (alphabetical ordering)
-
-  if (auto* send = dynamic_cast<const CommSendTransition*>(other))
-    return send->depends(this); // Send < Test (alphabetical ordering)
+  if (other->type_ < type_)
+    return other->depends(this);
 
   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
     return false; // Test & Test are independent
@@ -141,12 +116,8 @@ bool CommRecvTransition::depends(const Transition* other) const
   if (aid_ == other->aid_)
     return false;
 
-  if (dynamic_cast<const RandomTransition*>(other) != nullptr)
-    return false; // Random is indep with any transition
-  if (auto* any = dynamic_cast<const WaitAnyTransition*>(other))
-    return any->depends(this);
-  if (auto* any = dynamic_cast<const TestAnyTransition*>(other))
-    return any->depends(this);
+  if (other->type_ < type_)
+    return other->depends(this);
 
   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
     return mbox_ == recv->mbox_;
@@ -242,13 +213,8 @@ bool CommSendTransition::depends(const Transition* other) const
   if (aid_ == other->aid_)
     return false;
 
-  if (dynamic_cast<const RandomTransition*>(other) != nullptr)
-    return false; // Random is indep with any transition
-
-  if (auto* any = dynamic_cast<const WaitAnyTransition*>(other))
-    return any->depends(this);
-  if (auto* any = dynamic_cast<const TestAnyTransition*>(other))
-    return any->depends(this);
+  if (other->type_ < type_)
+    return other->depends(this);
 
   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
     return mbox_ == other_isend->mbox_;