From f366bc88b96ef6fd929ee3e11401121efc9612da 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: Thu, 26 Jul 2018 10:13:12 +0900 Subject: [PATCH] [nest] Support copy/move operation on Module (#823) This commit revises Module class to have default copy/move constructor. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Expr.h | 4 ++++ contrib/nest/include/nest/Module.h | 4 ---- contrib/nest/include/nest/Ret.h | 4 ++++ contrib/nest/src/Module.test.cpp | 12 ++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/contrib/nest/include/nest/Expr.h b/contrib/nest/include/nest/Expr.h index d23137b..5630204 100644 --- a/contrib/nest/include/nest/Expr.h +++ b/contrib/nest/include/nest/Expr.h @@ -14,6 +14,10 @@ namespace nest { +// WARNING All of the descendant of expr::Node SHOULD BE immutable +// +// The copy/move constructor of Block and Module class simply copies their shared pointer under +// the assumption that these classes are immutable. using Expr = std::shared_ptr; } // namespace nest diff --git a/contrib/nest/include/nest/Module.h b/contrib/nest/include/nest/Module.h index 7e4f1f3..4f84c66 100644 --- a/contrib/nest/include/nest/Module.h +++ b/contrib/nest/include/nest/Module.h @@ -14,10 +14,6 @@ class Module public: Module() = default; -public: - Module(const Module &) = delete; - Module(Module &&) = delete; - private: VarContext _var_ctx; diff --git a/contrib/nest/include/nest/Ret.h b/contrib/nest/include/nest/Ret.h index 75c0166..daf270e 100644 --- a/contrib/nest/include/nest/Ret.h +++ b/contrib/nest/include/nest/Ret.h @@ -7,6 +7,10 @@ namespace nest { +// WARNING Ret SHOULD BE immutable +// +// The copy/move constructor of Module class simply copies the shared pointer under the assumption +// that Ret is immutable. class Ret { public: diff --git a/contrib/nest/src/Module.test.cpp b/contrib/nest/src/Module.test.cpp index 975ee12..8048816 100644 --- a/contrib/nest/src/Module.test.cpp +++ b/contrib/nest/src/Module.test.cpp @@ -69,3 +69,15 @@ TEST(MODULE, ret) ASSERT_EQ(m.ret().id(), ofm.id()); ASSERT_EQ(m.ret().sub().rank(), 1); } + +TEST(MODULE, copy) +{ + nest::Module orig; + nest::Module copy; + + orig = copy; + + orig.var().make(); + + ASSERT_EQ(copy.var().count(), 0); +} -- 2.7.4