From b62d3d63a0728149d62d663165ddc74c4478c31e 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: Tue, 17 Jul 2018 09:36:53 +0900 Subject: [PATCH] [nest] Add 'Var' class (#670) This commit adds 'Var' class which users will actually use to contruct nest expression. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Expr.h | 9 +++++++++ contrib/nest/include/nest/Var.h | 33 +++++++++++++++++++++++++++++++++ contrib/nest/src/Var.cpp | 8 ++++++++ contrib/nest/src/Var.test.cpp | 22 ++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 contrib/nest/include/nest/Var.h create mode 100644 contrib/nest/src/Var.cpp create mode 100644 contrib/nest/src/Var.test.cpp diff --git a/contrib/nest/include/nest/Expr.h b/contrib/nest/include/nest/Expr.h index 8c84c06..66b2e43 100644 --- a/contrib/nest/include/nest/Expr.h +++ b/contrib/nest/include/nest/Expr.h @@ -6,4 +6,13 @@ #include "nest/expr/VarNode.h" +#include + +namespace nest +{ + +using Expr = std::shared_ptr; + +} // namespace nest + #endif // __NEST_EXPR_H__ diff --git a/contrib/nest/include/nest/Var.h b/contrib/nest/include/nest/Var.h new file mode 100644 index 0000000..6549e45 --- /dev/null +++ b/contrib/nest/include/nest/Var.h @@ -0,0 +1,33 @@ +#ifndef __NEST_VAR_H__ +#define __NEST_VAR_H__ + +#include "nest/VarID.h" +#include "nest/Expr.h" + +namespace nest +{ + +class Var +{ +public: + Var() = default; + +public: + Var(const VarID &id) : _id{id} + { + // DO NOTHING + } + +public: + const VarID &id(void) const { return _id; } + +public: + operator Expr(void) const; + +private: + VarID const _id; +}; + +} // namespace nest + +#endif // __NEST_VAR_H__ diff --git a/contrib/nest/src/Var.cpp b/contrib/nest/src/Var.cpp new file mode 100644 index 0000000..1b519ca --- /dev/null +++ b/contrib/nest/src/Var.cpp @@ -0,0 +1,8 @@ +#include "nest/Var.h" + +namespace nest +{ + +Var::operator Expr(void) const { return std::make_shared(_id); } + +} // namespace nest diff --git a/contrib/nest/src/Var.test.cpp b/contrib/nest/src/Var.test.cpp new file mode 100644 index 0000000..8e15c63 --- /dev/null +++ b/contrib/nest/src/Var.test.cpp @@ -0,0 +1,22 @@ +#include "nest/Var.h" + +#include + +TEST(VAR, ctor) +{ + nest::VarID id{0}; + nest::Var var{id}; + + ASSERT_EQ(var.id(), id); +} + +TEST(VAR, cast) +{ + nest::VarID id{0}; + nest::Var var{id}; + + nest::Expr expr = var; + + ASSERT_NE(expr->asVar(), nullptr); + ASSERT_EQ(expr->asVar()->id(), id); +} -- 2.7.4