[nest] Overload 'operator+' over nest expressions (#712)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 19 Jul 2018 01:15:59 +0000 (10:15 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 19 Jul 2018 01:15:59 +0000 (10:15 +0900)
This commit introduce 'operator+' overloading to make it easy to
construct 'ADD' expression in nest IR.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nest/include/nest/Expr.h
contrib/nest/src/Expr.cpp [new file with mode: 0644]
contrib/nest/src/Expr.test.cpp [new file with mode: 0644]

index 9fc09cb..8fef2b1 100644 (file)
@@ -17,4 +17,6 @@ using Expr = std::shared_ptr<nest::expr::Node>;
 
 } // namespace nest
 
+nest::Expr operator+(const nest::Expr &, const nest::Expr &);
+
 #endif // __NEST_EXPR_H__
diff --git a/contrib/nest/src/Expr.cpp b/contrib/nest/src/Expr.cpp
new file mode 100644 (file)
index 0000000..46e9b41
--- /dev/null
@@ -0,0 +1,6 @@
+#include "nest/Expr.h"
+
+nest::Expr operator+(const nest::Expr &lhs, const nest::Expr &rhs)
+{
+  return std::make_shared<nest::expr::AddNode>(lhs, rhs);
+}
diff --git a/contrib/nest/src/Expr.test.cpp b/contrib/nest/src/Expr.test.cpp
new file mode 100644 (file)
index 0000000..de469ca
--- /dev/null
@@ -0,0 +1,27 @@
+#include "nest/Expr.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(EXPR, operator_sum)
+{
+  auto left = std::make_shared<DummyNode>();
+  auto right = std::make_shared<DummyNode>();
+
+  auto expr = left + right;
+
+  ASSERT_NE(expr->asAdd(), nullptr);
+
+  auto add = expr->asAdd();
+
+  ASSERT_EQ(add->lhs().get(), left.get());
+  ASSERT_EQ(add->rhs().get(), right.get());
+}