This commit adds 'Var' class which users will actually use to contruct
nest expression.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
#include "nest/expr/VarNode.h"
+#include <memory>
+
+namespace nest
+{
+
+using Expr = std::shared_ptr<nest::expr::Node>;
+
+} // namespace nest
+
#endif // __NEST_EXPR_H__
--- /dev/null
+#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__
--- /dev/null
+#include "nest/Var.h"
+
+namespace nest
+{
+
+Var::operator Expr(void) const { return std::make_shared<expr::VarNode>(_id); }
+
+} // namespace nest
--- /dev/null
+#include "nest/Var.h"
+
+#include <gtest/gtest.h>
+
+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);
+}