[coco] Refine Bag::deps method interface (#1444)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 06:41:39 +0000 (15:41 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 06:41:39 +0000 (15:41 +0900)
This commit refines Bag::deps method to return the set of Deps links
that points on the current bag.

Note that this commit does not change the semantics non-member 'dependent_objects'
helper, so one may use 'dependent_objects' helper instead of 'deps'
method for compatiblity.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h
contrib/coco/core/include/coco/IR/Dep.forward.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/DepSet.h
contrib/coco/core/src/IR/Bag.cpp
contrib/coco/core/src/IR/Dep.test.cpp
contrib/coco/core/src/IR/Object.test.cpp

index bc2f0e5..98092ad 100644 (file)
@@ -4,6 +4,7 @@
 #include "coco/IR/BagInfo.forward.h"
 
 #include "coco/IR/ObjectSet.h"
+#include "coco/IR/DepSet.h"
 #include "coco/IR/Locatable.h"
 
 #include <set>
@@ -55,9 +56,8 @@ public:
   bool isOutput(void) const;
 
 public:
-  // WARN This method will be deprecated. Please use below "dependent_objects" instead
-  // @brief Return the set of objects that depends on this bag
-  ObjectSet deps(void) const;
+  // @brief Return the set of Dep links that point to this bag
+  const DepSet *deps(void) const;
   // WARN This method will be deprecated. Please below "readers" instead
   ReaderSet reads(void) const;
   // WARN This method will be dpercated. Please use below "updaters" instead
diff --git a/contrib/coco/core/include/coco/IR/Dep.forward.h b/contrib/coco/core/include/coco/IR/Dep.forward.h
new file mode 100644 (file)
index 0000000..03b2951
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __COCO_IR_DEP_FORWARD_H__
+#define __COCO_IR_DEP_FORWARD_H__
+
+namespace coco
+{
+
+class Dep;
+
+} // namespace coco
+
+#endif // __COCO_IR_DEP_FORWARD_H__
index 3b27c95..fcc2aa9 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __COCO_IR_DEP_SET_H__
 #define __COCO_IR_DEP_SET_H__
 
-#include "coco/IR/Dep.h"
+#include "coco/IR/Dep.forward.h"
 
 #include <set>
 
index 41311b8..1876213 100644 (file)
@@ -23,26 +23,13 @@ uint32_t Bag::size(void) const { return _info->size(); }
 bool Bag::isInput(void) const { return _info->mask()->masked(BagMask::Input); }
 bool Bag::isOutput(void) const { return _info->mask()->masked(BagMask::Output); }
 
-ObjectSet Bag::deps(void) const
-{
-  ObjectSet res;
-
-  for (const auto &dep : *(_info->deps()))
-  {
-    if (auto obj = dep->object())
-    {
-      res.insert(obj);
-    }
-  }
-
-  return res;
-}
+const DepSet *Bag::deps(void) const { return _info->deps(); }
 
 Bag::ReaderSet Bag::reads(void) const
 {
   Bag::ReaderSet res;
 
-  for (auto obj : deps())
+  for (auto obj : dependent_objects(this))
   {
     for (auto use : *obj->user())
     {
@@ -64,7 +51,7 @@ Bag::UpdaterSet Bag::updates(void) const
 {
   Bag::UpdaterSet res;
 
-  for (auto obj : deps())
+  for (auto obj : dependent_objects(this))
   {
     if (obj->def())
     {
@@ -82,7 +69,21 @@ Bag::UpdaterSet Bag::updates(void) const
   return res;
 }
 
-ObjectSet dependent_objects(const Bag *b) { return b->deps(); }
+ObjectSet dependent_objects(const Bag *b)
+{
+  ObjectSet res;
+
+  for (const auto &dep : *(b->deps()))
+  {
+    if (auto obj = dep->object())
+    {
+      res.insert(obj);
+    }
+  }
+
+  return res;
+}
+
 Bag::ReaderSet readers(const Bag *b) { return b->reads(); }
 Bag::UpdaterSet updaters(const Bag *b) { return b->updates(); }
 
index 083b032..87c93eb 100644 (file)
@@ -56,7 +56,7 @@ TEST_F(DepTest, bag_update_with_link_and_object)
 
   dep.bag(bag);
 
-  auto deps = bag->deps();
+  auto deps = coco::dependent_objects(bag);
 
   ASSERT_EQ(deps.size(), 1);
   ASSERT_NE(deps.count(obj), 0);
index 0411ddc..dad3828 100644 (file)
@@ -76,7 +76,7 @@ TEST_F(ObjectTest, bag_update)
 
   // User SHOULD be able to access dependent objects through 'bag'
   {
-    auto deps = bag->deps();
+    auto deps = coco::dependent_objects(bag);
     ASSERT_EQ(deps.size(), 1);
     ASSERT_EQ(deps.count(&obj), 1);
   }
@@ -87,7 +87,7 @@ TEST_F(ObjectTest, bag_update)
   ASSERT_EQ(obj.bag(), nullptr);
 
   {
-    auto deps = bag->deps();
+    auto deps = coco::dependent_objects(bag);
     ASSERT_EQ(deps.size(), 0);
   }
 }
@@ -108,7 +108,7 @@ TEST_F(ObjectTest, destructor)
 
   // Object SHOULD be unlinked from Bag on destruction
   {
-    auto deps = bag->deps();
+    auto deps = coco::dependent_objects(bag);
     ASSERT_EQ(deps.size(), 0);
   }
 }