From 7fbea7ab89d6dda928c03be671f5a6d2450c2154 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 17 Sep 2018 13:25:09 +0900 Subject: [PATCH] [coco] Allow Def to access the internals of Object (#1515) 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 --- contrib/coco/core/include/coco/IR/Def.h | 8 +++----- contrib/coco/core/include/coco/IR/Object.h | 3 +++ contrib/coco/core/src/IR/Def.cpp | 6 ++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Def.h b/contrib/coco/core/include/coco/IR/Def.h index cdb3982..2febd16 100644 --- a/contrib/coco/core/include/coco/IR/Def.h +++ b/contrib/coco/core/include/coco/IR/Def.h @@ -12,8 +12,9 @@ namespace coco class Def final { public: - Def(const PtrLink *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::Producer *producer) : _producer{producer} { // DO NOTHING } @@ -31,9 +32,6 @@ public: Object::Producer *producer(void) const { return _producer; } private: - const PtrLink *_link = nullptr; - -private: Object *_value = nullptr; Object::Producer *_producer = nullptr; }; diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index 61b98db..60bfd6f 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -21,6 +21,9 @@ namespace coco class Object { public: + friend class Def; + +public: struct Producer : public Bag::Updater { virtual ~Producer() = default; diff --git a/contrib/coco/core/src/IR/Def.cpp b/contrib/coco/core/src/IR/Def.cpp index 9b3d16a..b93ffca 100644 --- a/contrib/coco/core/src/IR/Def.cpp +++ b/contrib/coco/core/src/IR/Def.cpp @@ -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); } -- 2.7.4