[coco] Remove DefHook (#1483)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 13 Sep 2018 02:23:01 +0000 (11:23 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 13 Sep 2018 02:23:01 +0000 (11:23 +0900)
This commit removes DefHook and implements its functionalities directly
in DefSlot.

This change is a step to revise DefSlot similarly as Dep/Read/Update.

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

diff --git a/contrib/coco/core/include/coco/IR/DefHook.h b/contrib/coco/core/include/coco/IR/DefHook.h
deleted file mode 100644 (file)
index c544771..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef __COCO_IR_DEF_HOOK_H__
-#define __COCO_IR_DEF_HOOK_H__
-
-#include "coco/IR/Object.h"
-#include "coco/IR/ObjectInfo.forward.h"
-
-#include "coco/ADT/PtrLink.h"
-
-namespace coco
-{
-
-class DefHook final
-{
-public:
-  DefHook(const PtrLink<Object, ObjectInfo> *obj_link, Object::Producer *def)
-      : _obj_link{obj_link}, _def{def}
-  {
-    // DO NOTHING
-  }
-
-private:
-  ObjectInfo *info(Object *o) const;
-
-public:
-  void onTake(Object *o);
-  void onRelease(Object *o);
-
-private:
-  const PtrLink<Object, ObjectInfo> *const _obj_link;
-  // TODO Rename field
-  Object::Producer *const _def;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_DEF_HOOK_H__
index 7ed5bee..ec0b17b 100644 (file)
@@ -1,7 +1,10 @@
 #ifndef __COCO_IR_DEF_SLOT_H__
 #define __COCO_IR_DEF_SLOT_H__
 
-#include "coco/IR/DefHook.h"
+#include "coco/IR/Object.h"
+#include "coco/IR/ObjectInfo.forward.h"
+
+#include "coco/ADT/PtrLink.h"
 
 namespace coco
 {
@@ -9,9 +12,10 @@ namespace coco
 class DefSlot final
 {
 public:
-  DefSlot(const PtrLink<Object, ObjectInfo> *obj_link, Object::Producer *use)
-      : _hook{obj_link, use}, _value{nullptr}
+  DefSlot(const PtrLink<Object, ObjectInfo> *link, Object::Producer *producer)
+      : _link{link}, _producer{producer}
   {
+    // DO NOTHING
   }
 
 public:
@@ -21,28 +25,14 @@ public:
   Object *value(void) const { return _value; }
 
 public:
-  void value(Object *value)
-  {
-    if (_value)
-    {
-      _hook.onRelease(_value);
-      _value = nullptr;
-    }
-
-    assert(_value == nullptr);
+  void value(Object *value);
 
-    if (value)
-    {
-      _value = value;
-      _hook.onTake(_value);
-    }
-
-    assert(_value == value);
-  }
+private:
+  const PtrLink<Object, ObjectInfo> *_link = nullptr;
 
 private:
-  DefHook _hook;
-  Object *_value;
+  Object *_value = nullptr;
+  Object::Producer *_producer = nullptr;
 };
 
 } // namespace coco
diff --git a/contrib/coco/core/src/IR/DefHook.cpp b/contrib/coco/core/src/IR/DefHook.cpp
deleted file mode 100644 (file)
index b6affb9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "coco/IR/DefHook.h"
-#include "coco/IR/ObjectInfo.h"
-
-#include <cassert>
-
-namespace coco
-{
-
-ObjectInfo *DefHook::info(Object *o) const
-{
-  auto info = _obj_link->find(o);
-  assert(info != nullptr);
-  return info;
-}
-
-void DefHook::onTake(Object *o) { info(o)->def(_def); }
-void DefHook::onRelease(Object *o) { info(o)->def(nullptr); }
-
-} // namespace coco
diff --git a/contrib/coco/core/src/IR/DefHook.test.cpp b/contrib/coco/core/src/IR/DefHook.test.cpp
deleted file mode 100644 (file)
index d36837b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "coco/IR/DefHook.h"
-#include "coco/IR/ObjectInfo.h"
-#include "coco/IR/ObjectManager.h"
-
-#include "coco/IR/FeatureObject.h"
-
-#include "Def.mock.h"
-
-#include <gtest/gtest.h>
-
-namespace
-{
-class DefHookTest : public ::testing::Test
-{
-protected:
-  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-  coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
-
-  coco::ObjectManager obj_mgr{&obj_link, &bag_link};
-};
-} // namespace
-
-TEST_F(DefHookTest, TakeAndRelease)
-{
-  auto o = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 1, 1});
-
-  ::mock::Def use;
-
-  coco::DefHook hook{&obj_link, &use};
-
-  hook.onTake(o);
-  hook.onRelease(o);
-}
diff --git a/contrib/coco/core/src/IR/DefSlot.cpp b/contrib/coco/core/src/IR/DefSlot.cpp
new file mode 100644 (file)
index 0000000..203d8f4
--- /dev/null
@@ -0,0 +1,36 @@
+#include "coco/IR/DefSlot.h"
+#include "coco/IR/ObjectInfo.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+void DefSlot::value(Object *value)
+{
+  assert(_link != nullptr);
+
+  if (_value)
+  {
+    auto info = _link->find(_value);
+    assert(info != nullptr);
+    info->def(nullptr);
+
+    _value = nullptr;
+  }
+
+  assert(_value == nullptr);
+
+  if (value)
+  {
+    _value = value;
+
+    auto info = _link->find(_value);
+    assert(info != nullptr);
+    info->def(_producer);
+  }
+
+  assert(_value == value);
+}
+
+} // namespace coco