From 295e311f9e439fa30178183cfbc81a8cfc016aeb 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 10:34:54 +0900 Subject: [PATCH] [coco] Remove ReadHook (#1433) ReadHook was introduced to provide common (non-template) implementation over Read classes. This commit removes ReadHook and directly implements related operation in Read as Read is no longer based on template. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Read.h | 39 +++++++++++-------------- contrib/coco/core/include/coco/IR/ReadHook.h | 35 ---------------------- contrib/coco/core/src/IR/Read.cpp | 38 ++++++++++++++++++++++++ contrib/coco/core/src/IR/ReadHook.cpp | 19 ------------ contrib/coco/core/src/IR/ReadHook.test.cpp | 43 ---------------------------- 5 files changed, 54 insertions(+), 120 deletions(-) delete mode 100644 contrib/coco/core/include/coco/IR/ReadHook.h create mode 100644 contrib/coco/core/src/IR/Read.cpp delete mode 100644 contrib/coco/core/src/IR/ReadHook.cpp delete mode 100644 contrib/coco/core/src/IR/ReadHook.test.cpp diff --git a/contrib/coco/core/include/coco/IR/Read.h b/contrib/coco/core/include/coco/IR/Read.h index dbdb190..78f8ad8 100644 --- a/contrib/coco/core/include/coco/IR/Read.h +++ b/contrib/coco/core/include/coco/IR/Read.h @@ -1,9 +1,10 @@ #ifndef __COCO_IR_READ_H__ #define __COCO_IR_READ_H__ -#include "coco/IR/ReadHook.h" +#include "coco/IR/Bag.h" +#include "coco/IR/BagInfo.forward.h" -#include +#include "coco/ADT/PtrLink.h" namespace coco { @@ -14,38 +15,30 @@ namespace coco class Read final { public: - Read(const PtrLink *bag_link, Bag::Reader *read) - : _hook{bag_link, read}, _bag{nullptr} + Read(const PtrLink *bag_link, Bag::Reader *r) { - // DO NOTHING + // Initialize link and reader + link(bag_link); + reader(r); } public: Bag *bag(void) const { return _bag; } + void bag(Bag *bag); public: - void bag(Bag *bag) - { - if (_bag) - { - _hook.onRelease(_bag); - _bag = nullptr; - } - - assert(_bag == nullptr); + Bag::Reader *reader(void) const { return _reader; } + void reader(Bag::Reader *r) { _reader = r; } - if (bag) - { - _bag = bag; - _hook.onTake(_bag); - } +public: + void link(const PtrLink *l) { _link = l; } - assert(_bag == bag); - } +private: + const PtrLink *_link; private: - ReadHook _hook; - Bag *_bag; + Bag *_bag = nullptr; + Bag::Reader *_reader = nullptr; }; } // namespace coco diff --git a/contrib/coco/core/include/coco/IR/ReadHook.h b/contrib/coco/core/include/coco/IR/ReadHook.h deleted file mode 100644 index 653530f..0000000 --- a/contrib/coco/core/include/coco/IR/ReadHook.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __COCO_IR_READ_HOOK_H__ -#define __COCO_IR_READ_HOOK_H__ - -#include "coco/IR/Bag.h" -#include "coco/IR/BagInfo.forward.h" - -#include "coco/ADT/PtrLink.h" - -namespace coco -{ - -class ReadHook final -{ -public: - ReadHook(const PtrLink *bag_link, Bag::Reader *read) - : _bag_link{bag_link}, _read{read} - { - // DO NOTHING - } - -private: - BagInfo *info(Bag *bag) const; - -public: - void onTake(Bag *bag); - void onRelease(Bag *bag); - -private: - const PtrLink *const _bag_link; - Bag::Reader *const _read; -}; - -} // namespace coco - -#endif // __COCO_IR_READ_HOOK_H__ diff --git a/contrib/coco/core/src/IR/Read.cpp b/contrib/coco/core/src/IR/Read.cpp new file mode 100644 index 0000000..3144fc8 --- /dev/null +++ b/contrib/coco/core/src/IR/Read.cpp @@ -0,0 +1,38 @@ +#include "coco/IR/Read.h" +#include "coco/IR/BagInfo.h" + +#include + +namespace coco +{ + +void Read::bag(Bag *bag) +{ + if (_bag) + { + if (_link && _reader) + { + auto info = _link->find(_bag); + assert(info != nullptr); + info->reads()->erase(_reader); + } + _bag = nullptr; + } + + assert(_bag == nullptr); + + if (bag) + { + _bag = bag; + if (_link && _reader) + { + auto info = _link->find(_bag); + assert(info != nullptr); + info->reads()->insert(_reader); + } + } + + assert(_bag == bag); +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/ReadHook.cpp b/contrib/coco/core/src/IR/ReadHook.cpp deleted file mode 100644 index 31929db..0000000 --- a/contrib/coco/core/src/IR/ReadHook.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "coco/IR/ReadHook.h" -#include "coco/IR/BagInfo.h" - -#include - -namespace coco -{ - -BagInfo *ReadHook::info(Bag *bag) const -{ - auto info = _bag_link->find(bag); - assert(info != nullptr); - return info; -} - -void ReadHook::onTake(Bag *bag) { info(bag)->reads()->insert(_read); } -void ReadHook::onRelease(Bag *bag) { info(bag)->reads()->erase(_read); } - -} // namespace coco diff --git a/contrib/coco/core/src/IR/ReadHook.test.cpp b/contrib/coco/core/src/IR/ReadHook.test.cpp deleted file mode 100644 index 246e270..0000000 --- a/contrib/coco/core/src/IR/ReadHook.test.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "coco/IR/ReadHook.h" - -#include "coco/IR/BagInfo.h" -#include "coco/IR/BagManager.h" - -#include "Read.mock.h" - -#include - -namespace -{ -class ReadHookTest : public ::testing::Test -{ -protected: - coco::PtrLink bag_link; - - coco::BagManager bag_mgr{&bag_link}; -}; -} // namespace - -TEST_F(ReadHookTest, TakeAndRelease) -{ - auto bag = bag_mgr.create(16); - - ::mock::Read read; - - coco::ReadHook hook{&bag_link, &read}; - - hook.onTake(bag); - { - auto reads = bag->reads(); - - ASSERT_EQ(reads.size(), 1); - ASSERT_NE(reads.find(&read), reads.end()); - } - - hook.onRelease(bag); - { - auto reads = bag->reads(); - - ASSERT_EQ(reads.size(), 0); - } -} -- 2.7.4