From 690d3e33a5c72a2c42b296ab074095c5f998ad22 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 19:11:09 +0900 Subject: [PATCH] [nest] Override 'operator*' over expressions (#720) This commit overrides 'operator*' over two nest expressions to make it easy to build nest expressions. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Expr.h | 2 ++ contrib/nest/src/Expr.cpp | 5 +++++ contrib/nest/src/Expr.test.cpp | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/contrib/nest/include/nest/Expr.h b/contrib/nest/include/nest/Expr.h index 8fef2b1..d23137b 100644 --- a/contrib/nest/include/nest/Expr.h +++ b/contrib/nest/include/nest/Expr.h @@ -7,6 +7,7 @@ #include "nest/expr/VarNode.h" #include "nest/expr/DerefNode.h" #include "nest/expr/AddNode.h" +#include "nest/expr/MulNode.h" #include @@ -18,5 +19,6 @@ using Expr = std::shared_ptr; } // namespace nest nest::Expr operator+(const nest::Expr &, const nest::Expr &); +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 index 46e9b41..790fe92 100644 --- a/contrib/nest/src/Expr.cpp +++ b/contrib/nest/src/Expr.cpp @@ -4,3 +4,8 @@ nest::Expr operator+(const nest::Expr &lhs, const nest::Expr &rhs) { return std::make_shared(lhs, rhs); } + +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 index de469ca..ad36131 100644 --- a/contrib/nest/src/Expr.test.cpp +++ b/contrib/nest/src/Expr.test.cpp @@ -25,3 +25,18 @@ TEST(EXPR, operator_sum) ASSERT_EQ(add->lhs().get(), left.get()); ASSERT_EQ(add->rhs().get(), right.get()); } + +TEST(EXPR, operator_mul) +{ + auto left = std::make_shared(); + auto right = std::make_shared(); + + auto expr = left * right; + + ASSERT_NE(expr->asMul(), nullptr); + + auto add = expr->asMul(); + + ASSERT_EQ(add->lhs().get(), left.get()); + ASSERT_EQ(add->rhs().get(), right.get()); +} -- 2.7.4