+++ /dev/null
-#ifndef __COCO_IR_DEF_HOOK_H__
-#define __COCO_IR_DEF_HOOK_H__
-
-#include "coco/IR/Object.h"
-#include "coco/IR/ObjectInfo.forward.h"
-
-#include "coco/ADT/PtrLink.h"
-
-namespace coco
-{
-
-class DefHook final
-{
-public:
- DefHook(const PtrLink<Object, ObjectInfo> *obj_link, Object::Producer *def)
- : _obj_link{obj_link}, _def{def}
- {
- // DO NOTHING
- }
-
-private:
- ObjectInfo *info(Object *o) const;
-
-public:
- void onTake(Object *o);
- void onRelease(Object *o);
-
-private:
- const PtrLink<Object, ObjectInfo> *const _obj_link;
- // TODO Rename field
- Object::Producer *const _def;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_DEF_HOOK_H__
#ifndef __COCO_IR_DEF_SLOT_H__
#define __COCO_IR_DEF_SLOT_H__
-#include "coco/IR/DefHook.h"
+#include "coco/IR/Object.h"
+#include "coco/IR/ObjectInfo.forward.h"
+
+#include "coco/ADT/PtrLink.h"
namespace coco
{
class DefSlot final
{
public:
- DefSlot(const PtrLink<Object, ObjectInfo> *obj_link, Object::Producer *use)
- : _hook{obj_link, use}, _value{nullptr}
+ DefSlot(const PtrLink<Object, ObjectInfo> *link, Object::Producer *producer)
+ : _link{link}, _producer{producer}
{
+ // DO NOTHING
}
public:
Object *value(void) const { return _value; }
public:
- void value(Object *value)
- {
- if (_value)
- {
- _hook.onRelease(_value);
- _value = nullptr;
- }
-
- assert(_value == nullptr);
+ void value(Object *value);
- if (value)
- {
- _value = value;
- _hook.onTake(_value);
- }
-
- assert(_value == value);
- }
+private:
+ const PtrLink<Object, ObjectInfo> *_link = nullptr;
private:
- DefHook _hook;
- Object *_value;
+ Object *_value = nullptr;
+ Object::Producer *_producer = nullptr;
};
} // namespace coco
+++ /dev/null
-#include "coco/IR/DefHook.h"
-#include "coco/IR/ObjectInfo.h"
-
-#include <cassert>
-
-namespace coco
-{
-
-ObjectInfo *DefHook::info(Object *o) const
-{
- auto info = _obj_link->find(o);
- assert(info != nullptr);
- return info;
-}
-
-void DefHook::onTake(Object *o) { info(o)->def(_def); }
-void DefHook::onRelease(Object *o) { info(o)->def(nullptr); }
-
-} // namespace coco
+++ /dev/null
-#include "coco/IR/DefHook.h"
-#include "coco/IR/ObjectInfo.h"
-#include "coco/IR/ObjectManager.h"
-
-#include "coco/IR/FeatureObject.h"
-
-#include "Def.mock.h"
-
-#include <gtest/gtest.h>
-
-namespace
-{
-class DefHookTest : public ::testing::Test
-{
-protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
-
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
-};
-} // namespace
-
-TEST_F(DefHookTest, TakeAndRelease)
-{
- auto o = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 1, 1});
-
- ::mock::Def use;
-
- coco::DefHook hook{&obj_link, &use};
-
- hook.onTake(o);
- hook.onRelease(o);
-}
--- /dev/null
+#include "coco/IR/DefSlot.h"
+#include "coco/IR/ObjectInfo.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+void DefSlot::value(Object *value)
+{
+ assert(_link != nullptr);
+
+ if (_value)
+ {
+ auto info = _link->find(_value);
+ assert(info != nullptr);
+ info->def(nullptr);
+
+ _value = nullptr;
+ }
+
+ assert(_value == nullptr);
+
+ if (value)
+ {
+ _value = value;
+
+ auto info = _link->find(_value);
+ assert(info != nullptr);
+ info->def(_producer);
+ }
+
+ assert(_value == value);
+}
+
+} // namespace coco