From e11715251313bf9ae106ff21d9b2e28e2c90a3b9 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: Tue, 11 Sep 2018 09:42:02 +0900 Subject: [PATCH] [coco] Rename ReadSlot and UpdateSlot (#1420) This commit renames ReadSlot and UpdateSlot as Read/Update similarly as Dep class. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Read.h | 53 ++++++++++++++++++++++ contrib/coco/core/include/coco/IR/ReadSlot.h | 50 -------------------- contrib/coco/core/include/coco/IR/Shuffle.h | 12 ++--- contrib/coco/core/include/coco/IR/Update.h | 53 ++++++++++++++++++++++ contrib/coco/core/include/coco/IR/UpdateSlot.h | 50 -------------------- .../src/IR/{ReadSlot.test.cpp => Read.test.cpp} | 24 +++++----- contrib/coco/core/src/IR/Shuffle.cpp | 4 +- .../IR/{UpdateSlot.test.cpp => Update.test.cpp} | 24 +++++----- 8 files changed, 140 insertions(+), 130 deletions(-) create mode 100644 contrib/coco/core/include/coco/IR/Read.h delete mode 100644 contrib/coco/core/include/coco/IR/ReadSlot.h create mode 100644 contrib/coco/core/include/coco/IR/Update.h delete mode 100644 contrib/coco/core/include/coco/IR/UpdateSlot.h rename contrib/coco/core/src/IR/{ReadSlot.test.cpp => Read.test.cpp} (57%) rename contrib/coco/core/src/IR/{UpdateSlot.test.cpp => Update.test.cpp} (58%) diff --git a/contrib/coco/core/include/coco/IR/Read.h b/contrib/coco/core/include/coco/IR/Read.h new file mode 100644 index 0000000..dbdb190 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/Read.h @@ -0,0 +1,53 @@ +#ifndef __COCO_IR_READ_H__ +#define __COCO_IR_READ_H__ + +#include "coco/IR/ReadHook.h" + +#include + +namespace coco +{ + +/** + * @brief A Read represents an edge between a Bag and its Reader + */ +class Read final +{ +public: + Read(const PtrLink *bag_link, Bag::Reader *read) + : _hook{bag_link, read}, _bag{nullptr} + { + // DO NOTHING + } + +public: + Bag *bag(void) const { return _bag; } + +public: + void bag(Bag *bag) + { + if (_bag) + { + _hook.onRelease(_bag); + _bag = nullptr; + } + + assert(_bag == nullptr); + + if (bag) + { + _bag = bag; + _hook.onTake(_bag); + } + + assert(_bag == bag); + } + +private: + ReadHook _hook; + Bag *_bag; +}; + +} // namespace coco + +#endif // __COCO_IR_READ_H__ diff --git a/contrib/coco/core/include/coco/IR/ReadSlot.h b/contrib/coco/core/include/coco/IR/ReadSlot.h deleted file mode 100644 index 1c7d6c6..0000000 --- a/contrib/coco/core/include/coco/IR/ReadSlot.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef __COCO_IR_READ_SLOT_H__ -#define __COCO_IR_READ_SLOT_H__ - -#include "coco/IR/ReadHook.h" - -#include - -namespace coco -{ - -template class ReadSlot final -{ -public: - ReadSlot(const PtrLink *bag_link, Bag::Reader *read) - : _hook{bag_link, read}, _value{nullptr} - { - // DO NOTHING - } - -public: - T *value(void) const { return _value; } - -public: - void value(T *value) - { - if (_value) - { - _hook.onRelease(_value); - _value = nullptr; - } - - assert(_value == nullptr); - - if (value) - { - _value = value; - _hook.onTake(_value); - } - - assert(_value == value); - } - -private: - ReadHook _hook; - T *_value; -}; - -} // namespace coco - -#endif // __COCO_IR_READ_SLOT_H__ diff --git a/contrib/coco/core/include/coco/IR/Shuffle.h b/contrib/coco/core/include/coco/IR/Shuffle.h index e94ca38..f45695d 100644 --- a/contrib/coco/core/include/coco/IR/Shuffle.h +++ b/contrib/coco/core/include/coco/IR/Shuffle.h @@ -4,8 +4,8 @@ #include "coco/IR/Instr.h" #include "coco/IR/Bag.h" -#include "coco/IR/ReadSlot.h" -#include "coco/IR/UpdateSlot.h" +#include "coco/IR/Read.h" +#include "coco/IR/Update.h" #include "coco/ADT/PtrLink.h" @@ -39,11 +39,11 @@ private: void get(const PtrLink **out) const override { *out = _instr_link; } public: - Bag *from(void) const { return _from.value(); } + Bag *from(void) const { return _from.bag(); } void from(Bag *bag); public: - Bag *into(void) const { return _into.value(); } + Bag *into(void) const { return _into.bag(); } void into(Bag *); public: @@ -66,8 +66,8 @@ private: const PtrLink *const _instr_link; private: - ReadSlot _from; - UpdateSlot _into; + Read _from; + Update _into; private: std::map _content; diff --git a/contrib/coco/core/include/coco/IR/Update.h b/contrib/coco/core/include/coco/IR/Update.h new file mode 100644 index 0000000..1241caf --- /dev/null +++ b/contrib/coco/core/include/coco/IR/Update.h @@ -0,0 +1,53 @@ +#ifndef __COCO_IR_UPDATE_H__ +#define __COCO_IR_UPDATE_H__ + +#include "coco/IR/UpdateHook.h" + +#include + +namespace coco +{ + +/** + * @brief A Update represents an edge between a Bag and its Updater + */ +class Update final +{ +public: + Update(const PtrLink *bag_link, Bag::Updater *update) + : _hook{bag_link, update}, _bag{nullptr} + { + // DO NOTHING + } + +public: + Bag *bag(void) const { return _bag; } + +public: + void bag(Bag *bag) + { + if (_bag) + { + _hook.onRelease(_bag); + _bag = nullptr; + } + + assert(_bag == nullptr); + + if (bag) + { + _bag = bag; + _hook.onTake(_bag); + } + + assert(_bag == bag); + } + +private: + UpdateHook _hook; + Bag *_bag; +}; + +} // namespace coco + +#endif // __COCO_IR_UPDATE_H__ diff --git a/contrib/coco/core/include/coco/IR/UpdateSlot.h b/contrib/coco/core/include/coco/IR/UpdateSlot.h deleted file mode 100644 index 2df04a6..0000000 --- a/contrib/coco/core/include/coco/IR/UpdateSlot.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef __COCO_IR_UPDATE_SLOT_H__ -#define __COCO_IR_UPDATE_SLOT_H__ - -#include "coco/IR/UpdateHook.h" - -#include - -namespace coco -{ - -template class UpdateSlot final -{ -public: - UpdateSlot(const PtrLink *bag_link, Bag::Updater *update) - : _hook{bag_link, update}, _value{nullptr} - { - // DO NOTHING - } - -public: - T *value(void) const { return _value; } - -public: - void value(T *value) - { - if (_value) - { - _hook.onRelease(_value); - _value = nullptr; - } - - assert(_value == nullptr); - - if (value) - { - _value = value; - _hook.onTake(_value); - } - - assert(_value == value); - } - -private: - UpdateHook _hook; - T *_value; -}; - -} // namespace coco - -#endif // __COCO_IR_UPDATE_SLOT_H__ diff --git a/contrib/coco/core/src/IR/ReadSlot.test.cpp b/contrib/coco/core/src/IR/Read.test.cpp similarity index 57% rename from contrib/coco/core/src/IR/ReadSlot.test.cpp rename to contrib/coco/core/src/IR/Read.test.cpp index 1b01651..1231467 100644 --- a/contrib/coco/core/src/IR/ReadSlot.test.cpp +++ b/contrib/coco/core/src/IR/Read.test.cpp @@ -1,4 +1,4 @@ -#include "coco/IR/ReadSlot.h" +#include "coco/IR/Read.h" #include "coco/IR/BagInfo.h" #include "coco/IR/BagManager.h" @@ -8,7 +8,7 @@ namespace { -class ReadSlotTest : public ::testing::Test +class ReadTest : public ::testing::Test { protected: coco::PtrLink bag_link; @@ -17,26 +17,28 @@ protected: }; } // namespace -TEST_F(ReadSlotTest, constructor) +TEST_F(ReadTest, constructor) { ::mock::Read read; - coco::ReadSlot slot{&bag_link, &read}; + // TODO Rename 'slot' + coco::Read slot{&bag_link, &read}; - ASSERT_EQ(slot.value(), nullptr); + ASSERT_EQ(slot.bag(), nullptr); } -TEST_F(ReadSlotTest, value) +TEST_F(ReadTest, value) { ::mock::Read read; - coco::ReadSlot slot{&bag_link, &read}; + // TODO Rename 'slot' + coco::Read slot{&bag_link, &read}; auto bag = bag_mgr.create(16); - slot.value(bag); + slot.bag(bag); - ASSERT_EQ(slot.value(), bag); + ASSERT_EQ(slot.bag(), bag); { auto reads = bag->reads(); @@ -45,12 +47,12 @@ TEST_F(ReadSlotTest, value) ASSERT_NE(reads.find(&read), reads.end()); } - slot.value(nullptr); + slot.bag(nullptr); { auto reads = bag->reads(); - ASSERT_EQ(slot.value(), nullptr); + ASSERT_EQ(slot.bag(), nullptr); ASSERT_EQ(reads.size(), 0); } diff --git a/contrib/coco/core/src/IR/Shuffle.cpp b/contrib/coco/core/src/IR/Shuffle.cpp index 3accd5e..9fd5873 100644 --- a/contrib/coco/core/src/IR/Shuffle.cpp +++ b/contrib/coco/core/src/IR/Shuffle.cpp @@ -47,7 +47,7 @@ std::set Shuffle::updates(void) const return res; } -void Shuffle::from(Bag *b) { _from.value(b); } -void Shuffle::into(Bag *b) { _into.value(b); } +void Shuffle::from(Bag *b) { _from.bag(b); } +void Shuffle::into(Bag *b) { _into.bag(b); } } // namespace coco diff --git a/contrib/coco/core/src/IR/UpdateSlot.test.cpp b/contrib/coco/core/src/IR/Update.test.cpp similarity index 58% rename from contrib/coco/core/src/IR/UpdateSlot.test.cpp rename to contrib/coco/core/src/IR/Update.test.cpp index 3ae83a4..7b7db7e 100644 --- a/contrib/coco/core/src/IR/UpdateSlot.test.cpp +++ b/contrib/coco/core/src/IR/Update.test.cpp @@ -1,4 +1,4 @@ -#include "coco/IR/UpdateSlot.h" +#include "coco/IR/Update.h" #include "coco/IR/BagInfo.h" #include "coco/IR/BagManager.h" @@ -8,7 +8,7 @@ namespace { -class UpdateSlotTest : public ::testing::Test +class UpdateTest : public ::testing::Test { protected: coco::PtrLink bag_link; @@ -17,26 +17,28 @@ protected: }; } // namespace -TEST_F(UpdateSlotTest, constructor) +TEST_F(UpdateTest, constructor) { ::mock::Update update; - coco::UpdateSlot slot{&bag_link, &update}; + // TODO Rename 'slot' + coco::Update slot{&bag_link, &update}; - ASSERT_EQ(slot.value(), nullptr); + ASSERT_EQ(slot.bag(), nullptr); } -TEST_F(UpdateSlotTest, value) +TEST_F(UpdateTest, value) { ::mock::Update update; - coco::UpdateSlot slot{&bag_link, &update}; + // TODO Rename 'slot' + coco::Update slot{&bag_link, &update}; auto bag = bag_mgr.create(16); - slot.value(bag); + slot.bag(bag); - ASSERT_EQ(slot.value(), bag); + ASSERT_EQ(slot.bag(), bag); { auto updates = bag->updates(); @@ -45,12 +47,12 @@ TEST_F(UpdateSlotTest, value) ASSERT_NE(updates.find(&update), updates.end()); } - slot.value(nullptr); + slot.bag(nullptr); { auto updates = bag->updates(); - ASSERT_EQ(slot.value(), nullptr); + ASSERT_EQ(slot.bag(), nullptr); ASSERT_EQ(updates.size(), 0); } -- 2.7.4