From 4d351f82d743b9f463b32099a0f87b80fad87c61 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: Thu, 13 Sep 2018 10:24:29 +0900 Subject: [PATCH] [coco] Non-template DefSlot (#1480) DefSlot is revised as a non-template version, which is a step to support Object-to-Object substitution. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/DefSlot.h | 8 ++++---- contrib/coco/core/include/coco/IR/Instr.h | 4 ++-- contrib/coco/core/src/IR/DefSlot.test.cpp | 6 +++--- contrib/coco/core/src/IR/Instr.cpp | 13 +++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/DefSlot.h b/contrib/coco/core/include/coco/IR/DefSlot.h index 537cfee..7ed5bee 100644 --- a/contrib/coco/core/include/coco/IR/DefSlot.h +++ b/contrib/coco/core/include/coco/IR/DefSlot.h @@ -6,7 +6,7 @@ namespace coco { -template class DefSlot final +class DefSlot final { public: DefSlot(const PtrLink *obj_link, Object::Producer *use) @@ -18,10 +18,10 @@ public: ~DefSlot() { value(nullptr); } public: - T *value(void) const { return _value; } + Object *value(void) const { return _value; } public: - void value(T *value) + void value(Object *value) { if (_value) { @@ -42,7 +42,7 @@ public: private: DefHook _hook; - T *_value; + Object *_value; }; } // namespace coco diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index 4348235..46eeacb 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -172,10 +172,10 @@ public: void ifm(FeatureObject *ifm); private: - DefSlot _ofm; + DefSlot _ofm; public: - FeatureObject *ofm(void) const { return _ofm.value(); } + FeatureObject *ofm(void) const; void ofm(FeatureObject *ofm); }; diff --git a/contrib/coco/core/src/IR/DefSlot.test.cpp b/contrib/coco/core/src/IR/DefSlot.test.cpp index 26a9681..47aaf66 100644 --- a/contrib/coco/core/src/IR/DefSlot.test.cpp +++ b/contrib/coco/core/src/IR/DefSlot.test.cpp @@ -30,7 +30,7 @@ TEST_F(DefSlotTest, constructor) ::mock::Def def; - coco::DefSlot slot{&obj_link, &def}; + coco::DefSlot slot{&obj_link, &def}; ASSERT_EQ(slot.value(), nullptr); } @@ -41,7 +41,7 @@ TEST_F(DefSlotTest, value) ::mock::Def def; - coco::DefSlot slot{&obj_link, &def}; + coco::DefSlot slot{&obj_link, &def}; slot.value(o); @@ -60,7 +60,7 @@ TEST_F(DefSlotTest, unlink_on_destruction) ::mock::Def def; - auto slot = make_unique>(&obj_link, &def); + auto slot = make_unique(&obj_link, &def); slot->value(o); ASSERT_EQ(o->def(), &def); diff --git a/contrib/coco/core/src/IR/Instr.cpp b/contrib/coco/core/src/IR/Instr.cpp index 8f37af8..7da448d 100644 --- a/contrib/coco/core/src/IR/Instr.cpp +++ b/contrib/coco/core/src/IR/Instr.cpp @@ -1,6 +1,8 @@ #include "coco/IR/Instr.h" #include "coco/IR/Block.h" +#include + namespace coco { @@ -23,4 +25,15 @@ FeatureInstr::FeatureInstr(const PtrLink *obj_link) void FeatureInstr::ifm(FeatureObject *ifm) { _ifm.value(ifm); } void FeatureInstr::ofm(FeatureObject *ofm) { _ofm.value(ofm); } +FeatureObject *FeatureInstr::ofm(void) const +{ + if (auto obj = _ofm.value()) + { + assert(obj->asFeature() != nullptr); + return obj->asFeature(); + } + + return nullptr; +} + } // namespace coco -- 2.7.4