[coco] Allow Def to access the internals of Object (#1515)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 04:25:09 +0000 (13:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 04:25:09 +0000 (13:25 +0900)
This commit declares Def as a friend of Object class, which allows Def
to access Object's internal fields.

This change allows us to simplify the implementation of Def.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Def.h
contrib/coco/core/include/coco/IR/Object.h
contrib/coco/core/src/IR/Def.cpp

index cdb3982..2febd16 100644 (file)
@@ -12,8 +12,9 @@ namespace coco
 class Def final
 {
 public:
-  Def(const PtrLink<Object, ObjectInfo> *link, Object::Producer *producer)
-      : _link{link}, _producer{producer}
+  // NOTE Object-to-ObjectInfo link is no longer used
+  // TODO Simplify Def's constructor
+  Def(const PtrLink<Object, ObjectInfo> *, Object::Producer *producer) : _producer{producer}
   {
     // DO NOTHING
   }
@@ -31,9 +32,6 @@ public:
   Object::Producer *producer(void) const { return _producer; }
 
 private:
-  const PtrLink<Object, ObjectInfo> *_link = nullptr;
-
-private:
   Object *_value = nullptr;
   Object::Producer *_producer = nullptr;
 };
index 61b98db..60bfd6f 100644 (file)
@@ -21,6 +21,9 @@ namespace coco
 class Object
 {
 public:
+  friend class Def;
+
+public:
   struct Producer : public Bag::Updater
   {
     virtual ~Producer() = default;
index 9b3d16a..b93ffca 100644 (file)
@@ -8,11 +8,9 @@ namespace coco
 
 void Def::value(Object *value)
 {
-  assert(_link != nullptr);
-
   if (_value)
   {
-    auto info = _link->find(_value);
+    auto info = _value->info();
     assert(info != nullptr);
     info->def(nullptr);
 
@@ -25,7 +23,7 @@ void Def::value(Object *value)
   {
     _value = value;
 
-    auto info = _link->find(_value);
+    auto info = _value->info();
     assert(info != nullptr);
     info->def(this);
   }