From 02890ce6fa797214a3ce471624cdb1e73328d832 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, 23 Jul 2018 14:28:46 +0900 Subject: [PATCH] [coco] Record a backing bag for each object (#758) This commit revises 'Object' class to record a backing bag. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Object.h | 12 ++++++++++++ contrib/coco/core/src/IR/Object.cpp | 17 ++++++++++++++++- contrib/coco/core/src/IR/Object.test.cpp | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 contrib/coco/core/src/IR/Object.test.cpp diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index e678e05..521dc50 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -1,6 +1,8 @@ #ifndef __COCO_IR_OBJECT_H__ #define __COCO_IR_OBJECT_H__ +#include "coco/IR/Bag.h" + namespace coco { @@ -10,7 +12,17 @@ namespace coco class Object { public: + Object(); + +public: virtual ~Object() = default; + +private: + coco::Bag *_bag; + +public: + coco::Bag *bag(void) const { return _bag; } + void bag(coco::Bag *bag); }; } // namespace coco diff --git a/contrib/coco/core/src/IR/Object.cpp b/contrib/coco/core/src/IR/Object.cpp index c83a9ec..8c3f864 100644 --- a/contrib/coco/core/src/IR/Object.cpp +++ b/contrib/coco/core/src/IR/Object.cpp @@ -1,3 +1,18 @@ #include "coco/IR/Object.h" -// NOTE Do NOT delete this file; this file checks the completeness of 'Object.h' +namespace coco +{ + +Object::Object() : _bag{nullptr} +{ + // DO NOTHING +} + +void Object::bag(coco::Bag *bag) +{ + // TODO Update bag-object relation + // Q: Should descendant (such as FeatureObject) be aware of bag changes? + _bag = bag; +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp new file mode 100644 index 0000000..8d02e77 --- /dev/null +++ b/contrib/coco/core/src/IR/Object.test.cpp @@ -0,0 +1,22 @@ +#include "coco/IR/Object.h" + +#include + +TEST(IR_OBJECT, ctor) +{ + coco::Object obj{}; + + // Newly created object should not have a backing bag + ASSERT_EQ(obj.bag(), nullptr); +} + +TEST(IR_OBJECT, bag_update) +{ + coco::Bag bag{1}; + coco::Object obj{}; + + obj.bag(&bag); + + // 'bag(Bag *)' should affect the return of 'bag(void)' + ASSERT_EQ(obj.bag(), &bag); +} -- 2.7.4