This commit revises 'Object' class to record a backing bag.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
#ifndef __COCO_IR_OBJECT_H__
#define __COCO_IR_OBJECT_H__
+#include "coco/IR/Bag.h"
+
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
#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
--- /dev/null
+#include "coco/IR/Object.h"
+
+#include <gtest/gtest.h>
+
+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);
+}