From 158b9faeccb22cc8f7267f03884c8017f259fb11 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: Fri, 7 Sep 2018 16:38:51 +0900 Subject: [PATCH] [coco] Use 'Dep' inside 'Object' (#1406) This commit replaces Bag * inside Object with 'Dep'. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Object.h | 11 +++------ contrib/coco/core/src/IR/Object.cpp | 39 +++--------------------------- contrib/coco/core/src/IR/Object.test.cpp | 18 ++++++++++++++ 3 files changed, 26 insertions(+), 42 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index cde9132..308e3f7 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -2,6 +2,7 @@ #define __COCO_IR_OBJECT_H__ #include "coco/IR/Bag.h" +#include "coco/IR/Dep.h" #include "coco/IR/ObjectInfo.forward.h" #include "coco/IR/FeatureObject.forward.h" @@ -42,12 +43,9 @@ protected: virtual void get(ObjectInfo **) const = 0; void setBagLink(const PtrLink *); -private: - coco::Bag *_bag; - public: - coco::Bag *bag(void) const { return _bag; } - void bag(coco::Bag *bag); + coco::Bag *bag(void) const { return _dep.bag(); } + void bag(coco::Bag *bag) { _dep.bag(bag); } public: virtual FeatureObject *asFeature(void) { return nullptr; } @@ -58,14 +56,13 @@ public: private: ObjectInfo *info(void) const; - BagInfo *info(const Bag *) const; public: Def *def(void) const; const User *user(void) const; private: - const PtrLink *_bag_link; + Dep _dep; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/Object.cpp b/contrib/coco/core/src/IR/Object.cpp index 838c06c..2fca0cc 100644 --- a/contrib/coco/core/src/IR/Object.cpp +++ b/contrib/coco/core/src/IR/Object.cpp @@ -8,38 +8,13 @@ namespace coco { -Object::Object() : _bag{nullptr} +Object::Object() { - // DO NOTHING + // Register self to Dep + _dep.object(this); } -void Object::setBagLink(const PtrLink *bag_link) { _bag_link = bag_link; } - -void Object::bag(coco::Bag *bag) -{ - if (_bag != nullptr) - { - auto bag_info = info(_bag); - assert(bag_info != nullptr); - assert(bag_info->object()->find(this) != bag_info->object()->end()); - - bag_info->object()->erase(this); - - _bag = nullptr; - } - - assert(_bag == nullptr); - - if (bag != nullptr) - { - // TODO Update bag-object relation - _bag = bag; - - auto bag_info = info(_bag); - assert(bag_info != nullptr); - bag_info->object()->insert(this); - } -} +void Object::setBagLink(const PtrLink *bag_link) { _dep.link(bag_link); } ObjectInfo *Object::info(void) const { @@ -48,12 +23,6 @@ ObjectInfo *Object::info(void) const return res; } -BagInfo *Object::info(const Bag *bag) const -{ - assert(_bag_link != nullptr); - return _bag_link->find(bag); -} - Object::Def *Object::def(void) const { return info()->def(); } const Object::User *Object::user(void) const { return info()->user(); } diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp index 2305bbe..6a236c8 100644 --- a/contrib/coco/core/src/IR/Object.test.cpp +++ b/contrib/coco/core/src/IR/Object.test.cpp @@ -91,3 +91,21 @@ TEST_F(ObjectTest, bag_update) ASSERT_EQ(bag->object()->size(), 0); } + +TEST_F(ObjectTest, destructor) +{ + auto bag = bag_mgr.create(1); + + // Destruct Object after proper initialization + { + ::mock::Object obj; + + obj.info = make_unique(); + obj.link(&link); + + obj.bag(bag); + } + + // Object SHOULD be unlinked from Bag on destruction + ASSERT_EQ(bag->object()->size(), 0); +} -- 2.7.4