The current design of DLinkedList::Node enforces all of its descendent classes to
implement a consturctor that takes PtrLink, and passes it to its parent.
This restriction makes it difficult to introduce some intermediate
traists.
This commit revises DLinkedList::Node to remove this restriction.
The current design enforces only leaf classes to implement 'get' method.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
class Node
{
public:
- Node(const PtrLink<Child, Parent> *link) : _link{link}
+ Node()
{
static_assert(std::is_base_of<Node, Child>::value, "Type `Child` must be subclass of `Node`.");
public:
virtual ~Node() = default;
+ protected:
+ virtual void get(const PtrLink<Child, Parent> **out) const = 0;
+
public:
- Parent *parent(void) const { return _link->find(reinterpret_cast<const Child *>(this)); }
+ Parent *parent(void) const
+ {
+ const PtrLink<Child, Parent> *link = nullptr;
+ get(&link);
+ assert(link != nullptr);
+ return link->find(reinterpret_cast<const Child *>(this));
+ }
public:
Child *prev(void) const { return _prev; }
}
private:
- const PtrLink<Child, Parent> * const _link;
-
- private:
Child *_prev;
Child *_next;
};
{
public:
Block(const PtrLink<Block, Module> *block_link, PtrLink<Instr, Block> *instr_link)
- : DLinkedList<Block, Module>::Node{block_link}, _instr{this, instr_link}
+ : _block_link{block_link}, _instr{this, instr_link}
{
// DO NOTHING
}
Block(const Block &) = delete;
Block(Block &&) = delete;
+private:
+ const PtrLink<Block, Module> * const _block_link;
+
+private:
+ void get(const PtrLink<Block, Module> **out) const override { *out = _block_link; }
+
public:
InstrList *instr(void) { return &_instr; }
const InstrList *instr(void) const { return &_instr; }
class Instr : public coco::DLinkedList<Instr, Block>::Node
{
public:
- Instr(const PtrLink<Instr, Block> *link) : DLinkedList<Instr, Block>::Node{link}
- {
- // DO NOTHING
- }
+ Instr() = default;
public:
Instr(const Instr &) = delete;
class FeatureInstr : public Instr
{
public:
- FeatureInstr(const PtrLink<Instr, Block> *link) : Instr{link}, _ifm{nullptr}, _ofm{nullptr}
+ FeatureInstr() : _ifm{nullptr}, _ofm{nullptr}
{
// DO NOTHING
}
class UnitF final : public FeatureInstr
{
public:
- UnitF(const PtrLink<Instr, Block> *link) : FeatureInstr{link}, _op{nullptr}
+ UnitF(const PtrLink<Instr, Block> *link) : _link{link}, _op{nullptr}
{
// DO NOTHING
}
std::set<Bag *> updates(void) const override;
private:
+ const PtrLink<Instr, Block> * const _link;
+
+private:
+ void get(const PtrLink<Instr, Block> **out) const override { *out = _link; }
+
+private:
Op *_op;
public:
ChildList _list;
};
-class Child : public coco::DLinkedList<Child, Parent>::Node
+class Child final : public coco::DLinkedList<Child, Parent>::Node
{
public:
- Child(const coco::PtrLink<Child, Parent> *link) : coco::DLinkedList<Child, Parent>::Node{link}
+ Child(const coco::PtrLink<Child, Parent> *link) : _link{link}
{
// DO NOTHING
}
+private:
+ void get(const coco::PtrLink<Child, Parent> **out) const override { *out = _link; }
+
public:
ChildList *head(void) const override { return parent()->children(); }
+
+private:
+ const coco::PtrLink<Child, Parent> *_link;
};
} // namespace
struct FeatureInstr : public coco::FeatureInstr
{
public:
- FeatureInstr(const coco::PtrLink<coco::Instr, coco::Block> *ins_link)
- : coco::FeatureInstr{ins_link}
+ FeatureInstr()
{
-
+ // DO NOTHING
}
+private:
+ void get(const coco::PtrLink<coco::Instr, coco::Block> **) const override { return; }
+
public:
std::set<coco::Bag *> reads(void) const override { return std::set<coco::Bag *>(); }
std::set<coco::Bag *> updates(void) const override { return std::set<coco::Bag *>(); }
TEST(IR_FEATURE_INSTR, ctor)
{
- coco::PtrLink<coco::Instr, coco::Block> link;
- ::mock::FeatureInstr ins{&link};
+ ::mock::FeatureInstr ins;
// IFM and OFM should be initialized as nullptr
ASSERT_EQ(ins.ifm(), nullptr);
auto obj = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 3, 3});
// Test 'FeatureInstr' class
- coco::PtrLink<coco::Instr, coco::Block> link;
- ::mock::FeatureInstr ins{&link};
+ ::mock::FeatureInstr ins;
// 'ifm(FeatureObject *)' method should affect 'ifm()' method
ins.ifm(obj);
auto obj = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 3, 3});
// Test 'FeatureInstr' class
- coco::PtrLink<coco::Instr, coco::Block> link;
- ::mock::FeatureInstr ins{&link};
+ ::mock::FeatureInstr ins;
// 'ofm(FeatureObject *)' method should affect 'ofm()' method
ins.ofm(obj);