From 50fda2d100bdf653fe57817db496ac13c7c8d048 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, 19 Jul 2018 10:15:59 +0900 Subject: [PATCH] [nest] Overload 'operator+' over nest expressions (#712) This commit introduce 'operator+' overloading to make it easy to construct 'ADD' expression in nest IR. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Expr.h | 2 ++ contrib/nest/src/Expr.cpp | 6 ++++++ contrib/nest/src/Expr.test.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 contrib/nest/src/Expr.cpp create mode 100644 contrib/nest/src/Expr.test.cpp diff --git a/contrib/nest/include/nest/Expr.h b/contrib/nest/include/nest/Expr.h index 9fc09cb..8fef2b1 100644 --- a/contrib/nest/include/nest/Expr.h +++ b/contrib/nest/include/nest/Expr.h @@ -17,4 +17,6 @@ using Expr = std::shared_ptr; } // 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 index 0000000..46e9b41 --- /dev/null +++ b/contrib/nest/src/Expr.cpp @@ -0,0 +1,6 @@ +#include "nest/Expr.h" + +nest::Expr operator+(const nest::Expr &lhs, const nest::Expr &rhs) +{ + return std::make_shared(lhs, rhs); +} diff --git a/contrib/nest/src/Expr.test.cpp b/contrib/nest/src/Expr.test.cpp new file mode 100644 index 0000000..de469ca --- /dev/null +++ b/contrib/nest/src/Expr.test.cpp @@ -0,0 +1,27 @@ +#include "nest/Expr.h" + +#include + +#include + +namespace +{ +struct DummyNode final : public nest::expr::Node +{ +}; +} + +TEST(EXPR, operator_sum) +{ + auto left = std::make_shared(); + auto right = std::make_shared(); + + 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()); +} -- 2.7.4