From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 14 Sep 2018 10:57:09 +0000 (+0900) Subject: [coco] Class static head (#1498) X-Git-Tag: nncc_backup~1811 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c2986b184cef733b547435a792ddcdd3fd15803f;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Class static head (#1498) This commit replaces pure virtual head method with class static version in order to support detach from destructor. Note that destructor SHOULD NOT invoke virtual method. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/ADT/DLinkedList.h b/contrib/coco/core/include/coco/ADT/DLinkedList.h index 92c1743..d506675 100644 --- a/contrib/coco/core/include/coco/ADT/DLinkedList.h +++ b/contrib/coco/core/include/coco/ADT/DLinkedList.h @@ -130,6 +130,9 @@ template struct DLinkedList Child *_tail; }; + // NOTE Client SHOULD implement this static method + static Head *head(Parent *); + class Node { public: @@ -159,14 +162,12 @@ template struct DLinkedList Child *prev(void) const { return _prev; } Child *next(void) const { return _next; } - protected: - virtual Head *head(void) const = 0; - public: void insertBefore(Node *next) { assert(next != nullptr); - assert(next->head() != nullptr); + assert(next->parent() != nullptr); + assert(head(next->parent()) != nullptr); assert(_prev == nullptr); assert(_next == nullptr); @@ -183,7 +184,7 @@ template struct DLinkedList // Update parent-child relation assert(parent() == nullptr); - next->head()->enlist(curr()); + head(next->parent())->enlist(curr()); assert(parent() == next->parent()); } @@ -191,7 +192,8 @@ template struct DLinkedList void insertAfter(Node *prev) { assert(prev != nullptr); - assert(prev->head() != nullptr); + assert(prev->parent() != nullptr); + assert(head(prev->parent()) != nullptr); assert(_prev == nullptr); assert(_next == nullptr); @@ -209,7 +211,7 @@ template struct DLinkedList // Update parent-child relation assert(parent() == nullptr); - prev->head()->enlist(curr()); + head(prev->parent())->enlist(curr()); assert(parent() == prev->parent()); }; @@ -218,8 +220,8 @@ template struct DLinkedList { // Update parent-child relation assert(parent() != nullptr); - assert(head() != nullptr); - head()->delist(curr()); + assert(head(parent()) != nullptr); + head(parent())->delist(curr()); assert(parent() == nullptr); // Update the link of sibling nodes diff --git a/contrib/coco/core/include/coco/IR/Block.h b/contrib/coco/core/include/coco/IR/Block.h index e17ddb7..af1eed0 100644 --- a/contrib/coco/core/include/coco/IR/Block.h +++ b/contrib/coco/core/include/coco/IR/Block.h @@ -38,9 +38,6 @@ public: private: DLinkedList::Head _instr; - -public: - BlockList *head(void) const override; }; } // namespace coco diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index 42ef65a..30df370 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -39,9 +39,6 @@ public: virtual ~Instr() = default; public: - InstrList *head(void) const override; - -public: #define INSTR(Name) \ virtual Name *as##Name(void) { return nullptr; } \ virtual const Name *as##Name(void) const { return nullptr; } diff --git a/contrib/coco/core/src/ADT/DLinkedList.test.cpp b/contrib/coco/core/src/ADT/DLinkedList.test.cpp index caaffdc..c09ddd8 100644 --- a/contrib/coco/core/src/ADT/DLinkedList.test.cpp +++ b/contrib/coco/core/src/ADT/DLinkedList.test.cpp @@ -33,13 +33,17 @@ public: { // DO NOTHING } - -private: - ChildList *head(void) const override { return parent()->children(); } }; } // namespace +namespace coco +{ + +template <> ChildList *DLinkedList::head(Parent *p) { return p->children(); } + +} // namespace coco + TEST(ADT_DLINKED_LINK, insert_two_elements) { auto link = new coco::PtrLink<::Child, ::Parent>{}; diff --git a/contrib/coco/core/src/IR/Block.cpp b/contrib/coco/core/src/IR/Block.cpp index ec11d8d..f52facf 100644 --- a/contrib/coco/core/src/IR/Block.cpp +++ b/contrib/coco/core/src/IR/Block.cpp @@ -4,6 +4,6 @@ namespace coco { -BlockList *Block::head(void) const { return parent()->block(); } +template <> BlockList *DLinkedList::head(Module *m) { return m->block(); } } // namespace coco diff --git a/contrib/coco/core/src/IR/Instr.cpp b/contrib/coco/core/src/IR/Instr.cpp index 60e7b8e..6cd5cd7 100644 --- a/contrib/coco/core/src/IR/Instr.cpp +++ b/contrib/coco/core/src/IR/Instr.cpp @@ -6,7 +6,7 @@ namespace coco { -InstrList *Instr::head(void) const { return parent()->instr(); } +template <> InstrList *DLinkedList::head(Block *b) { return b->instr(); } } // namespace coco